Stylesheets grow by accretion: a reset, a component, an override, a media query, a fix for the override. Minification claws back the bytes that process leaves behind — comments, indentation, repeated rules — without touching what the cascade actually computes. The skill is knowing which rewrites are guaranteed safe and which only feel safe.
csso (MIT) has been the trusty CSS optimizer in toolchains for a decade, and it offers two levels. To make the difference concrete, we ran its exact browser build over a 772-byte sample stylesheet — custom properties, three rules, a hover state, a media query:
| Pass | What happens | Sample → | Saved |
|---|---|---|---|
| Keep structure | Comments, whitespace, trailing semicolons removed; values folded | 572 B | 25.9% |
| Restructure | Plus merged duplicate selectors, overridden declarations dropped | 555 B | 28.1% |
| Gzipped versions | Transport compression on top | 326 / 321 B | Gap nearly closes |
Notice the last row. After gzip, the two passes land five bytes apart — compression already squeezes the repetition that restructuring removes. The restructure win is real but modest; choose it when you trust your regression testing, skip it when you want byte-predictable output.
Modern minifiers parse CSS into an AST and regenerate it, so the output is valid by construction. Within that, the value rewrites are equivalences the CSS specification defines:
#ffffff → #fff — three-digit form where the pairs repeat0.10 → .1 — leading zero dropped24px 24px 24px 24px → 24px — four-value shorthand collapse0px → 0 — units removed from zero lengths0px 0px 8px 0px → 0 0 8px — both rules togetherOur sample hit every one of those. None of them can change rendering, because they're not judgment calls — they're alternative serializations the spec defines as identical. If a minifier you're evaluating produces "clever" rewrites beyond this class (dropping !important, reordering properties that interact), look closer before trusting it.
The scary-sounding option deserves a precise answer. Restructuring merges rules that share a selector, removes declarations that later rules unconditionally override, and merges selectors with identical blocks. Each of those preserves the computed styles — what the browser finally applies to each element — while changing the source order that produced them.
Where it can bite: tools that assume source structure. Visual-regression suites that diff CSS files, style guides generated from stylesheet comments (comments are gone anyway after minification), and hand-edits to the minified file, which you then can't re-minify cleanly. The discipline that avoids all three: minified CSS is a build artifact. Edit the source, re-run the minifier, ship the result. You can try both passes on your own stylesheet with the CSS Minifier — it runs csso in your browser and shows byte and gzip columns for each pass.
Two modern-CSS features worry people unnecessarily. Custom properties (--brand: #6366f1) are declarations like any other and pass through untouched — our sample's :root block survived every pass intact. Media queries are minified inside-out: their contents get the same treatment as top-level rules, and merging happens only within the same query. A @media (max-width: 640px) block stays a block; it doesn't dissolve into the top level or merge with a differently-query'd twin.
The features that genuinely deserve test attention are the ones minifiers conservatively leave alone or that interact with ordering: @layer rules, container queries with style conditions, and any selector relying on :where()'s zero specificity. Those are newer than most minifier test suites; a quick visual check after your first restructured build is cheap insurance.
At build time, for anything served repeatedly — the same rule as JavaScript. Sass and PostCSS setups usually have a minification step waiting in their plugin ecosystems; standalone stylesheets and CMS-embedded blocks are where a browser tool earns its keep, the same way one does for scripts. And measure what you ship: run your stylesheet through both raw and gzip columns before celebrating, because a 28% raw win that becomes 4% over the wire changes how much the effort was worth.
One habit worth keeping regardless of toolchain: never let the minified file become the source. Version-control the readable stylesheet, generate the artifact, and treat any diff between the two as a build step to re-run, not a conflict to resolve.
Minify every stylesheet you ship — structure-safe by default, restructured when your tests are good — then let gzip do its part. Expect a quarter off hand-written CSS raw, less over the wire, and nothing off the design if you stick to spec-defined rewrites. Start with the CSS Minifier (csso in your browser, both passes, gzip columns), and handle the rest of the payload with the Minify JS and Minify HTML siblings.
csso 5.0.5 in your browser: keep-structure or restructure, byte and gzip columns, custom properties and media queries preserved.
CSS Minifier →