JSON Formatter
Pretty-print, validate and minify JSON with precise error positions.
Developer & Security
Strip comments and whitespace from CSS, JS and HTML safely.
Being precise about the boundary matters, because "minifier" covers two quite different classes of tool.
This one does safe minification: it strips comments, collapses whitespace runs, removes line breaks where the grammar permits, drops the final semicolon in CSS blocks, and shortens hex colors where equivalent. Every transformation is provably behavior-preserving.
It does not do mangling: renaming local variables to single letters, dead code elimination, tree shaking, constant folding, or scope hoisting. Those require full AST construction and scope analysis, and getting them wrong breaks code in ways that only surface in production.
For a build pipeline, use esbuild, Terser or SWC — they do the full job and they are correct. This tool is for the case where you have a snippet, no build step, and you want it smaller without risk.
| Language | Typical reduction | Plus gzip | Main saving |
|---|---|---|---|
| CSS | 25–35% | 80–85% | Indentation and comments |
| JavaScript (unmangled) | 20–30% | 75–82% | Comments and formatting |
| JavaScript (with mangling) | 45–60% | 82–88% | Variable renaming — not done here |
| HTML | 10–20% | 70–80% | Inter-tag whitespace |
| JSON | 15–30% | 85–92% | All whitespace |
The gzip column is the one that matters for a website, and it explains why minification is less dramatic than it appears. Compression algorithms already handle repeated whitespace efficiently, so minifying before gzipping typically saves an additional 5–12% rather than the headline 30%. It is still worth doing — it is free — but it is not where the big wins are.
Not with the transformations this tool applies, but there are three cases worth knowing about generally.
The first is automatic semicolon insertion in JavaScript. Code that relies on ASI can break when line breaks are removed. This tool preserves line breaks wherever removing one would change parsing, which is why the JS reduction here is lower than an aggressive minifier’s.
The second is significant whitespace in HTML. Whitespace between inline elements is rendered, so collapsing it can visibly close a gap between two words. Content inside <pre> and <textarea> is preserved verbatim for the same reason.
The third is conditional comments and license headers. Comments beginning /*! are preserved by convention, because many licenses require the notice to survive minification.
For a project with a build step, no — your bundler already does it, better, as part of the build.
The cases where a standalone minifier is genuinely useful are narrower but real: a snippet going into a CMS field or a Shopify theme, an inline script for a landing page with no toolchain, a WordPress custom CSS box, an email template, or a quick check of how much a file would shrink before deciding whether to set up tooling at all.
That last one is the most common. Minify the file here, look at the numbers, and decide whether a build step is worth the setup.
No, deliberately. Variable mangling requires full scope analysis and is where naive minifiers break code. Use esbuild or Terser in a build pipeline if you need it.
You can reformat it — a beautifier restores indentation. You cannot restore comments or original variable names, because those bytes are gone.
Yes. Comments starting with /*! are kept, following the convention every major minifier uses.
Marginally. It parses slightly faster because there is less to scan, but execution speed is unchanged. The real benefit is transfer size.
Before. Minify at build time, then let the server gzip or Brotli the result. The two are complementary.
No. Those need compilation first. Compile to CSS or JavaScript, then minify the output.
No. The tokenizer runs in this page — safe for proprietary code.