Cadmeo

Code Formatters and Minifiers

These 10 code formatters and minifiers handle JSON, XML, HTML, CSS, SQL and JavaScript. Each parses the document before printing it, so an invalid file is reported with a line and column rather than quietly rewritten.

10 tools

How these formatters treat your code

Six format or minify a language: JSON, XML, HTML, CSS, SQL and JavaScript. Formatting and minifying are the same parse with two output styles, which is why the JSON tool does both from one page rather than splitting them across two.

Three are viewers rather than formatters. The JSON viewer renders a document as a collapsible tree and counts the children of each branch before you open it. The CSV viewer opens a file as a sortable table using an RFC 4180 parser. The SVG viewer previews markup at any zoom against four backgrounds and reports the viewBox.

The formatters refuse to change meaning. The HTML formatter leaves whitespace-sensitive elements exactly as written and keeps short inline elements on one line, because re-indenting either would change what the page renders. The XML formatter leaves an element containing only text on a single line for the same reason.

The minifiers protect string contents. Removing a comment from CSS must not touch a comment-like sequence inside a string, and the CSS minifier reports the exact bytes saved so you can judge whether it was worth doing at all once gzip is accounted for.

The Markdown table generator is the one that produces rather than reformats, turning comma, tab or pipe-separated data into an aligned GitHub-flavoured table with per-column alignment.

Format, minify or view

Three tools can act on the same JSON document, and picking the wrong one is the most common confusion here.

Format, minify or view, matching a situation to the tool that answers it
What you wantThe tool
Readable text to paste elsewhereJSON formatter, which pretty-prints and hands back text
To explore a large document on screenJSON viewer, a collapsible tree with each branch counted
The smallest possible fileThe minify mode in the formatter, or the dedicated CSS minifier
To read a query somebody sent as one lineSQL formatter, which breaks before each clause keyword
To open a CSV without a spreadsheetCSV viewer, sortable and filterable, parsed to RFC 4180
To check what an SVG actually containsSVG viewer, reporting the viewBox and the element count

Frequently asked questions

Will minifying break my file?

No, when the input is valid. Each minifier parses the document first and removes only whitespace and comments that carry no meaning, leaving the inside of every string untouched. An invalid document is reported rather than minified, because guessing what was intended would be worse.

Is minifying worth it when the server already uses gzip?

Often marginal. Gzip removes most of what minification targets, so the saving on top is smaller than the raw byte count suggests. Judge it on the compressed size rather than the uncompressed one. It costs nothing to do, so the honest answer is to measure rather than assume.

Why does the HTML formatter leave some elements unindented?

Because indenting them would change the rendered page. Whitespace inside a pre or textarea element is displayed literally, so adding indentation adds visible spaces. Short inline elements stay on one line for the same reason: breaking them introduces whitespace between words.

Does the JSON formatter validate as well as format?

It has to. Formatting means parsing the document and printing it again, so anything that cannot be parsed cannot be formatted. When parsing fails the tool reports the line, the column and the offending text, which is the same information the dedicated validator gives.