What minification actually removes
CSS minification strips what the browser does not need: comments, indentation, line breaks, the final semicolon in a block, and empty rules. Applied to typical hand-written CSS that removes 25–40% of the bytes before compression.
Where naive minifiers break stylesheets
The common shortcut is a regular expression that deletes whitespace around {, }, :, ; and ,. It fails in four places that appear in real code:
- Inside strings —
content: "hello, world"loses the space after the comma, changing what the page renders. - In
calc()—calc(100% - 2rem)becomescalc(100%-2rem), which is invalid and drops the declaration. - In selectors —
a :hoverbecomesa:hover, a completely different selector. - In at-rules —
@media (min-width: 600px)becomes@media(min-width:600px), which is not valid.
This minifier tokenises the stylesheet instead, so those cases survive. Beautify reverses the process when you need to read minified CSS.
For the markup around your styles, see the HTML beautifier, and for scripts the JavaScript formatter.