How to Minify CSS

March 22, 2026 · 7 min read

CSS minification removes whitespace, comments, and unnecessary characters from your stylesheets without changing how they work. The result is a smaller file that loads faster — often 20-50% smaller than the original.

This guide covers what CSS minification does, how to do it with build tools, and when (and when not) to minify.

What Does CSS Minification Do?

A CSS minifier performs several transformations:

Before Minification

/* Main navigation styles */ .navbar { display: flex; justify-content: space-between; align-items: center; padding: 16px 24px; background-color: #ffffff; border-bottom: 1px solid #e0e0e0; } .navbar .logo { font-size: 1.25rem; font-weight: 700; color: #333333; }

After Minification

.navbar{display:flex;justify-content:space-between;align-items:center;padding:16px 24px;background-color:#fff;border-bottom:1px solid #e0e0e0}.navbar .logo{font-size:1.25rem;font-weight:700;color:#333}

Same exact rendering in the browser, but significantly fewer bytes over the wire.

Minify your CSS instantly

Paste your CSS and get a minified version in one click — no signup required.

Open CSS Minifier

Why Minify CSS?

File size directly affects page load speed, and page load speed affects everything:

How to Minify CSS with Build Tools

1. PostCSS + cssnano (Recommended)

cssnano is the most popular CSS minifier in the Node.js ecosystem. It runs as a PostCSS plugin:

npm install postcss cssnano postcss-cli

Create a postcss.config.js:

module.exports = { plugins: [ require('cssnano')({ preset: 'default' }) ] };

Then run it:

npx postcss src/style.css -o dist/style.min.css

2. esbuild (Fastest)

esbuild is a bundler written in Go that's incredibly fast — it can minify CSS as part of the build:

npx esbuild src/style.css --minify --outfile=dist/style.min.css

esbuild is ideal when you need speed over maximum compression. It doesn't do advanced optimizations like merging rules, but it's 10-100x faster than cssnano.

3. Lightning CSS (Modern)

Lightning CSS (formerly Parcel CSS) is a Rust-based tool that also handles vendor prefixes and modern CSS transpilation:

npx lightningcss --minify src/style.css -o dist/style.min.css

It combines minification with features like automatic vendor prefixing and syntax lowering — a good all-in-one choice.

4. clean-css (CLI)

clean-css is a battle-tested minifier with aggressive optimization options:

npx clean-css-cli src/style.css -o dist/style.min.css

Build Tool Integration

Most bundlers and build tools have built-in CSS minification:

ToolMinificationNotes
Webpackcss-minimizer-webpack-pluginUses cssnano by default
ViteBuilt-in (esbuild)Enabled in production builds automatically
Next.jsBuilt-inAutomatic in production
ParcelBuilt-in (Lightning CSS)Zero config
Gulpgulp-clean-cssPlugin-based

If you're using a modern framework, CSS minification is probably already happening in your production build. Check your build output to confirm.

When NOT to Minify

CSS Minification vs. Gzip

A common question: "If the server gzips everything, do I still need to minify?"

Yes. Minification and gzip are complementary, not alternatives:

Think of it this way: minification removes waste, then compression squeezes what's left. You want both.

Quick Minification Online

If you need to minify a CSS file quickly without setting up a build pipeline, use the free CSS minifier on UtilShed. Paste your CSS, click minify, and copy the result. Everything runs in your browser — nothing is uploaded to a server.

Related tools: