CSS Minify
Minify CSS code online instantly. Remove comments, whitespace, and redundant characters to reduce file size and improve page load speed.
About
Unminified CSS carries dead weight: block comments, trailing semicolons, redundant whitespace, and line breaks that browsers discard during parsing. A typical stylesheet loses 15 - 40% of its transfer size to these characters. On HTTP/1.1 connections without Brotli or gzip, every excess byte directly increases Time to First Paint. This tool strips all non-functional characters from valid CSS while preserving semantic correctness. It handles nested @media blocks, url() references with quoted or unquoted paths, and content strings containing whitespace-sensitive values. The output is a single-line, deployment-ready stylesheet. Note: this is a syntactic minifier. It does not merge duplicate selectors or perform shorthand collapsing. For critical-path CSS, always validate the minified output against your rendering target.
Formulas
The compression ratio quantifies how much dead weight was removed from the original stylesheet:
Where R = compression ratio in %, Soriginal = byte size of input CSS (UTF-8 encoded via TextEncoder), and Sminified = byte size of output CSS after all transformations. Byte size is used instead of character count because multi-byte characters (emoji in content: properties) would skew length-based calculations. A ratio of 0% means the input was already fully minified. Ratios above 50% typically indicate heavily commented source files.
Reference Data
| Optimization | Characters Affected | Typical Savings | Risk Level |
|---|---|---|---|
| Strip block comments /* … */ | All comment content | 5 - 20% | None |
| Remove line breaks & tabs | \n, \r, \t | 3 - 10% | None |
| Collapse consecutive spaces | Multiple \x20 → single | 2 - 8% | None |
| Trim around { } | Spaces before/after braces | 1 - 3% | None |
| Trim around : | Space after property colon | 1 - 2% | None |
| Trim around ; | Spaces before semicolons | 0.5 - 1% | None |
| Remove trailing ; before } | Last semicolon in block | 0.5 - 2% | None (CSS spec allows) |
| Trim around , in selectors | Spaces around commas | 0.5 - 1% | None |
| Trim around > ~ + | Combinator spacing | 0.2 - 0.5% | None |
| Preserve url() content | Quoted/unquoted paths | 0% (no change) | Must preserve |
| Preserve string literals | content: "..." | 0% (no change) | Must preserve |
| Strip @charset duplicates | Redundant charset rules | 0.1 - 0.3% | Low |
| Normalize zero values | 0px → 0 | 0.1 - 0.5% | Low |
| Shorten hex colors | #ffffff → #fff | 0.1 - 0.3% | None |
| Combined total (typical) | All non-functional chars | 15 - 40% | None if parser-safe |