How to use the css minifier
- Paste your stylesheet into the CSS input field.
- Toggle the options: remove comments (optionally keeping
/*! license */notes), shorten hex colors, remove units from zero lengths, and drop the last semicolon. - The minified output and the exact byte savings appear below.
- Copy the compressed CSS into your project.
How CSS minification works
A css minifier reduces file size without changing how the styles render. This tool first splits your stylesheet into tokens: strings, comments, url() contents, punctuation and words. Each kind of token is treated by its own rules, which is what keeps the output correct.
- Comment removal: every
/* ... */block is dropped when the option is on. Comments that start with/*!are kept when the license checkbox is on. - Whitespace collapse: runs of whitespace become one space, and spaces next to
{,},;and,are removed. In declarations the space after the colon goes too. In selectors the space around>,+and~is removed, but a descendant space is kept. - Semicolon cleanup: the last semicolon before a closing brace is dropped, because CSS treats it as optional.
- Color shortening: in declaration values only, an exact six-digit hex color whose pairs repeat (such as
#aabbcc) becomes three digits (#abc). - Zero units: a length such as
0pxbecomes0where that is always valid.
For example, a { color : red ; } becomes a{color:red}. The input is 19 bytes and the output is 12, so 7 bytes (36.8%) are saved on that single rule.
What the minifier preserves
Not all whitespace can be removed safely. A correct css compressor must leave certain constructs untouched, and this one does.
- Strings: quoted text keeps every character.
content: "a : b ; c"comes out exactly as written, including the spaces, the colon and the semicolon. - The descendant combinator:
a :hovermeans any hovered descendant ofa, whilea:hovermeans a hovereda. The space is kept, soul li :first-childis unchanged. - url() contents: unquoted URLs, including data URIs with semicolons, are copied as they are. Only the whitespace just inside the parentheses is trimmed.
- 8-digit hex colors:
#aabbccddincludes an alpha channel and is never shortened. IDs such as#aabbcc { }in selectors are never treated as colors. - progid filters: legacy
filter: progid:...values, includingstartColorstr='#ff000000', are left alone. - calc() expressions: spaces around
+and-are required, so they stay. Zero units insidecalc(),min(),max(),clamp()andvar()are not touched either. - Time units and flex-basis:
0sand0mskeep their unit, andflexandflex-basisvalues keep0px. - Custom properties: a value such as
--gap: 0pxkeeps its units. Whitespace runs inside the value are collapsed to one space.
This tool does not merge rules, reorder declarations or rename anything. It only removes characters that the parser ignores.
Typical size savings
The table below was measured with this css minifier using all default options. Your results depend on how much whitespace and how many comments the original author left in.
| Input | Original | Minified | Saved |
|---|---|---|---|
a { color : red ; } | 19 B | 12 B | 7 B (36.8%) |
Rule plus comment plus b{margin:0px} | 41 B | 23 B | 18 B (43.9%) |
| Commented card component (three rules, hex colors) | 266 B | 183 B | 83 B (31.2%) |
a{content:"x y"} | 17 B | 17 B | 0 B (0%) |
Already compact CSS saves little, as the last row shows. Across 17 real stylesheets, including this site's own CSS and Tailwind's source files, the combined saving was about 21% of the bytes. Hand-written, well-formatted CSS with many comments benefits the most.
When to minify CSS
Minification is a build step, not a development workflow. Keep your source files formatted for readability and run the css minifier only when preparing assets for production.
If you also need to compress markup, the companion HTML minifier applies the same ideas to HTML documents. To estimate what the saved bytes mean for slow connections, a download time calculator converts file size and bandwidth into seconds.
Pair minification with gzip or Brotli on your server. Minification removes characters people add for readability, while transfer compression removes repetition. The two savings overlap, so measure the compressed size before and after instead of adding the percentages together.
Common mistakes to avoid
Naive search-and-replace scripts often break stylesheets. Watch out for these pitfalls when you minify CSS manually or evaluate a tool.
- Stripping the space before a pseudo-class: turning
a :hoverintoa:hoverchanges which elements match. - Removing spaces inside calc():
calc(100%-10px)is invalid. The CSS Values specification requires spaces around the minus sign. - Rewriting strings:
content: "hello world"must keep its internal space, and a colon or semicolon inside quotes is just text. - Shortening the wrong hex values:
#aabbcdcannot become#abcdbecause the digit pairs differ, and an 8-digit#aabbccddcarries alpha, so it is left alone. - Stripping license comments: some open-source licenses require attribution to remain in distributed files. Keep the
/*!option on if your project depends on those notices.
Worked examples
| Example | Input | Result |
|---|---|---|
| Basic rules with comment | CSS input: a { color : red ; } / /* c */ b{margin:0px}; Remove comments: yes; Keep /*! license */ comments: yes; Shorten hex colors (#aabbcc to #abc): yes; Remove units from zero lengths (0px to 0): yes; Remove last semicolon before }: yes | Original size: 41 bytes; Minified size: 23 bytes; Bytes saved: 18 bytes (43.9%) |
| Descendant combinator kept | CSS input: a :hover { color : red } / ul li :first-child { color : blue }; Remove comments: yes; Keep /*! license */ comments: yes; Shorten hex colors (#aabbcc to #abc): yes; Remove units from zero lengths (0px to 0): yes; Remove last semicolon before }: yes | Original size: 60 bytes; Minified size: 49 bytes; Bytes saved: 11 bytes (18.3%) |
| Strings stay untouched | CSS input: a{content:"a : b ; c"}; Remove comments: yes; Keep /*! license */ comments: yes; Shorten hex colors (#aabbcc to #abc): yes; Remove units from zero lengths (0px to 0): yes; Remove last semicolon before }: yes | Original size: 22 bytes; Minified size: 22 bytes; Bytes saved: 0 bytes (0.0%) |
| Shorten hex colors | CSS input: a{color:#aabbcc;border-color:#aabbcd;background:#aabbccdd}; Remove comments: yes; Keep /*! license */ comments: yes; Shorten hex colors (#aabbcc to #abc): yes; Remove units from zero lengths (0px to 0): yes; Remove last semicolon before }: yes | Original size: 58 bytes; Minified size: 55 bytes; Bytes saved: 3 bytes (5.2%) |
| Keep calc() spacing | CSS input: a{width:calc( 100% - 10px )}; Remove comments: yes; Keep /*! license */ comments: yes; Shorten hex colors (#aabbcc to #abc): yes; Remove units from zero lengths (0px to 0): yes; Remove last semicolon before }: yes | Original size: 28 bytes; Minified size: 26 bytes; Bytes saved: 2 bytes (7.1%) |
FAQ
Does this css minifier upload my code?
No. All processing happens locally in your browser. Nothing is sent to any server.
Will minifying CSS change how my page looks?
It should not. The minifier only removes whitespace, comments and redundant characters, and it keeps strings, url() values, descendant combinators, 8-digit hex colors and calc() spacing as written. Invalid or unusual CSS, such as legacy hacks, is passed through with minimal changes, so test the result before you ship it.
Why does calc() keep its spaces?
The CSS specification requires spaces around + and - operators inside calc(). Removing them creates an invalid expression, so the minifier preserves them.
What does the shorten colors option do?
It converts six-digit hex colors where each pair repeats into three-digit shorthand in declaration values, so #aabbcc becomes #abc and saves three bytes. Colors with alpha (#aabbccdd), selectors such as #aabbcc, strings and filter values are never changed.
Which zero values lose their unit?
Lengths such as 0px, 0em or 0rem become 0 when they stand alone in a declaration. Time values like 0s, angles, percentages, flex and flex-basis values, custom properties and anything inside calc(), min(), max(), clamp() or var() keep their units.
Should I remove the last semicolon in a rule?
Yes. CSS syntax allows omitting the semicolon before a closing brace, which saves one byte per block. Turn the option off if another tool in your pipeline expects it.
Can I use this as a general css compressor for production?
Yes for plain CSS. Paste your final stylesheet, copy the output into your build or a style tag, and compare the saved bytes shown in the table. It does not merge rules or optimise shorthand properties, so a full build-time optimiser can shave a little more.