CSS Minifier
Remove comments, whitespace and the last semicolon of every block from CSS. The result behaves exactly like the original.
CSS Minifier: the tool
Input
Minified CSS
The result appears here.How to use CSS Minifier
- Paste your CSS, or press Example.
- The minified stylesheet appears on the right, and the status bar shows the size before and after.
- Keep licence comments (those starting with /*!) if your licence requires the notice to stay in distributed files.
- Copy the result or download it as styles.min.css.
Example
The button stylesheet with its comment removed.
/* Buttons */
.btn{display:inline-block;padding:.5rem 1rem;color:#fff;background:#3b35a8;border:0}
.btn:hover,.btn:focus{background:#2a2566}
@media (max-width:600px){.btn{display:block;width:calc(100% - 2rem)}}.btn{display:inline-block;padding:.5rem 1rem;color:#fff;background:#3b35a8;border:0}.btn:hover,.btn:focus{background:#2a2566}@media (max-width:600px){.btn{display:block;width:calc(100% - 2rem)}}About this tool
This minifier removes what browsers ignore: comments, line breaks, indentation, the space after colons and commas, and the last semicolon in each block. It is deliberately conservative. It does not merge or reorder rules, shorten colours, drop units or rewrite values, because each of those can change behaviour in some browsers or in some context. Typical savings are 15 to 35 percent, similar to the gain from reformatting alone, and the result is safe to deploy.
Whitespace that has meaning is kept. The space in calc(100% - 2px) is required by the specification, and a space before a pseudo-class, as in a :hover, changes which elements the selector matches. Strings, unquoted url() values and custom properties are written exactly as they were. A test checks that minifying the formatted version of a stylesheet gives the same result as minifying the original.
The CSS is parsed first, so an unclosed brace, string or comment is reported with its position instead of producing broken output. For further savings, also serve your CSS with gzip or Brotli compression, which removes most of the remaining redundancy.
Frequently asked questions
Is it safe to minify CSS?
With this tool, yes. It only removes whitespace and comments, and keeps the whitespace that has a meaning. More aggressive optimisers that merge rules or shorten values can occasionally change how a page renders, which is why this one does not do that.
Why is the result not as small as with other minifiers?
Tools that restructure CSS can save more by merging selectors and shortening values, at the cost of some risk. If you need that, run a build-step optimiser such as Lightning CSS and review the diff. Compression on the server then reduces both versions to a similar transfer size.
What happens to comments?
They are removed, except licence comments starting with /*! when Keep licence comments is on. Many open-source licences require the notice to stay in files you distribute.
Does it break calc() or custom properties?
No. Spaces around the operators in calc() are required by the specification and are kept. Custom property values are kept as they are, because their syntax is open-ended.
Can I undo minification?
Yes, with the CSS formatter. The layout comes back, but comments that were removed do not.
More developer tools
- cssCSS FormatterBeautify CSS with one declaration per line and consistent indentation. Media queries, nesting, custom properties and data URLs are handled.
- <//>HTML MinifierReduce the size of HTML by removing comments and collapsing whitespace. Pre-formatted text, scripts and conditional comments are left alone.
- jsJavaScript MinifierMinify JavaScript with Terser: remove comments and whitespace, compress expressions and rename local variables. Syntax errors show line and column.
- {}JSON MinifierRemove every optional space and line break from JSON to make it as small as possible, without changing a single value.