CSS & JS Minifier
Strip comments and whitespace from CSS and JavaScript.
Safe minification only — comments and redundant whitespace. Variables are not renamed, and spacing inside calc() is preserved, since removing it would produce invalid CSS. Always test minified output before deploying.
About this tool
Shrink a stylesheet or script by removing comments and unnecessary whitespace, with a live byte count showing the saving. Useful for a quick inline snippet where wiring up a full build step would be overkill.
How to use it
- Pick CSS or JavaScript.
- Paste your source.
- Copy the minified output and check the size saving.
Why calc() keeps its spaces
Most CSS minifiers strip whitespace around operators. Inside calc() that produces invalid CSS, and the declaration is dropped entirely by the browser:
width: calc(100% + 2rem); /* valid */
width: calc(100%+2rem); /* invalid */
The CSS specification requires whitespace around + and - in calc() because +2rem is ambiguous — it could be a signed number rather than an addition. * and / do not have this problem, but the safe move is to leave all of them alone.
This minifier collapses whitespace around {, }, :, ;, , and > only, which is where the savings are anyway. The + and ~ sibling combinators keep their spaces as a side effect — slightly larger output, no broken stylesheets.
Safe minification versus mangling
There are two levels of JavaScript minification and only one of them is safe to do without a test suite.
Safe: removing comments and collapsing whitespace. The code is identical to the parser; only the bytes shrink. That is what happens here.
Mangling: renaming local variables to single letters, inlining functions, dropping unreachable branches. This gives much larger savings and requires full parsing plus a set of assumptions about your code. When those assumptions are wrong — code relying on Function.prototype.name, on a class name string, or on with — it breaks in ways that only appear in production.
Line breaks are preserved here, which matters because JavaScript inserts semicolons automatically at line ends. Joining everything onto one line can change behaviour around return statements.
For production, mangle in your bundler where tests run against the output. Use this for a snippet or an inline block where setting up a build step is not worth it.
Frequently asked questions
- Does this rename variables?
- No. It performs safe minification — comments and whitespace only. Identifier mangling needs full parsing and is better handled by your bundler, where it can be verified by tests.
- Will it break my code?
- String and template literal contents are preserved, as are regex literals. That said, always test minified output before deploying, exactly as you would with any build tool.
- Could my source code be retained?
- There is nowhere for it to be retained. Minification runs in the browser tab, so proprietary scripts and stylesheets are never transmitted or stored.