CSS minifier
Strip comments and whitespace without breaking calc(), data URIs or quoted content. The readout shows exactly what you saved.
What it removes
Everything a browser does not read: comments, indentation, newlines, the space after every colon and comma, and the final semicolon in each block. On a hand-written stylesheet that is usually 20 to 35 percent of the file.
.card {
border: 1px solid #dee4ee;
border-radius: 12px;
padding: 20px 22px;
}
.card{border:1px solid #dee4ee;border-radius:12px;padding:20px 22px}
It does not rewrite values. Colours stay in the notation you wrote them in, 0.5em keeps its
leading zero, and shorthand is not collapsed. Those transformations save more bytes and carry more risk —
they belong in a dedicated build tool like cssnano or Lightning CSS, which have test suites behind them.
Where CSS minification actually pays
CSS is render-blocking. The browser will not paint until it has your stylesheet, which makes it worth more attention than HTML byte-for-byte. That said, the ordering of wins is not what people expect:
| Action | Typical effect | Effort |
|---|---|---|
| Enable gzip or brotli | 75–85% smaller | One server setting |
| Remove unused CSS | Often 60–90% smaller | A build step and some care |
| Minify | 20–35% before compression, a few percent after | A build step |
| Inline critical CSS | Removes one render-blocking request | Real work |
If your stylesheet is genuinely slowing the page down, unused rules are almost certainly the bigger problem. Most sites ship a framework and use a fraction of it.
Safe by design
The minifier tracks strings, comments and parentheses the same way the formatter does, so:
- A semicolon inside
url(data:image/svg+xml;base64,...)does not end the declaration. - A brace inside
content: "}"does not close the block. - Spaces inside
calc(100% - 2rem)are preserved — remove them and the expression breaks. - Spaces inside
grid-template-areasstrings are preserved.
Those four are where naive regular-expression minifiers fail, and they fail silently.
Doing it in a build
npx cssnano input.css output.css
module.exports = {
plugins: {
autoprefixer: {},
cssnano: { preset: "default" }
}
};
Vite, Next.js, Astro and every modern bundler minify CSS in production builds already. Check before you add anything — you may be doing this twice.
This page is for the cases with no build: a single landing page, a snippet going into a CMS field, an email template, or a quick check of how much a file would shrink.
Questions about this tool
Will minifying break my CSS?
It should not. Spaces that carry meaning — inside calc(), inside strings, between compound values like 1px solid red — are preserved. If you do find a case where it breaks something, send the input and it gets fixed.
Does it remove unused CSS?
No. That needs to know which selectors your HTML actually uses, which means analysing your whole site. PurgeCSS and Tailwind's own build do this; a standalone minifier cannot.
Should I minify CSS if my server already uses gzip?
The gain drops to a few percent, but it is free inside a build step, so yes. What you should not do is skip compression because you minified — compression is by far the larger effect of the two.
Can I get my formatted CSS back?
Switch to Format and the structure returns. Comments do not, if you stripped them. Keep your source file in version control and treat the minified version as a build artefact.
Related tools
CSS Formatter
Lay out stylesheets with consistent indentation.
OpenCSS Gradient Generator
Build linear, radial and conic gradients visually.
OpenBox Shadow Generator
Layer CSS shadows and copy the result.
OpenHTML Minifier
Strip whitespace and comments from HTML.
OpenJSON Minifier
Remove every unnecessary byte from JSON.
OpenJavaScript Minifier
Strip comments and whitespace, safely.
OpenLearn the why, not just the how
Longer reading on formatting, indentation and minification.