My Tool Studio
Developer Tools·2 min read

How to Minify CSS Safely for Production

The whitespace and comments that help you read a stylesheet add weight to every page load. The CSS Minifier strips them in one click, shows the size before and after plus a gzip estimate, and lets you download a .min.css file. It can also minify several files at once. Everything runs in your browser.

1.24 KB{"a": 1,"b": 2}MINIFIED · 430 B{"a":1,"b":2,"c":3,"d":4}−64%

What minifying CSS removes

Same styles, fewer bytes.

The minifier removes comments, line breaks and spaces the browser does not need, drops the last semicolon in each rule, and turns 0px into 0 where that is safe. With Shorten hex colors ticked, the default, #ffffff becomes #fff inside values. How much you save depends on the indentation, comments and colors in your file, and the size line shows the exact figure.

It reads the CSS character by character instead of using blunt find-and-replace. That matters for the next part.

Why safe minifying matters

Where cruder tools break things.

Some regex-based minifiers remove the spaces around + and - inside calc(), which makes the rule invalid. Here, spaces inside calc(), min(), max() and clamp() are kept, a descendant selector like .card :hover keeps its meaning, and text inside quotes is never touched. A media query only loses spaces it does not need.

How to minify CSS

Three steps.

Keep the readable source for future edits, since comments are removed.

  • Paste your rules into the Input pane, or click Upload .css to load a file, which is minified straight away.
  • Leave Keep /*! license */ comments and Shorten hex colors ticked or untick them. Click Minify, or turn on Live mode, and read the size line: original, new, percent saved and the gzip estimate.
  • Click Copy, or Download to save a .min.css file named after your upload.

Several files at once

Batch mode.

Under Minify several CSS files, add the files and use the arrows to set their order. You can download each one, a ZIP of separate .min.css files, or one combined bundle.min.css. Order matters in the combined file, because later rules override earlier ones.

What it does not do

Deliberately conservative.

It does not merge duplicate rules, remove unused selectors or rewrite shorthand properties. For deeper optimization, use cssnano or Lightning CSS in a build step. Removing unused CSS often saves more than minifying does.

Comments that start with /*! are kept by default, on their own line, because many open-source licenses ask you to keep the notice. All other comments are removed. Untick the option for your own code.

One-off jobs and WordPress

Browser tool or build step.

For a site you update often, a build step is better, because every deploy gets fresh minified CSS. On a live WordPress site, most caching and optimization plugins minify theme and plugin stylesheets automatically. This page suits one-off work: a theme's custom CSS box, a stylesheet for an email, or checking what a minifier does to your code.

Back to readable CSS

The reverse direction.

When you need to edit a minified file, click Beautify instead on this page, or use the CSS Beautifier for more layout options. Each rule and declaration goes back on its own line. Comments removed during minifying cannot be restored. For markup and scripts, the HTML Minifier and JavaScript Minifier do the same job for their own languages.

Try it now

Open CSS Minifier

The tool is one click away. No sign up, no upload, no payment.

Open CSS Minifier