What Minify CSS does
Minify CSS removes comments, collapses whitespace, removes spaces around braces, colons, semicolons and commas, and drops the last semicolon in each block.
Minify CSS examples
The built-in sample
Input
/* buttons */
a {
color: red;
margin: 0 auto;
}
.b {
padding: 4px;
}Output
a{color:red;margin:0 auto}.b{padding:4px}This is the input that the Load sample button fills in.
Media queries, calc() and strings
Input
.b > .c , .d { margin : 0 auto ; content : "a b" }
@media (min-width : 600px) { .e { width : calc(100% - 10px) } }Output
.b>.c,.d{margin:0 auto;content:"a b"}@media (min-width:600px){.e{width:calc(100% - 10px)}}Spaces around braces, colons, semicolons, commas and > are removed and the last semicolon in each block is dropped. The spaces around the minus sign in calc() are kept, which CSS requires, but the two spaces inside the quoted string were collapsed to one.
Each output was produced by running this tool on the input above it.
How it works
Comments are removed, runs of whitespace become one space, spaces around { } : ; , > are removed, and the semicolon before each closing brace is dropped. Selectors, values and rule order are otherwise unchanged. The tool works on the text and does not parse CSS.
Details and limits
- There is no fixed size limit: everything runs on your device, so very large inputs depend on its memory.
- It works in current browsers on phones, tablets and computers, and it is free with no account needed.
- A space before a colon is removed even in a selector.
.menu :hover(any hovered descendant) becomes.menu:hover(the menu itself), which is a different selector. Write.menu *:hoverto keep the meaning. - Values are not rewritten:
0pxstays0px,#ffffffis not shortened andmargin: 0 0 0 0is not collapsed. - Comments marked as important with
/*! */, often used for licence headers, are removed like any other comment.
Worked example: Stripping comments and whitespace from a 340-byte CSS button block
Paste this 16-line commented CSS component (342 bytes) into the input box:
/* Primary CTA button styles */
.btn-cta {
display: inline-flex;
align-items: center;
padding: 0.75rem 1.5rem;
font-weight: 700;
color: #ffffff;
background-color: #2563eb;
border-radius: 0.5rem;
}
.btn-cta:hover {
background-color: #1d4ed8;
}
Clicking Minify CSS removes the block comment, collapses every line break and indentation space, removes spaces around :, {, }, and ;, and drops the final semicolon before each closing }:
.btn-cta{display:inline-flex;align-items:center;padding:0.75rem 1.5rem;font-weight:700;color:#ffffff;background-color:#2563eb;border-radius:0.5rem}.btn-cta:hover{background-color:#1d4ed8}
The stylesheet shrinks from 342 bytes to 191 bytes (a 44.2% size reduction).
Limits and what this tool cannot do
- Safe lexical minification (does not merge duplicate rules or rewrite shorthand): Unlike risky AST optimizers that reorder cascade rules and accidentally break specificity overrides, this minifier keeps your exact selector and property order untouched.
- Preserves spaces inside
calc()and quoted strings: Required spaces around+and-insidecalc(100vh - 64px)and spaces insidecontent: "Read more "are preserved so layout and pseudo-elements do not break. - Plain CSS only (not uncompiled SASS/LESS with
//single-line comments): Standard CSS supports only/* ... */block comments; compile.scssor.lessfiles to.cssbefore minifying.
Questions
Is the minified CSS always equivalent?
Almost always. Two cases change meaning: a space before a colon in a selector, and several spaces inside a quoted string. Both are described above.
Why is the last semicolon inside each { ... } block removed?
In CSS syntax, semicolons are *separators* between declarations rather than terminators. The semicolon right before the closing brace } is optional, so removing it saves 1 byte per rule block.
Should I still minify CSS if my server uses Gzip or Brotli compression?
Yes. Stripping developer comments (/* ... */) and normalizing whitespace removes text that even Brotli must otherwise spend bits encoding, typically saving an extra 10% to 20% over compression alone and speeding up browser CSS parsing.
How can I make minified CSS readable again?
Paste the minified CSS into the CSS Beautifier or Code Formatter tool to restore 2-space indentation and one declaration per line.