Skip to content
ToolZone

CSS Minifier

Compress a stylesheet by removing whitespace, comments, and unnecessary characters, reducing file size without changing how styles are applied.

Runs in your browser. Nothing you enter or upload leaves your device.

Input
Minified output…

Removes comments and whitespace; strings are kept as written.

Keyboard shortcuts

Run the main action
⌘ / Ctrl + Enter
Copy the result
⌘ / Ctrl + Shift + Enter
Download the result
⌘ / Ctrl + S
Paste a file or image into file tools
⌘ / Ctrl + V
Search all tools
⌘ / Ctrl + K
Show these shortcuts
?

You can also drop files anywhere on the page.

About the CSS Minifier

The CSS Minifier compresses a stylesheet by removing comments and every space that CSS does not need around braces, colons, semicolons, commas, and child selectors. Paste code or open a .css file, compare the original, minified and gzipped sizes, and download the result.

How it works

The minifier removes all /* ... */ comments and sets quoted strings aside so their contents are never changed. It then collapses every run of whitespace to a single space and deletes spaces around { } ; , and >.

Spaces around colons are removed only inside declaration blocks, such as color : red becoming color:red. In selectors, a space before a colon is meaningful ("a :hover" is not the same as "a:hover"), so it is kept. Finally, a semicolon right before a closing brace is dropped and the strings are restored. Values are not rewritten, so #ffffff stays as written.

How to use

  1. 1

    Paste your CSS into the input box, or click Open file to load a .css file.

  2. 2

    Review the minified CSS and the size cards.

  3. 3

    Click Copy or Download to use the result.

Worked examples

Small stylesheet

Two rules with a comment.

Input
/* Buttons */ .btn, .btn-primary { color: #fff; padding: 8px 16px; } nav > a { margin: 0 auto; }
Result
.btn,.btn-primary{color:#fff;padding:8px 16px}nav>a{margin:0 auto} (Saved 37 bytes, 36%)

Descendant pseudo-class selector

A selector targeting any hovered element inside a link.

Input
a :hover { color: red; }
Result
a :hover{color:red} (Saved 5 bytes, 21%)

The space before :hover is kept, because removing it would change the selector to mean "a hovered link".

Limitations
Spaces around + and ~ selectors are kept rather than removed. It is a text-based pass, not a CSS parser, so malformed CSS can produce unexpected output. Values, colors, and duplicate rules are not optimized.
Assumptions
The CSS is syntactically valid.
Privacy
Your CSS is minified in your browser and is not uploaded or stored.

Frequently asked questions

Will minifying CSS break my styles?+

For valid stylesheets, no. Strings are protected, and spaces that change meaning, such as the one in "a :hover", are kept.

How much does minifying CSS actually save?+

It depends on how the source is written. Heavily commented and indented stylesheets often shrink by 20 to 40 percent before server compression.

Does it shorten colors or remove duplicate rules?+

No. It only removes comments, whitespace, and final semicolons. The gzipped size card shows how much your server's compression saves on top.

Can I un-minify CSS later?+

Comments are gone for good, but the formatting can be restored with a code beautifier.

Related tools