CSS Minification Guide: CSSO, Unused CSS, Builds

CSS Minification Guide: CSSO, Unused CSS, Builds

How to minify CSS in 2026: CSSO (and friends), unused-CSS removal, Vite/Webpack, vs an online minifier. Honest limits before you chase bytes.

29.10.2025
12 min read
Share this article:
CSSMinificationPerformanceOptimizationCSSOTutorial

What CSS minification does and does not do

Minifying CSS is not the same job as deleting unused rules, extracting critical CSS or enabling gzip/Brotli. Minification rewrites the stylesheet you already ship into a shorter form. Comments and whitespace go away, colors and zeros get shorter, and adjacent duplicate selectors can merge. Class names stay the contract with your HTML, unlike JavaScript mangling. You can try that step in the browser with the FastMinify online CSS minifier (CSSO, no upload). Production apps still belong in the build. This guide covers CSSO as it actually works, the unused-CSS tools that replaced PurifyCSS, Webpack and Vite, and when a paste box is enough.

Handwritten stylesheets typically shrink by 20–40% before gzip or Brotli, the range in our CSS tool documentation. It is not a ranking guarantee.
Smaller render-blocking CSS can help LCP; minification alone will not fix a 2 MB hero image or a late font
Unused-CSS removal (PurgeCSS, Tailwind content scan) is a different, often larger, win on framework CSS
Online CSSO is for a file or a few files; the build repeats the same pipeline on every deploy
Compression on the wire is still a server or CDN layer: add gzip or Brotli after you minify

Minify, remove unused CSS, compress

Three layers, three tools

A “CSS went from 1.8 MB to 420 KB” story is almost never minification alone. Such a drop usually combines unused-CSS removal on a framework dump, then minification, then gzip, so treat figures from marketing posts as mixed pipelines. FastMinify’s minifier does not scan your HTML. For the same split in JavaScript, see tree shaking vs minification.

CSS code on screen showing performance optimization
What actually moves Core Web Vitals

INP replaced FID as a Core Web Vital in March 2024. Minified CSS can reduce the download and parsing of render-blocking stylesheets, which may support LCP. It does not rename classes, extract above-the-fold rules or fix layout shift from unsized images. Measure with Lighthouse or CrUX, and do not promise a fixed number of milliseconds or a conversion lift. After minifying, still enable compression: see the Apache and Nginx GZIP/Brotli guide.

LCP: smaller blocking CSS helps when the LCP element depends on that file, but not when the bottleneck is a video or a late image
INP: minifying CSS is a weak lever, since long tasks are usually JavaScript
CLS: minification does not reserve image or font space, and aggressive CSSO restructuring can even reorder the cascade
Over the network: gzip or Brotli still applies after minification, so use both

Setting up CSSO (the minifier FastMinify uses)

Install and minify with real CSSO options

CSSO (CSS Optimizer) parses with CSSTree, then cleans, compresses and optionally restructures rulesets. FastMinify’s Minify CSS page runs CSSO in your browser. Its Compression Level setting decides how far that goes. Conservative keeps every rule and re-indents the output. Normal minifies and keeps the cascade order. Aggressive restructures rulesets, which can change source order. The snippets below use the public CSSO API.

Installation

npm install --save-dev csso csso-cli

API (Node)

const csso = require('csso'); const result = csso.minify(css, { restructure: true, comments: false }); console.log(result.css);

CLI

npx csso src/styles.css --output dist/styles.min.css # Safer preview (no structural merge): # npx csso src/styles.css --no-restructure -o dist/styles.min.css
The usage option is an allowlist, not PurgeCSS

CSSO’s `usage` option lets you list the tags, ids and classes that exist in your markup, which lets CSSO drop unused selectors. You must maintain that list. It does not scan `*.html` or `*.jsx` files, and class names built in JavaScript will disappear if you leave them out. For real unused-CSS removal, use PurgeCSS or Tailwind’s content paths, and keep `usage` for small, known surfaces.

CSSO configuration with documented minify options

Configuration

const cssoConfig = { restructure: true, comments: false, usage: { tags: ['div', 'span', 'a', 'img'], ids: ['header', 'footer', 'main'], classes: ['btn', 'card', 'nav'] } };

Usage

const fs = require('fs'); const csso = require('csso'); function minifyCSS(inputPath, outputPath) { const css = fs.readFileSync(inputPath, 'utf8'); const result = csso.minify(css, cssoConfig); fs.writeFileSync(outputPath, result.css); const pct = ((css.length - result.css.length) / css.length * 100).toFixed(1); console.log(`${inputPath} -> ${outputPath} (${pct}% smaller source)`); }

Removing unused CSS with PurgeCSS and Tailwind

PurgeCSS (not PurifyCSS)

PurifyCSS has not been maintained for years. In 2026, scan your content with PurgeCSS or with Tailwind’s built-in content and `@source` scan. FastMinify does not run this step. After you drop dead rules, minify the remainder with CSSO or cssnano, or paste a file into the online CSS minifier to check the result.

Installation

npm install --save-dev purgecss

PurgeCSS (v8 API)

import { PurgeCSS } from 'purgecss'; const [{ css }] = await new PurgeCSS().purge({ content: ['src/**/*.html', 'src/**/*.{js,jsx,ts,tsx}'], css: ['src/**/*.css'] });

Tailwind content paths without a second purge

// tailwind.config.js (v3) — list every template that can emit classes module.exports = { content: ['./src/**/*.{html,js,ts,jsx,tsx}'], theme: { extend: {} } }; /* Tailwind v4: prefer @source in CSS instead of a second PurgeCSS pass unless you know why you need both. Dynamic class strings still need a safelist. */

Webpack and Vite production CSS

Webpack minifies with cssnano through CssMinimizerPlugin, not with CSSO

A production Webpack CSS pipeline usually extracts files with MiniCssExtractPlugin and minifies them with css-minimizer-webpack-plugin. That plugin’s default engine is cssnano, not CSSO, although you can still run CSSO in npm scripts or a custom minimizer. Vite minifies CSS in production through build.cssMinify: Lightning CSS by default in recent versions, esbuild in earlier ones. Check the Vite documentation for the version you ship rather than copying a “default minifier” from a post written for another major version. For WordPress themes without a JS build, see WordPress minification plugins.

Configuration Webpack

const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const CssMinimizerPlugin = require('css-minimizer-webpack-plugin'); module.exports = { mode: 'production', module: { rules: [ { test: /\.css$/, use: [ MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader' ] } ] }, plugins: [ new MiniCssExtractPlugin({ filename: 'styles.[contenthash].min.css' }) ], optimization: { minimizer: [ '...', new CssMinimizerPlugin() ] } };

package.json

{ "scripts": { "build": "webpack --mode=production", "minify:css": "csso src/styles.css --output dist/styles.min.css" }, "devDependencies": { "css-minimizer-webpack-plugin": "^8.0.0", "mini-css-extract-plugin": "^2.9.0", "csso-cli": "^4.0.0" } }

Critical CSS, selectors, online or build

Critical CSS is a separate workflow

A minifier does not inline above-the-fold CSS or load the rest asynchronously. Extract the critical rules first, then minify that block. The full walkthrough is in Critical CSS: extract, minify, inline.

Extract above-the-fold rules (`critical`, Penthouse, or your design-system subset)
Minify that block (CSSO online or the same engine as your build) before you inline it
Load the remainder with media=print onload or a non-blocking pattern you have tested
On WordPress, the “optimize CSS delivery” option of a plugin covers this layer, not FastMinify
Selector depth and file size

Deep selectors cost parsing time and specificity fights more than they cost kilobytes. Minification will not flatten `.container .row .card .title` for you, so prefer fewer, stable classes and minify after.

Before

/* Slow to maintain, not just “slow to parse” */ .container .row .col-md-6 .card .card-body .card-title { color: #333; } .btn-primary, .btn.btn-primary, button.btn-primary { background: blue; }

After

.card-title { color: #333; } .btn-primary { background: blue; }
When the online minifier is enough

Paste-and-minify suits a child-theme override or a one-off landing page stylesheet. It also shows what CSSO does to a snippet before you change the build. It is the wrong tool as the only production pipeline for an app that ships on every commit. The trade-offs are covered in online minifiers vs build tools. If you write SCSS or Less, compile first with the CSS preprocessor hub, then minify the CSS.

Use Minify CSS for files you can paste, and concatenate on that page if you merge a few sheets
Leave Aggressive off if your cascade depends on source order
Keep comments only if you accept a weaker size win: with comment removal off, the page only collapses whitespace and skips CSSO’s rewrites
Lock the same step in Webpack, Vite or CI so production cannot skip minification

Measure CSS, don’t guess

What to look at

File size on disk is not bytes on the wire. Check the compressed transfer size in DevTools Network, unused bytes in Coverage, and field LCP. Do not rely on a single invented “CSS performance score”.

CSS performance analysis dashboard showing optimization metrics and file size reduction
Chrome Coverage: unused CSS bytes in the page you actually loaded
DevTools Network: encoded vs decoded size after gzip/Brotli
Lighthouse: render-blocking CSS and LCP breakdown, not a CSS-only grade
WebPageTest: filmstrip + request waterfall for the stylesheet
Fail the build on regressions you define

A Lighthouse score of “the whole page” is not a CSS budget. Prefer a max size on the extracted CSS artifact, then optionally a performance assertion on a stable URL.

Configuration GitHub Actions

name: CSS size check on: [push] jobs: css-budget: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: '22' - run: npm ci && npm run build - name: Fail if production CSS exceeds budget run: node scripts/check-css-size.js

What to do next

Minify CSS with CSSO or cssnano in the build you already trust. Remove unused rules with PurgeCSS or Tailwind’s content scan, not with PurifyCSS and not with FastMinify’s paste box. Use the online CSS minifier to inspect a file or a custom snippet. If the site is WordPress without a frontend build, start with plugin minification on staging rather than looking for a FastMinify plugin.

Run CSSO (or cssnano or Lightning CSS) in your production build, and use the browser tab for one-off checks
Treat unused CSS and critical CSS as extra pipelines with their own tests
Do not enable CSSO restructuring on a cascade you have not tested for regressions
Measure compressed transfer size and LCP, not bounce-rate folklore
WordPress: one minification plugin stack, CSS before JS, exclusions before combining
Share this article
Share this article: