Eighteen languages share a Format button on this page. They do not share a grammar. A brace in Java opens a block. A brace in JSON opens an object. A colon in Python opens a suite. The same colon in YAML starts a mapping. Treating those as one problem is why most format-anything pages quietly wreck one of the files you paste.
This universal code formatter is a desk with five printers behind the button. Not a style guide.
Pick a language or leave Auto-detect on. Indent is rebuilt inside the tab. Nothing is uploaded. The 2 MB ceiling is real. A whole repository belongs in Prettier, Black, gofmt, or rustfmt sitting on disk, not here.
The guess chip is a ranking, not a compiler
Auto-detect scores fragments against a list of signals. def plus a colon leans Python. <?php is PHP. An opening { as the first non-space character plus a successful JSON parse is JSON. Confidence is the gap between the winner and the runner-up.
JavaScript and TypeScript share most of those signals. C and C++ share #include. A YAML mapping looks a lot like a Python keyword-argument list if you only count colons.
When the chip reads low confidence, read the output before you keep the result. Better: pick the language yourself. The ranking is a convenience for a paste whose origin you forgot. The ranking is not a substitute for knowing what you copied.
Split the clipboard before you hit Format. Auto-detect scores the whole paste as one document. A stack trace glued to a config file produces a confident wrong language more often than a useful indent.
Five printers sit behind one button
One Format click does not run one algorithm. The language pick, or the guess, chooses a printer. Indent width is the only shared setting, 2 spaces, 4 spaces, or a tab.
- Brace walker
- JavaScript, TypeScript, Java, C, C++, C#, PHP, Go, Rust. Indent follows
{ },( ),[ ]. Strings and comments are masked so a brace inside"{ ok }"never moves the counter. Preprocessor lines starting with#stay flush left in C, C++, and C#. - Keyword walker
- Ruby and Lua. Indent follows
def,function,if,do,classdown toend. A missingendleaves a warning on the status bar. Identifiers are never rewritten. - Space rescale
- Python and YAML. No braces to count. Leading width is measured, a step is inferred, every line is remapped onto the unit you picked. Body text stays character for character.
- Markup
- HTML and XML. Nesting of tags. Content inside
<script>is handed to the JavaScript walker. Content inside<style>is handed to the CSS walker.<pre>,<textarea>, and CDATA stay as typed, because whitespace there is data. - Style
- CSS and SCSS. Rules and declarations split onto their own lines. Comments collapse to one line. Declarations pick up a space after the colon.
- SQL
- Clauses land on their own lines:
SELECT,FROM,WHERE, joins,GROUP BY,ORDER BY. Quoted identifiers stay quoted. Parentheses around a subquery add a level. - JSON
- The only printer allowed to refuse.
JSON.stringifypretty-prints a successful parse. A failure prints the parser message. Values do not move. Trailing commas are errors, not repairs.
JSON is the only printer allowed to refuse
Every other engine still emits a best-effort indent after a warning. Unbalanced brackets in JavaScript, unpaired end in Ruby, mixed tabs in Python: the right pane fills anyway. The status bar is the part to read. A warning there means the right pane is a sketch, not a file you commit.
JSON does the opposite. Parse fails, the right pane stays empty, the status bar quotes the token the parser rejected. A leading HTTP/1.1 200 OK line from curl -i is the usual cause. Peel the headers off, or open the API response formatter, which strips status lines, XSSI guards, and double-encoded payloads before parsing.
Minified source is exploded first
A webpack dump on one line. A SQL query copied from a log. A CSS file with every rule jammed together.
If the average live line is longer than 110 characters, or any line is longer than 240, the brace engine splits on {, }, and ; before indenting. Strings are masked, so a semicolon inside "a;b" does not start a new line.
const load=(id)=>{const r=fetch("https://api.toolexe.com/v2/invoices/"+id);return r.then(x=>x.json());}const load = (id) => {const r = fetch("https://api.toolexe.com/v2/invoices/" + id);
return r.then(x => x.json());}Spacing around = and => in the sample above is already in the source. The walker does not insert operator spaces. Indent is the job. Operator style belongs to a language page, Prettier for JavaScript, the Python formatter for PEP 8.
Python and YAML refuse to count braces
Python has no braces to count. Indentation is the block structure. The space engine finds the greatest common divisor of existing leading widths, then remaps each line onto the unit you picked. A file written with three-space indent, a file written with tabs, a file where two people disagreed, all three land on the same grid.
The cost shows up on the status bar. No consistent step? Nesting is read one column at a time. Tabs mixed with spaces? The rescale treats one tab as four columns. If your editor used eight, the result looks wrong on purpose, so you notice.
YAML follows the same rescale, with one extra lock. A line ending in | or > starts a block scalar. Lines indented further than the parent stay untouched. The spaces inside a literal block are content. Strip them and the string your config parser returns changes.
Load the sample while Python is selected, or while Auto-detect is on with a def in the pane, to see the rescale. Do not expect keyword spacing. total=0 stays total=0. For total = 0, open the Python page.
Leave this desk once the language is known
A dedicated formatter knows more than indent. Use this page for a paste whose language you have not decided, a snippet from chat, a file you need readable before you pick a desk. Do not use this page as a repository formatter. There is no .prettierrc. There is no gofmt fidelity. There is no rustfmt edition flag.
- Java imports, attached braces versus Allman: the Java beautifier.
- Type punctuation a JavaScript walker will mangle: the TypeScript beautifier.
- GraphQL, where commas are whitespace: the GraphQL formatter.
- A JSON body you already trust: the JSON beautifier.
PHP mixed with HTML is the awkward case. The brace walker sees PHP. The markup walker sees HTML. A file with both, <?php in the middle of a template, gets one printer. Expect the other half to look worse. Split the regions, or open the PHP beautifier when the file is mostly PHP.
Two megabytes is the honest stop
Formatting runs in JavaScript inside this tab. Closing the tab drops both buffers. There is no account, no paste history, no URL fetch. A private schema, a production query, a customer dump, none of those leave the machine.
Pastes over 2 MB are refused. Ace holds the whole string in memory twice, once per pane. A 40 MB SQL dump belongs in sqlformat or pg_format on your machine. The refusal is the feature. A tab trying to pretty-print a warehouse export will lock the browser before the indent finishes.
Read the guess chip. Read the status bar. Copy only after both look boring.
