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
- CSS MinifierThe CSS minifier strips comments and whitespace safely, keeping licence headers intact and never touching the inside of a string, and reports the bytes saved.
- CSV ViewerA CSV viewer that opens a file as a sortable table with row filtering, parsed to RFC 4180 so quoted commas and embedded line breaks are handled correctly.
- HTML FormatterThe HTML formatter indents markup by nesting depth while leaving inline elements on one line and pre blocks untouched, so the rendered page never changes.
- JavaScript (JS) BeautifierThe JS beautifier reindents minified JavaScript so it can be read, with strings, regexes and comments left intact.
- JSON FormatterThe JSON formatter pretty-prints or minifies a document, sorts keys on request, and reports any parse error by line and column with the offending text shown.
- JSON ViewerA JSON viewer that opens a document as a collapsible tree, counting the children of every branch before you expand it, so a large file stays navigable.
- Markdown Table GeneratorThe Markdown table generator turns comma, tab or pipe-separated data into an aligned GitHub-flavoured table, with column alignment set per column as you like.
- SQL FormatterBreak a one-line SQL query onto readable lines, or collapse a formatted one back to a single line.
- SVG ViewerAn SVG viewer that previews markup at any zoom against four backgrounds, reporting the viewBox and the element count so you can see what a file really holds.
- XML FormatterThe XML formatter indents a document into a readable tree or minifies it to one line, leaving text-only elements untouched so no whitespace changes meaning.
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.
| What you want | The tool |
|---|---|
| Readable text to paste elsewhere | JSON formatter, which pretty-prints and hands back text |
| To explore a large document on screen | JSON viewer, a collapsible tree with each branch counted |
| The smallest possible file | The minify mode in the formatter, or the dedicated CSS minifier |
| To read a query somebody sent as one line | SQL formatter, which breaks before each clause keyword |
| To open a CSV without a spreadsheet | CSV viewer, sortable and filterable, parsed to RFC 4180 |
| To check what an SVG actually contains | SVG 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.