CSS Minifier
Minify CSS by removing whitespace, comments, and redundant code to reduce file size.
CSS Minifier tool
Example
Input: body { color: red; margin: 0 auto; } /* header */ h1 { font-size: 2em; } (formatted over 6 lines)
Result: body{color:red;margin:0 auto}h1{font-size:2em}
Comments, line breaks and spaces around braces, colons and semicolons are removed, as is the last semicolon in each rule. Spaces inside values like 0 auto are kept.
CSS Minification Examples
| Input | Minified output |
|---|---|
| a > b { color : red ; } | a>b{color:red} |
| .nav a:hover { color: blue; } | .nav a:hover{color:blue} |
| p { margin: 0 auto; } | p{margin:0 auto} |
| div { width: calc(100% - 20px); } | div{width:calc(100% - 20px)} |
| /* note */ h1 { font-size: 2em; } | h1{font-size:2em} |
| /*! MIT license */ b { x: 1 } | /*! MIT license */ b{x:1} |
| a { color: red;; } | a{color:red} |
Output of this minifier.
- Paste your CSS source code into the CSS panel.
- The minifier instantly processes the CSS and displays the compressed output in the Minified CSS panel.
- To reverse the process, paste minified CSS into the Minified CSS panel to get a beautified version.
- Verify the minified output preserves all your CSS rules and selectors.
- Click the copy button to copy the minified CSS for use in your production stylesheet.
What CSS Minification Removes
A CSS minifier makes a stylesheet smaller by removing what the browser does not need: comments, line breaks, indentation and extra spaces. p { margin: 0 auto; } becomes p{margin:0 auto}, which renders exactly the same.
The hard part is knowing where a space matters. This minifier keeps the space in a descendant selector such as .nav a, inside values like 0 auto, and around the minus sign in calc(100% - 20px), where removing it would break the rule. Strings, url() values and comments that start with /*! are left alone. Those comments usually hold license notices. It also drops the last semicolon in each block and collapses doubled semicolons. It does not rewrite your values. Colors, units and zeros stay as you wrote them, and rules are never merged or reordered. The output is predictable and easy to trace back to the source, though a build tool such as cssnano can squeeze out a little more.
The tool works both ways. Paste minified CSS into the Minified CSS panel and the CSS panel shows a beautified version, indented two spaces with one declaration per line. That helps when you need to read a vendor stylesheet. For the rest of a page, try the HTML Minifier and the JavaScript Minifier.
Frequently Asked Questions
Related Tools
JavaScript Minifier
Minify JavaScript by removing whitespace, line breaks, and comments for smaller files, without renaming your code.
Developer ToolsHTML Minifier
Minify HTML by removing comments and collapsing whitespace between tags and inside tags to reduce document size.
Developer ToolsHTML Entity Encode and Decode
Convert special characters to HTML entities and decode HTML entities back to readable text.
Developer ToolsJSON Formatter and Validator
Format, validate, beautify, and minify JSON data with a collapsible tree view and line-and-column error detection.
Developer Tools