Skip to content
Back to all articles
Developer3 min readNovember 20, 2026

How to Minify CSS (and How Much It Really Saves)

What CSS minification removes, real savings with and without gzip, the selectors and strings that can change, and when to use a build tool instead.

How to Minify CSS (and How Much It Really Saves) article
In this guide
  1. What minification removes
  2. How much it saves
  3. Two cases where a simple minifier changes meaning
  4. How to minify CSS
  5. Good habits
  6. Related

Minified CSS is the same stylesheet with everything a browser ignores taken out. It is one of the first things page-speed tools like Lighthouse suggest, and it takes seconds to do. This guide explains what is removed, what you save, and the two cases where a simple minifier can change how your styles behave. To minify a stylesheet now, paste it into the free CSS Minifier.

What minification removes

Before:

/* Primary button */
.button {
  color: #ffffff;
  padding: 8px 16px;
  border-radius: 6px;
}

After:

.button{color:#ffffff;padding:8px 16px;border-radius:6px}

The basic steps, which every minifier does:

  • Remove comments.
  • Remove line breaks and indentation.
  • Remove spaces around { } : ; ,.
  • Remove the last semicolon in each rule, which CSS allows.

Spaces that matter stay. padding: 8px 16px keeps the space between the two values, and calc(100% - 2rem) keeps the spaces around the minus sign, which CSS requires.

Advanced minifiers used in build tools, such as cssnano and Lightning CSS, also:

  • Shorten colours: #ffffff → #fff, rgb(255,0,0) → red
  • Remove zero units: 0px → 0
  • Merge duplicate selectors and rules
  • Combine longhand properties into shorthand
  • Remove rules that can never apply

How much it saves

On a commented, indented stylesheet, the basic steps save roughly 15–35% of the raw size. Advanced minifiers add a few more percent.

Servers almost always send CSS compressed with gzip or Brotli, which already squeezes repeated whitespace very well. After compression, minification typically saves only a few more percent. That still matters on large stylesheets and on slow mobile connections, and it is free once it is part of your build — but compression and removing unused CSS are bigger wins.

Where minifying by hand is genuinely useful:

  • Email templates, where `` blocks count toward Gmail's ~102 KB clipping limit
  • WordPress Additional CSS, theme option boxes and page-builder custom CSS fields
  • Critical CSS inlined into the page ``
  • Small static sites with no build step

Two cases where a simple minifier changes meaning

1. A space before a colon in a selector

These two selectors are different:

.menu :hover   /* any hovered element inside .menu */
.menu:hover    /* .menu itself, when hovered */

A minifier that removes spaces around every colon turns the first into the second. The fix is to make the descendant explicit before minifying — .menu *:hover — which means the same thing and survives minification. The same applies to :focus, :first-child and other pseudo-classes written after a space.

2. Text inside quotes

Simple minifiers do not know about strings, so in

.note::before { content: "Note: read this, please"; }

the spaces after the colon and comma inside the quotes can disappear, giving “Note:read this,please”. Check any content values, font-family names in quotes and url("…") paths after minifying. Build-tool minifiers parse CSS properly and leave strings alone.

How to minify CSS

Quick, one-off: paste into the CSS Minifier, check the bytes saved, copy the result. Runs in your browser.

In a project: let your build do it on every deploy, so the source stays readable:

  • Vite, Next.js and most modern frameworks minify CSS automatically in production builds.
  • PostCSS with the cssnano plugin.
  • Lightning CSS, a fast standalone minifier and transformer.

Good habits

  1. Never edit the minified file. Keep a readable source, edit that, minify again.
  2. Keep a source map in projects, so browser dev tools point you to the original lines.
  3. Test after minifying — especially pseudo-class selectors and quoted strings.
  4. Turn on gzip or Brotli on your server; it gives the largest saving.
  5. Remove unused CSS before minifying. A 200 KB framework stylesheet of which you use 10% is the real problem. The CSS Usage Analyzer helps find unused rules.

The page's markup can be minified too with the HTML Minifier — our guide to HTML minification covers what to check there.

Was this article helpful?

Found this guide useful?

Share it with someone who is struggling with the same problem.

Free tool · No sign-up

CSS Minifier

Minify CSS in your browser: strip comments, line breaks and spaces around braces, colons and semicolons, and see how many bytes you saved.

Open tool

Written by

Hemant Adhikari HemantInsights

Senior Software Engineer · Developer of Toolyconvert

I’m a senior software engineer from Dehradun, India, building websites since 2014. I designed and developed Toolyconvert, from the Next.js front end and headless WordPress back end to the tools themselves, and I review every guide before it goes live.