CSS Minifier and Beautifier - Compress or Expand
CSS minifier and beautifier
What this tool does
Two opposite jobs on the same stylesheet. Minifying strips what only humans need - comments and indentation. Beautifying puts it back so a file you inherited becomes readable. Both work on the text you gave, and both leave the meaning of the CSS alone.
How to use it
- 1 Paste the CSS - a whole file or a single rule.
- 2 Press Minify to compress, or Beautify to expand with indentation.
- 3 Check the byte count, then copy the result.
A space in a selector is not decoration
".a .b" matches a .b inside a .a; ".a.b" matches one element carrying both classes. They are different selectors, and a minifier that treats the space as slack silently paints the wrong elements. Here the space between two selector parts always survives - only the space around combinators like > and + is dropped.
calc() needs its spaces
In "calc(100% - 10px)" the spaces around the minus are required by the grammar: without them a browser reads "-10px" as a negative length, the expression becomes invalid and the whole declaration is thrown away. Nothing warns you - the layout is simply wrong. This tool never removes whitespace inside parentheses.
License comments stay
A comment that opens with /*! carries a copyright or licence notice, and by convention every minifier keeps it. Stripping it would remove the attribution a library asked you to ship. Ordinary /* comments are for you and your team, so those go.
Minifying CSS is worth less than gzip
Servers already compress stylesheets on the way out, and gzip is very good at repeated whitespace - so minifying on top of it usually saves a few percent, not half. Do it because the file is what ships and you want it small and stable, not because you expect the page to load noticeably faster.