CSS Minifier

Paste a stylesheet and get it back minified โ€” comments gone, whitespace collapsed, hex colours shortened โ€” with a real byte count for what you saved.

What this minifier changes

It removes comments, collapses every run of whitespace, drops the space around { } : ; , and the combinators > + ~, deletes the final semicolon before each closing brace, shortens #ffffff to #fff where the pairs repeat, and trims the leading zero from values like 0.5rem. Those are all byte-for-byte safe transformations โ€” the browser parses the result identically.

What it deliberately does not change

It will not merge duplicate selectors, reorder properties, remove rules it thinks are unused, or rewrite shorthand. Those optimisations need to understand your whole site โ€” a "dead" rule is often applied by JavaScript, and reordering can change the cascade. A minifier that guessed would eventually break a layout in a way that is miserable to debug, so this one sticks to transformations that cannot change behaviour.

Strings, url() and calc() are safe

The tokenizer tracks quoted strings and url() values, so spaces inside them are preserved exactly. Spaces inside parentheses are also preserved, which matters for calc(100% - 2rem) โ€” stripping the spaces around that minus sign is a classic minifier bug that silently breaks the expression, because CSS needs them to tell subtraction from a negative number.

How much does minifying actually save?

Typically 15โ€“30% of the raw file. But your server almost certainly serves CSS with gzip or Brotli compression already, and those algorithms are very good at squeezing repeated whitespace โ€” so the saving after compression is smaller, often 3โ€“8%. Minify anyway: it is free and it stacks. Just do not expect it to fix a slow page on its own. If your CSS is 300 KB, the real win is deleting rules you no longer use, not compressing the ones you do.

Benefits

  • Removes comments and whitespace, shortens hex colours and trims leading zeros โ€” all byte-safe changes.
  • Preserves strings, url() values and the spaces inside calc(), which naive minifiers break.
  • Keeps /*! licence comments when you need to preserve attribution.
  • Reports the exact byte saving and warns about mismatched braces in the original.

Limitations to know

  • It does not remove unused rules, merge duplicate selectors or reorder properties.
  • The real-world saving is smaller than the number shown, because servers usually gzip CSS as well.
  • It does not add vendor prefixes or transform modern syntax for older browsers.

Common mistakes to avoid

  • Editing the minified file instead of the source, then losing the change on the next build.
  • Expecting minification to fix a slow page when the real weight is images, fonts or third-party scripts.
  • Minifying CSS that already has an unclosed comment or brace, which makes the existing error harder to spot.

Alternatives

For scripts use the JavaScript Minifier, for markup use the HTML Minifier, and to build effects before minifying try the CSS Gradient Generator.

Last updated: August 2026 ยท Reviewed by the AI Toolbox editorial team.

Frequently asked questions

Will minifying break my CSS?

Not with these transformations โ€” they are all whitespace and syntax level. If something looks wrong afterwards, check for an unclosed comment or brace in the original; minifying often exposes an existing error.

Should I minify if my server already gzips?

Yes, but expect a modest extra saving. Gzip handles repeated whitespace well, so minified plus gzipped is only a few per cent smaller than gzipped alone.

Does it remove unused CSS?

No. That requires scanning your HTML and JavaScript, and getting it wrong breaks pages. Use a coverage tool in your browser devtools for that job.

Is my stylesheet uploaded?

No. The minifier runs in your browser; nothing is sent anywhere.

Related tools