Minify CSS
Comments, whitespace and the last semicolon.
Everything is processed in this tab. Nothing you paste is sent anywhere.
Every tool runs entirely in your browser. Your files are never uploaded to a server.
Minifying CSS removes comments and whitespace the parser ignores, and can shorten #ffffff to #fff and 0px to 0. Strings are left alone, because whitespace inside them is rendered content.
How to use CSS Minifier
- Paste your CSS. A single rule or a whole stylesheet.
- Choose the optimisations. Comment removal and value shortening are independent.
- Copy the result. Bytes saved are shown as an absolute and a percentage.
About minifying CSS
CSS minification removes what the parser ignores: comments, the whitespace between tokens, and the final semicolon before a closing brace. None of it changes how the stylesheet is interpreted, which is what makes minification safe in principle. In practice the safety depends on knowing where the parser stops ignoring things. Strings are the boundary. A content property with deliberate spacing renders that spacing, a url() may contain characters that mean something to the tokeniser, and a quoted font family can contain whatever the font is called. Collapsing whitespace inside any of those changes behaviour, so strings are extracted before the whitespace pass and restored afterwards. A minifier that runs a global whitespace collapse over the whole file will eventually corrupt one of them. Value shortening is a second category and is more nuanced than it appears. A six-digit hex colour can be shortened to three only when each pair repeats, and a zero length needs no unit — but a zero time does in some contexts, where a bare 0 is invalid. Excluding time units is the kind of distinction that separates a minifier you can run on a real stylesheet from one that works on the example in its own documentation. It is also worth keeping expectations calibrated. Twenty to thirty percent of raw bytes is a typical saving, and most of that is whitespace that compression was already handling. Over a gzipped connection the real gain is a few percent — genuinely worth having in a build step, and not a reason to make source unreadable.
Frequently asked questions
Why are strings left untouched?
What is a /*! comment?
Is shortening 0px to 0 always safe?
Does removing the last semicolon break anything?
How much does this save in practice?
Last updated