🛠️ Developer & Web

CSS Minifier

Smaller stylesheets with structural optimisation.

  • CSSO 5Optimiser used
  • 2Options
  • #fffColours shortened
  • 0Uploads

How to use the CSS Minifier

  1. 1

    Paste CSS

    Paste a stylesheet or open a .css file. Media queries, custom properties and modern selectors are fine.

  2. 2

    Set restructuring

    Leave “Merge & restructure rules” on for the smallest file, or turn it off for a safer, order-preserving minify.

  3. 3

    Check the savings

    The status line shows bytes before and after and the percentage removed.

  4. 4

    Ship the .min.css

    Download styles.min.css and link it from your pages; keep the original for editing.

Features

Colour shortening

#ff0000 becomes red, #ffffff becomes #fff and rgb(255, 255, 255) becomes #fff — whichever is shortest.

Number clean-up

Leading zeros and units on zero are dropped: 0.50em → .5em, 0px → 0.

Rule merging

With restructuring, selectors that share declarations are combined into one rule.

Shorthand collapsing

With restructuring, repeated values in margin and padding shorthands are shortened.

Licence comments

/*! … */ banners are kept unless you untick the option.

Local only

CSSO runs in the page; your stylesheet is not uploaded.

Who uses it — and for what

Theme and template makers

Ship a compact stylesheet with a WordPress theme or HTML template.

Small business sites

Shrink a hand-edited style.css before uploading it to hosting.

Email developers

Reduce the size of embedded <style> blocks to stay under email clipping limits.

Students

See which parts of a stylesheet are redundant by watching what CSSO merges.

More than removing spaces

This minifier uses CSSO, an optimiser that understands CSS. Beyond stripping whitespace and comments it shortens values (#ffffff → #fff, 0px → 0, font-weight: bold → 700), removes duplicate declarations and empty rules, and with restructuring on, merges rules that share selectors or declarations. Results are typically 20–40% smaller than the original before gzip.

When to turn restructuring off

Restructuring is safe for normal stylesheets, but if your CSS relies on rule order between separate files or uses unusual hacks, switch it off to get a plain whitespace-and-value minification. Comments starting with /*! (licence headers) are kept by default, as many open-source licences require. Keep your original, readable CSS in source control and only ship the minified file — the CSS Formatter can expand minified CSS again if needed.

Everything runs in your browser — your code and data are never uploaded, so it is safe to paste private config files and API responses.

What CSS minification can safely change

CSS is forgiving about whitespace, so removing spaces and line breaks is always safe outside strings and a few places where a space acts as a separator (between shorthand values, around + and - inside calc(), and in descendant selectors like .nav a). CSSO knows these cases because it parses the stylesheet into a syntax tree instead of running find-and-replace.

Value rewriting relies on equivalences defined by the CSS specifications: bold and 700 are the same font weight, #ff0000 and red are the same colour, and a length of zero needs no unit. Hex colours are compared case-insensitively, so #AABBCC can be written as #abc.

Restructuring is the clever and slightly riskier part. Because the cascade depends on source order and specificity, CSSO only moves or merges declarations when it can prove the winning value for every element stays the same. That is why, in the second example, .a{margin:0} could join .b — nothing between them disagreed about margin.

When not to minify, and what minifying will not do

  • Files you still edit. Keep the readable stylesheet in your project and generate the minified one from it. Editing a .min.css by hand is how mistakes creep in; the CSS Formatter can expand one if that is all you have.
  • Stylesheets that depend on order across files. Restructuring only sees the one file you paste. If a later file overrides an earlier one, merge order still matters; turn restructuring off when in doubt.
  • Unused selectors. CSSO cannot see your HTML, so it never knows that .old-banner is no longer used. Removing dead CSS needs a coverage tool that loads your pages, such as the Coverage panel in Chrome DevTools.
  • Source maps. This page outputs only the minified CSS. Build tools such as PostCSS or Lightning CSS can produce a .map file that points dev tools back to your original line numbers.

For the scripts and markup that sit alongside your stylesheet, use the JavaScript Minifier and HTML Minifier. Curious why one rule beats another after merging? The CSS Specificity Calculator explains the scores.

Worked examples

Restructuring on vs off

Input:

/*! brand.css v2 | MIT */
/* header styles */
.header {
  margin: 10px 20px 10px 20px;
  color: #ff0000;
  background: rgb(255, 255, 255);
  font-weight: bold;
}
.footer {
  color: #ff0000;
  font-weight: bold;
}
.card { padding: 0.50em 0px; }
.card { padding: 1em; }

With “Merge & restructure rules” on:

/*! brand.css v2 | MIT */
.header{margin:10px 20px;background:#fff}.footer,.header{color:red;font-weight:700}.card{padding:1em}

With it off:

/*! brand.css v2 | MIT */
.header{margin:10px 20px 10px 20px;color:red;background:#fff;font-weight:700}.footer{color:red;font-weight:700}.card{padding:.5em 0}.card{padding:1em}

Restructuring shared color and font-weight between the two selectors, collapsed the margin shorthand and dropped the first .card rule because the second one overrides it completely. Without restructuring, every rule stays where it was and only values are shortened.

Merging only when order allows

.a { color: red; }
.b { margin: 0; }
.a { margin: 0; }

Restructured:

.a{color:red}.a,.b{margin:0}

Not restructured:

.a{color:red}.b{margin:0}.a{margin:0}

What is left alone

.x { transition: opacity 0.30s ease-in-out; width: calc(100% - 0px); }
.y { color: #AABBCC; }

becomes

.x{transition:opacity .3s ease-in-out;width:calc(100% - 0px)}.y{color:#abc}

The 0px inside calc() keeps its unit and the spaces around the minus sign survive — inside calc, both are required for the expression to stay valid.

Pro tips

  • If a layout changes after minifying, minify again with restructuring off — if the problem disappears, a cross-rule merge was the cause and you can report or work around it.
  • Run the minifier on the final, combined stylesheet rather than on each partial separately; merging finds more duplicates when it can see everything.
  • Untick “Keep licence comments” only for your own code; third-party CSS licences often require the banner to stay.

Glossary

Restructuring
CSSO’s step that merges, moves and removes rules when the visual result is provably unchanged.
Shorthand property
A property like margin or padding that sets several sides or values at once.
Cascade
The CSS rules that decide which declaration wins when several apply to the same element.
Licence comment
A comment starting with /*! that minifiers keep because it holds copyright or licence text.

Frequently asked questions

Will minifying change how my site looks?

No — CSSO only applies transformations that keep the same result.

How much smaller will my CSS be?

Usually 20–40% before gzip, more for hand-written CSS with comments.

Does it remove unused CSS?

No, it can’t see your HTML; it only optimises the CSS itself.

Does it support CSS custom properties?

Yes. Custom properties like --brand-color are kept; CSSO is careful with their values because they can hold almost anything.

Can I minify SCSS or Less?

Not directly. Compile SCSS or Less to plain CSS first, then minify the result here.

Why did one of my rules disappear?

With restructuring on, a rule whose declarations are all overridden later by an identical selector is removed because it never has an effect. Turn restructuring off to keep every rule.

Found it useful? Share the CSS Minifier:

Last updated 2026-11-28 · Built by Vinayak Agarwal · Part of Developer & Web (77 tools)