Skip to the content

Contact usFree tools · No signup · Files stay on your device

Developer Tools

CSS Minifier: the complete guide to minifying CSS

CSS Minifier: the complete guide to minifying CSS

CSS minification removes everything a browser does not need: line breaks, indentation, comments, the last semicolon in each block, and the extra characters in values. Our free CSS Minifier does it in your browser, shows how many bytes you save before and after gzip, and has one setting, Restructure, that goes beyond whitespace and rewrites the rules themselves. This guide is for developers, bloggers who paste custom CSS into a theme, and anyone trying to get a PageSpeed warning to go away.

It also covers the places where you should look twice at the result. Minifiers are safe for ordinary CSS, but a few modern features need care. For the other two file types, see the guides for the HTML Minifier and the JS Minifier.

What CSS Minifier does

The tool passes your stylesheet through CSSO, a well-known CSS optimiser. It will:

  • Remove whitespace, line breaks and comments.
  • Remove the final semicolon before each closing brace.
  • Shorten values: 0px becomes 0, #ffffff becomes #fff, white becomes #fff, blue becomes #00f, font-weight: normal becomes 400, and url( 'x.png' ) becomes url(x.png).
  • With Restructure on, merge and clean up rules (explained below).

It does not combine several files, follow @import lines, add vendor prefixes or remove selectors that nothing uses. Cutting unused CSS is a different job that needs to see your HTML.

How to use CSS Minifier, step by step

  1. Open CSS Minifier.
  2. Paste your stylesheet into the box labelled "Paste CSS". You can also press Open file and pick a .css file, or press Sample to see an example.
  3. Tick or untick Restructure (merge rules) and Keep /*! license */ comments. Both are on by default.
  4. Read the result in the panel titled "Minified". It updates about 0.4 seconds after you stop typing and immediately when you change an option.
  5. Check the stats under the panels: Original, Minified, Saved, Gzip original, Gzip minified and Time.
  6. Press Copy, or Download to get styles.min.css (the site adds its "Tech Solution Point - " prefix to every download).

Every option explained

Restructure (merge rules)

With Restructure on, CSSO does more than strip characters. It merges rules with the same selector, groups selectors that share the same declarations, and removes declarations that a later one overrides. It also collapses repeated shorthand values.

Here is the effect on a few lines:

.button { color: white; background: var(--brand); }
.button { border: none; }
.a { color: red; }
.b { color: red; }

With Restructure on, the result is .button{color:#fff;background:var(--brand);border:0}.a,.b{color:red}. With Restructure off, the two .button rules stay separate (.button{color:#fff;background:var(--brand)}.button{border:0}) and .a and .b are not grouped.

On the sample stylesheet, Restructure on saves 29.4% (463 bytes down to 327), and Restructure off saves 24.4% (down to 350).

Why would you turn it off? Because merging can move declarations around, and a stylesheet that depends on a very particular cascade order can behave differently. If the minified page looks wrong, untick Restructure first. You then get a plain minify that keeps your rules in their original order.

Keep /*! license */ comments

When ticked, comments that start with an exclamation mark, such as /*! Theme v1.2 | MIT License */, stay at the top of the output. Everything else disappears. Open-source licences often require the notice to stay, which is why this exists.

Note the exact rule: only /*! comments are kept. A comment that merely contains the word @license but starts with a plain /* is removed. If you want a notice to survive, write it with the exclamation mark. Untick the option to remove every comment, including those.

A worked example

Press Sample and the tool loads a small theme. The input has a licence comment, a :root block with custom properties, margin: 0px, color: #333333, a four-value padding, two .button rules and a media query. With both options on, the output is:

/*! Theme v1.2 | MIT License */
:root{--brand:#1e6bff;--radius:12px}body{margin:0;padding:0;font-family:system-ui,-apple-system,"Segoe UI",sans-serif;color:#333}.card{padding:16px;border-radius:var(--radius);background-color:#fff}.button{color:#fff;background:var(--brand);border:0}@media (max-width:600px){.card{padding:12px}}

Notice that the custom property --brand:#1e6bff is unchanged, while #333333 became #333. Quoted font names such as "Segoe UI" are kept, because the space inside quotes matters.

What it accepts and its limits

  • Input: CSS text, pasted or opened from a .css file. A fragment is fine; you do not need a whole file.
  • Modern syntax: media queries, container queries, @layer, :is() and custom properties came through intact in our tests.
  • Live mode: up to 300,000 characters the tool minifies as you type. Above that, you press the Minify button that appears, with the hint "Large input (…) — click Minify to run."
  • Gzip figures: shown as "n/a" if your browser lacks the compression feature the page relies on.

Privacy

CSS Minifier runs in your browser. Your stylesheet is not uploaded to our server, so it is fine to paste client themes or unreleased designs.

Things to double-check

CSS nesting

This used to be the one that could bite. The CSSO engine behind the tool does not understand native CSS nesting: on its own it drops a nested rule from the output with no error. For example, .a { color: blue; &:hover { color: red; } } would come out as .a{color:#00f}, and a nested .b { … } inside .a would disappear too. The tool now checks for this. When it finds a rule inside a rule (including @media inside a rule), it skips CSSO and only removes comments and whitespace, keeping every nested rule exactly as written, and shows a warning note above the result. The trade-off is a smaller saving for that stylesheet: values are not shortened (#ffffff stays) and rules are not merged, and the Restructure option has no effect. Regular CSS without nesting is minified fully, as before.

Silent clean-up of mistakes

The engine is forgiving. A missing closing brace at the end is added for you, and a stray } is simply discarded. That means a typo can disappear rather than produce an error. The red box that says "Error at line … column …" appears only when the engine truly cannot continue, so treat a successful result as "minified", not "valid".

Values you did not expect to change

font-weight: normal becoming 400 and white becoming #fff are equivalent, but they look different from what you typed. Colours written as rgb(255 0 0 / 50%) come out as rgb(255 0 0/50%), which is still valid. Values inside custom properties are left almost untouched: spaces at the outer edges go, but --y:#FFFFFF stays as typed.

Tips to work faster

  • Keep your readable CSS in your project and treat the minified file as output.
  • Check the gzip numbers. Servers normally compress CSS, so the real saving is smaller than the raw percentage.
  • Put a short /*! Name vX | Licence */ comment at the top of your source file so it survives.
  • If you only have a <style> block inside a page, the HTML Minifier can minify it for you when Minify inline CSS & JS is ticked, though it does not merge rules there.
  • After minifying, load the page and look at the parts that use unusual selectors or cascade tricks.

Common problems and how to fix them

The page looks different after minifying

Untick Restructure and copy the new output. If the problem goes away, one of your rules depends on order. You can simply keep Restructure off for that stylesheet.

My nested styles are gone

The tool keeps nested rules now (see the nesting section above). If something is still missing, compare the output with the input and look for a stray } (see the next section).

My licence comment disappeared

Check it starts with /*!, and that Keep /*! license */ comments is ticked.

Nothing happens when I paste a large file

Above 300,000 characters the tool waits. Press the Minify button under the input box.

The saving is under 10%

That is normal for CSS that is already compact. Files written by hand with lots of comments and indentation shrink the most.

  • HTML Minifier: shrink the page that uses your CSS, optionally including its <style> blocks.
  • JS Minifier: do the same for your scripts, with name shortening and dead-code removal.
  • Developer Tools: more utilities for web work.

Quick checklist

  • Leave Restructure on, and turn it off if the page changes.
  • Write licence notices as /*! … */.
  • Expect a smaller saving if your CSS uses native nesting: the tool keeps nested rules but only strips whitespace and comments.
  • Compare the output with the input when the CSS had errors.
  • Judge the saving by the gzip numbers.

Frequently asked questions

What does the Restructure option change?
It lets the minifier rewrite the rules themselves: merge rules that share a selector or the same declarations, drop a property that a later one overrides, and shorten values like 16px 16px 16px 16px to 16px. Turn it off for a plain whitespace-and-values minify that leaves your rules in their original order.
Which comments are kept?
With Keep /*! license */ comments ticked, only comments that start with /*! survive. A plain /* … */ comment is always removed, and so is a comment that only contains @license, so write licence notices as /*! … */.
Why did my custom property value stay as I wrote it?
The minifier treats values of custom properties (the --name: value lines) as free-form text. It trims the outer spaces but does not shorten colours or collapse spaces inside them.
Does it fix mistakes in my CSS?
No, and it does not always report them either. The engine is forgiving: a missing closing brace is closed for you, and a stray closing brace is dropped without a message. Always look at the output and test the page.
Will it work with CSS nesting?
Yes, without losing anything. The CSSO engine does not understand a nested rule written inside another rule, such as &:hover { … } inside .a { … }, and on its own it would drop it. So when the tool finds nesting it only removes comments and whitespace and keeps every rule exactly as written, and it shows a note. Values are not shortened and rules are not merged for that stylesheet.
Found this useful? Share it

Tools in this guide

Main tool

CSS Minifier

Compress your stylesheets for faster pages.

Open tool

HTML Minifier

Make HTML pages smaller without breaking them.

Open tool

JS Minifier

Shrink JavaScript for production with Terser — the same minifier used by webpack, Vite and Next.js.

Open tool

Back to all guides & blog