How to minify CSS

Minifying CSS means stripping out everything a browser does not need — comments, line breaks and extra spaces — so the file downloads faster. Here is what minification removes, three honest ways to do it, and when to leave your stylesheet alone.

What minifying does to a stylesheet

Comments and whitespace, gone

A stylesheet written for humans is full of things a browser ignores: comments explaining why a rule exists, blank lines grouping related rules, indentation showing the structure, and spaces around every brace and colon. Minifying removes all of that. A rule like .button { background: #2563eb; color: white; } becomes .button{background:#2563eb;color:#fff} — the same rule, fewer bytes, no change in behaviour.

What it never does: rename a class

A careful minifier also removes the final semicolon before a closing brace, because the brace already ends the declaration. What it never does is rename a class, reorder a rule, merge selectors or change a value. The output is the same stylesheet with the air taken out, and a browser parses it exactly as it parsed the original.

Three ways to minify CSS

A browser tool for one-off jobs

The quickest way is a browser tool: paste the stylesheet, click a button, copy the result. That is the right call for a one-off job — a theme file, a snippet for a CMS, a stylesheet you inherited and want to ship smaller. Our CSS Minifier does exactly that, in your browser, with the before-and-after size shown so you can see what was saved.

A build tool for regular shipping

For a project you ship regularly, a build tool is better. cssnano, Lightning CSS and esbuild minify automatically on every deploy, and they can also do the advanced optimisations a simple minifier skips — merging duplicate rules, shortening colour values, removing unused declarations. The third route is your editor: most code editors have extensions that minify the open file on demand, which suits a quick check without leaving your workflow.

How much smaller, and does it matter?

A typical hand-written stylesheet shrinks by 20 to 40 percent when minified. A 50 KB file often comes out near 30 KB. That sounds small, but stylesheets block rendering: a browser waits for the CSS before it paints the page, so every kilobyte saved is time saved on first paint, especially on a slow mobile connection where the difference is visible.

Minifying also stacks with compression. A server that serves gzip or Brotli compresses the minified file further, and the two savings add up rather than overlap. Minify first, then let the server compress — the combination is the standard way production CSS is shipped, and it costs nothing once it is set up.

Minify CSS in the browser

  1. Open the CSS Minifier and paste your stylesheet into the Input box.
  2. Click Minify CSS. Comments and unneeded whitespace are removed; strings, calc spacing and media queries are left intact.
  3. Check the size readout to see how many bytes were saved, and skim the output to confirm nothing looks wrong.
  4. Click Copy output or Download to save the minified file, then use it on your live site.
  5. Keep your original readable stylesheet for editing — minify a fresh copy each time you change it.

Keep the original safe

Nobody edits a minified stylesheet, and nobody should have to. The readable file is the source of truth: it holds the comments that explain why a rule exists, the grouping that shows which rules belong together, and the formatting that makes a change safe to attempt. The minified file is a disposable product of the original, regenerated whenever the original changes.

Build tools make this painless with source maps — small sidecar files that let browser developer tools show the original file while debugging, even though the browser downloaded the minified one. If you minify by hand, you give that up, which is another reason to keep the original close and to minify only copies, never the only version.

When not to minify

A stylesheet under a kilobyte is barely worth minifying — the saving is a few hundred bytes, and the extra step adds a chance to ship the wrong file. Skip it for tiny snippets, and skip it while you are actively debugging: reading minified CSS in developer tools is miserable, and the time you lose far exceeds the bytes you save.

The same goes for files you edit every day. If a stylesheet changes constantly, a manual minify step will be forgotten, and the live file will drift out of sync with the source. That is the moment to switch to a build tool that minifies on deploy, so the process happens whether or not anyone remembers it.

Related guides

Questions people ask

Will minifying break my stylesheet?

No, as long as the CSS is valid to begin with. Minifying only removes comments and whitespace, and a careful minifier protects quoted strings, calc spacing and media queries, so the output means exactly what the original meant.

Do I still need gzip if I minify?

Yes. Minifying shrinks the file itself, while gzip compresses it during transfer. The two stack: a minified file compresses smaller than the original would, so production sites use both.

Can I un-minify CSS later?

You can format it back into readable code, but the comments are gone for good — minification deletes them. That is why the original file must be kept safe.