What gets removed
- Comments, except
/*! ... */licence comments when you choose to keep them. - Line breaks, indentation, and spaces around
{,},:,;, and,. - The final semicolon in each rule, which the browser does not need.
- Rules with no declarations, such as
.unused { }. - Redundant characters in values:
#ffffffbecomes#fffand0.5embecomes.5em.
What must be left alone
- Descendant spaces:
div :first-childanddiv:first-childselect different elements. - calc() operators:
calc(100% - 10px)is invalid without the spaces around the minus sign. - Strings and url(): anything in quotes, such as
content: " → ", must stay exactly as written. - Zero units in some places:
0pxcan usually become0, but not insidecalc(), so careful minifiers skip it.
This is why a good minifier reads the structure of the stylesheet instead of running a few find-and-replace rules over it.
How much it saves
Hand-written, well-commented CSS typically shrinks by 15 to 30%. Server compression (gzip or Brotli) then shrinks the file much further, and the two work together: minify first, then compress. Because CSS blocks the page from rendering until it has loaded, every kilobyte saved helps the first paint.
One-off or automatic
For a single file, paste it into the CSS Minifier. For a site you deploy regularly, add a minifier such as cssnano or Lightning CSS to your build so it happens on every release, and keep the readable source in version control.
Quick FAQ
Can minification break my CSS?
A careless minifier can, for example by removing spaces inside calc(). Test the minified file before deploying, and keep the original source.
Is minifying the same as compressing?
No. Minifying removes unneeded characters from the file itself. Compression such as gzip or Brotli encodes the file for transfer and is undone by the browser. Use both.
How do I read minified CSS?
Paste it into the CSS Beautifier to restore indentation and line breaks.