Skip to main content
CalcChef

CSS Minifier

Paste CSS to remove comments and unneeded whitespace while keeping descendant spaces, calc() operators and /*! */ license comments, with the characters saved. How it works

Use the CSS Minifier

or drop a .css file here

436 characters before, 289 after: 33.7% saved.

Input up to 2,000,000 characters; above 200,000 it runs in a background worker. Your code is minified in this browser tab and is not sent to a server.

About the CSS Minifier

The CSS minifier removes comments and the whitespace CSS does not need, and keeps the spaces that change meaning: the example stylesheet it opens with goes from 436 to 289 characters, 33.7% saved. Descendant spaces such as .nav * and a :hover, the and in @media (a) and (b), the spaces around + and - in calc(), strings, url() contents and /*! */ license comments are kept.

Before and after

InputOutput
.nav * { color: red; }.nav *{color:red}
a :hover { color: red }a :hover{color:red}
div { width: calc(100% - 2rem); }div{width:calc(100% - 2rem)}
@media (min-width: 600px) and (max-width: 900px) { a { color: red } }@media (min-width:600px) and (max-width:900px){a{color:red}}
@supports not (display: grid) { a { float: left } }@supports not (display:grid){a{float:left}}
a::after { content: "a b"; }a::after{content:"a b"}
a { color: #ffffff; margin: 0px; }a{color:#ffffff;margin:0px}
a { color: red !important; }a{color:red!important}
/* note */ a { color: red; }a{color:red}
a { margin: 1px/**/2px; }a{margin:1px/**/2px}

The last row keeps an empty comment, because without it 1px and 2px would run together into one token.

Frequently asked questions

Does minifying CSS change how the page looks?
It should not: only comments and whitespace that CSS ignores are removed. Whitespace that changes meaning stays, such as the space in a :hover, which matches any hovered element inside a link, while a:hover matches only the hovered link.
Does it shorten colors like #ffffff to #fff?
No. Colors, numbers and shorthand properties are left as written, so a { color: #ffffff; margin: 0px; } becomes a{color:#ffffff;margin:0px}. Only comments and whitespace are removed, plus the last semicolon before a }.
Why is my /*! comment still there?
Comments that start with /*! are license comments and are kept by default. Untick "Keep /*! ... */ license comments" to remove them: the example stylesheet then goes from 436 to 234 characters, 46.3% saved.
How large a stylesheet can I minify?
Up to 2,000,000 characters, about 2 MB of plain CSS. Above 200,000 the work runs in a background worker so the page keeps responding, and a new paste stops a run that is still going. A longer file gets a message with its length: minify it in parts.
What does the warning about a string that is not closed mean?
A quoted string ends at the end of its line in CSS. The minifier then keeps that line break and says: "A browser ends it at the line break and drops the declaration, so the minifier keeps that line break." Close the quote to fix the source.

Related Tools

View all tools