Code Formatter
Format and minify JSON, YAML, XML, HTML, and CSS in your browser — indentation only, never a change in meaning.
Settings
Input
paste your codeOutput
Format your code and the result appears here.
About this code formatter
Formatting is a pure syntactic transform. Whitespace, line breaks, and indentation change; meaning does not. A formatter that alters what your code does is not a formatter with a bug — it is a corruption tool. Every language here is parsed into a structure first and printed back out from that structure, so the output is a faithful re-rendering rather than a pile of regex substitutions applied to text.
Languages supported
- JSON – parsed with
JSON.parse, falling back to JSON5 so comments and trailing commas are accepted and normalized into strict JSON. - YAML – round-tripped through a real YAML document parser, which re-emits consistent indentation and resolves anchors.
- XML and HTML – tokenized into a tag tree that tracks quoting inside attributes, void elements, and HTML’s implicit end tags.
- CSS – a brace and semicolon indenter that walks strings, comments, and parentheses as units so nested at-rules and urls survive intact.
Why a parser and not a regex. Text that looks like structure very often is not. A CSS declaration can contain a closing brace inside a quoted string; an HTML attribute can contain a > character; a script block can contain < used as a comparison. Comments turn up in positions no pattern anticipates. A tokenizer that understands quoting handles all of these; a pattern match on braces or angle brackets silently mangles them.
Idempotence is the correctness test. Formatting already-formatted code must produce identical output. If a second pass changes anything, the formatter is not describing a canonical form and its output will churn in every diff. Each language here is checked against that property, including the awkward cases — preserved <pre> and <textarea> blocks, whose contents are whitespace-significant and are reproduced byte for byte.
Tabs versus spaces is a team convention, not a correctness question, so both are offered — with one exception. YAML forbids tabs as indentation outright, so the option is disabled there rather than quietly producing a file that no parser will read.
Why JavaScript and TypeScript are not here. Formatting them correctly requires a full parser. Automatic semicolon insertion means a line break in the wrong place changes what a program does; template literals, regex literals, and JSX all defeat naive tokenizing. A regex-based JavaScript formatter does not produce imperfect output, it produces broken code. A tool that formats five languages losslessly is worth more than one that claims ten and quietly damages your source. SQL is excluded for the same reason: keyword-based line breaking mangles dialect-specific syntax and string literals.
Everything runs locally in your browser. Nothing you paste is uploaded, which makes this safe for configuration files and payloads that contain credentials.