About Code Formatter
Useful for making a minified payload readable again, for checking that a config parses before you ship it, or for stripping a file down for production. Switching language keeps whatever you have already pasted.
Strip the comments, whitespace and line breaks out of a stylesheet to ship a smaller CSS file that downloads and parses faster. Paste your CSS and copy the minified output — it is compressed in your browser and never uploaded.
Paste messy or minified code and instantly beautify, minify or validate JSON, HTML, CSS, SQL, XML and YAML. Beautifying re-indents your source with consistent spacing so it is easy to read and review; minifying strips whitespace and comments to ship smaller files; validating surfaces syntax errors with the exact location so you can fix them fast.
It also doubles as a converter between common data formats — JSON to CSV, CSV to JSON, YAML to JSON and back — which is handy when wiring up APIs, configs or spreadsheets. Converting is where structure mismatches surface: CSV has no nesting, so a nested JSON object has to be flattened or dropped.
Validation errors cluster into a small set worth recognising by shape, because the parser's message often points at the end of the file rather than the mistake. A trailing comma after the last item is legal in JavaScript and illegal in JSON, and is by far the most common cause. Single-quoted strings and unquoted keys are valid JavaScript object literals and invalid JSON, which is why pasting a console-logged object into a config file so reliably fails. NaN, Infinity and undefined have no JSON representation at all, yet serialisers emit them anyway.
Minifying deserves a moment of scepticism. Stripping whitespace shrinks a file, but gzip and Brotli already compress repeated whitespace to almost nothing over the wire, so the real-world saving on a text asset is far smaller than the byte count suggests. Minify what ships to a browser; leave configuration and fixtures readable, since a diff on a minified file is unreviewable and that costs more than the bytes.
Indentation width is worth deciding once and applying everywhere rather than per file. Mixed indentation is invisible until a diff shows every line as changed because someone's editor expanded tabs differently, at which point a one-line fix becomes an unreviewable pull request. Two spaces is the common default for JSON, YAML and web languages, and YAML in particular forbids tabs outright — a tab in a YAML file is a parse error, not a style preference.
Common use cases
- Shrinking a hand-written stylesheet before uploading it to a site with no build step
- Trimming critical CSS that gets inlined into the document head
- Checking how much of a stylesheet's size is comments and formatting