Free tool · Developer tools
CSS minifier
Paste CSS and get the smallest safe version: comments, extra whitespace and the last semicolon of each block removed, strings and url() left alone. You see the bytes saved, then copy or download it.
- Free
- No sign-up
- Runs in your browser
18.0% smaller472 bytes before, 387 bytes after
- 1 comment removed
- 1 /*! */ comment kept
- 4 blocks
- Strings and url() untouched
- Before
- 472 bytes
- After
- 387 bytes
- Saved
- 85 bytes
- Gzipped, before
- …
- Gzipped, after
- …
Only comments, whitespace and the last semicolon of each block are removed. Numbers, units, colors and names are not rewritten, so the styles mean the same. Compare in your browser before you ship.
How to use the CSS Minifier
- Paste your stylesheet into Your CSS, or choose a .css file. It is read on your device.
- Leave Keep /*! license */ comments on to preserve license banners, or turn it off to remove every comment.
- Read the percent saved, the bytes before and after and the gzipped sizes, plus any warning such as an unclosed block.
- Press Copy or Download .min.css.
How do I minify CSS?
Minifying CSS means rewriting a stylesheet so it has the same meaning in fewer bytes. The safe savings are comments, line breaks and indentation, spaces around braces, colons and commas, and the semicolon after the last declaration in a block. This tool does exactly that, in one pass over your text, and nothing else. The example in the box is 472 bytes and comes out as 387 bytes, 18.0% smaller.
It works by reading the stylesheet token by token. Strings are copied exactly, so a content: "{ not a rule; /* not a comment */ }" keeps its braces, semicolon and comment-like text. A url() is trimmed outside and left alone inside, so url( "img/hero image.png" ) becomes url("img/hero image.png") and a data: address with semicolons survives. Comments that start with /*! are kept by default, since they usually hold a license. The rest are removed.
| Case | Input | Output |
|---|---|---|
| Spaces and last semicolon | a { color : red ; margin : 0 ; } | a{color:red;margin:0} |
| Comment | a { /* note */ color: red } | a{color:red} |
| calc keeps spaces | a { width: calc( 100% - 2rem ) } | a{width:calc(100% - 2rem)} |
| Selector combinators | ul > li + li , a ~ b { x: y } | ul>li+li,a~b{x:y} |
| Descendant before a pseudo-class | .card :hover { x: y } | .card :hover{x:y} |
| Media query | @media screen and ( min-width : 600px ) { a { x: y } } | @media screen and (min-width:600px){a{x:y}} |
| Important flag | a { color: red ! important } | a{color:red!important} |
Does minifying CSS change how it works?
It should not, and that is why this minifier is cautious. Some spaces carry meaning. In calc(100% - 2rem) the spaces around the minus sign are required: without them the expression is invalid, because the sign can be read as part of the next number. So spaces around + and - are kept inside calc(), min(), max() and clamp(). In a selector, .card :hover (any hovered descendant) is different from .card:hover (the card itself), so a space before a pseudo-class is kept, while the spaces around > and + and ~ are removed.
The tool does not rewrite numbers, units, colors or names. Some minifiers turn 0px into 0, shorten #ffffff to #fff or merge rules; each of those is a place a bug can hide, for example a bare 0 is not accepted everywhere a unit is needed. The savings here are a little smaller, and the result means exactly what the original meant. Broken input is handled too: an unclosed block, string or comment is reported as a warning instead of failing silently. Still, test your minified file before you ship it, in the browsers you support.
A short worked check. Take margin: 0 auto -4px from the example. The two spaces collapse to one, but the space before -4px stays, because removing it would glue auto and the negative number into a single unreadable token. The same care applies to center / cover in a background shorthand, whose slash spacing is left as written, and to the space between two quoted strings in grid-template-areas, where the space separates the names. The rule of thumb is simple: a space is removed only where a neighbor is punctuation that never needs one, such as a brace, a semicolon, a comma or a colon in a declaration.
How much smaller does minified CSS get, and should I do it for production?
The saving depends on how much whitespace and commenting the source has. A hand-formatted file with indentation and comments loses a good share of its bytes; a file that is already compact saves little. The tool shows the real figure for your CSS, both as plain bytes and as gzipped bytes, since most servers compress text before sending it. Gzip already squeezes repeated whitespace well, so the gap after compression is smaller than the gap before it. Both numbers are worth looking at.
For production, smaller files download and parse sooner, so minifying is a standard step, and it is best done by your build tool on every release. Keep your readable source files for editing and ship the minified copy. This page is for the cases where you have no build step: a CSS snippet for an email or a widget, a stylesheet pasted into a CMS, or a quick check of how heavy a file is. If a color is part of what you are tidying, the hex to RGB converter converts between color formats, and for pixel sizes the px to rem converter helps with relative units.
Use it with
- HEX to RGB Converter: HEX, RGB, HSL, CMYK conversions.
- Px to Rem Converter: convert px, rem, em.
- Box Shadow Generator: visual CSS box-shadow builder.
Questions
How do I minify CSS?
Paste it into the box. The tool removes comments, extra whitespace and the last semicolon in each block, leaves strings and url() untouched, and shows the bytes saved. Copy the result or download it as a .min.css file.
Does minifying CSS change how it works?
Not with this tool. It only removes comments and whitespace that carry no meaning, and keeps the ones that do, such as the spaces around + and - in calc() and the space in .card :hover.
How much smaller does minified CSS get?
It depends on the source. The example here goes from 472 to 387 bytes, 18.0% smaller. The page shows your own figure, plus the gzipped sizes.
Does it keep license comments?
Yes, by default. A comment that starts with /*! is kept. Turn the option off to remove every comment.
Should I minify CSS for production?
Yes, as part of your build, keeping the readable source for editing. This page is handy when you have no build step or want to check a size.
Is my CSS uploaded?
No. The minifying runs in your browser and nothing you paste or open leaves your device.
How this page was made: the tool's results are computed in your browser by the code on this page, using the sources listed above; the explanations were drafted with AI help and checked against the tool's own output.