CSS Minification Explained

CSS minification makes a stylesheet smaller by removing text the parser does not need. Keep your editable source readable, generate the compact artifact in a repeatable step, and compare the rendered result before deployment.

Minify a small rule and inspect the result

Whitespace around a declaration colon or inside the margins of a rule is often removable. The space in a descendant selector is significant, as is the space inside the quoted value below. A parser-based minifier can treat those cases differently instead of stripping every space.

The tool keeps important license comments and source map directives. If you change the stylesheet after generating a source map, confirm the map matches the published asset. Otherwise DevTools can show misleading source locations.

CSS input
.card .title::after {
  content: "two words";
  margin: calc(100% - 1rem);
}
Result
.card .title::after{content:"two words";margin:calc(100% - 1rem)}

Keep minification separate from other optimizations

Whitespace minification reduces the stylesheet text. Gzip or Brotli reduces transfer size, and the browser decompresses the response before interpreting CSS. Measure both the uncompressed resource size and the transferred size in the Network panel.

Removing unused selectors is a different operation. A selector absent from one page can appear in a responsive layout, dialog or dynamically loaded component. Determine usage across the application before deleting rules. Keep aggressive transformations in a build step that can be tested.

Check the states that are easy to miss

Compare a page before and after minification at several viewport widths. Exercise interactive states and inspect generated content, custom properties and media queries. Check the stylesheet loads with the correct content type and without parse errors.

If a rule breaks, reduce it to one selector and the smallest affected declaration. Copy the exact shorthand, math expression or custom property value. Compare how the browser parses it in both versions before changing unrelated CSS.

Frequently asked questions

Does minifying CSS replace compression?
No. The two operate at different layers and can both be used.
Should I edit the minified file directly?
Keep authoring in the original source so fixes remain reviewable and the artifact can be regenerated.

Try it with these tools

Related developer guides