Developer & Code
CSS Minifier
Remove comments and extra whitespace from CSS in your browser. A quick whitespace minifier, not a full optimizer; text inside strings can change.
This tool runs open-source code from CyberChef by GCHQ (Apache License 2.0). See open-source credits.
CSS Minifier removes comments and collapses whitespace with a few regular expressions. Every run of spaces, tabs, and line breaks becomes one space. Then the spaces after {, }, and ; are removed. It does not parse CSS, so spaces before { and after : remain, and text inside strings can change.
The result is the stylesheet on a single line. Colors, numbers, units, and the last semicolon in each rule stay as written.
- Compact a small inline style block for an HTML email or a code snippet.
- Strip comments and indentation from a CSS sample before sharing it.
- Get a one-line stylesheet quickly when no build tool is available.
Instructions
- Paste the stylesheet into Input.
- Leave Preserve comments off to delete every /* */ comment, including /*! license */ comments.
- Turn on Preserve comments to keep comments. The space after /* is still removed.
- Before you minify, search for content: or url() strings that contain double spaces or /*.
- Load a page with the minified CSS and compare it with the original rendering.
Example
Input: /* header */ h1, h2 { color: #ff0000; margin: 0 0 8px; }
Settings: Preserve comments: off (the default)
Result: h1, h2 {color: #ff0000;margin: 0 0 8px;}
The comment is gone, but one space remains at the start. The color #ff0000 and the value 0 0 8px are not shortened.
Limits
- Whitespace and comments inside strings change too. content: "a /* b */ c" becomes content: "a c".
- It does not shorten colors, drop zero units, merge rules, or remove the last semicolon. A build-time minifier saves more bytes.
- The output can start with a space when the input begins with a comment or a blank line.
- It does not validate CSS. Syntax errors pass through unchanged.