CSS Minifier
Minify CSS by removing whitespace and comments.
What is CSS Minifier?
A CSS minifier is a tool that removes whitespace, comments, and redundant syntax from a CSS stylesheet to produce a smaller file that browsers parse and apply faster. The minified output is byte-for-byte different but renders identically to the original, since none of the trimmed characters affect the cascade or specificity.
Frontend developers, theme authors, and platform engineers run a CSS minifier on every production build. A 60 KB hand-authored stylesheet routinely drops below 18 KB after minification, and shrinks again to under 4 KB once gzip or Brotli compression kicks in.
Why use the CSS Minifier
- Shrink stylesheets by 30% to 50%. Stripping whitespace, comments, and color shorthand alone removes a third of most hand-written CSS files.
- Faster First Contentful Paint. Render-blocking CSS lives in the critical path. Smaller files mean shorter blocking time and better Core Web Vitals.
- Lower CDN egress. Every byte saved compounds across thousands of pageviews. A 40 KB saving per visit adds up fast at scale.
- Easier inline embedding. Critical CSS inlined into
<style>blocks must stay under HTTP/2 header limits and one TCP packet for fastest delivery.
How to use the CSS Minifier
- Paste your stylesheet into the input panel on the left.
- Click the Minify button at the top of the panel.
- Read the minified result in the right panel. Syntax errors surface in red above the panels.
- Copy the output with the Copy button and paste it into your
dist/styles.css, theme file, or inline<style>block.
What gets removed
The CSS minifier applies safe transformations only. No selector is renamed, no declaration is reordered, and the cascade is preserved.
| Pass | Action | Typical savings |
|---|---|---|
| Whitespace removal | Strips newlines, indentation, spaces around {, }, :, ; | 25-35% |
| Comment stripping | Removes /* */ blocks including authoring notes | 5-15% |
| Trailing semicolons | Drops the last ; in each rule block | 1-2% |
| Color shortening | Rewrites #ffffff to #fff, rgb(0,0,0) to #000 | 1-3% |
| Zero unit collapse | Rewrites 0px, 0em, 0% to 0 | 0.5-2% |
| Quote normalization | Drops quotes around safe URL and font tokens | 0.5-1% |
The tool does not merge duplicate selectors, reorder media queries, or rewrite shorthand properties. Those passes can change the cascade and break specificity-dependent styles.
Size savings example
Input (242 bytes):
/* Primary button styling */
.button-primary {
background-color: #ffffff;
color: #000000;
padding: 0px 16px;
margin-top: 0em;
border: 1px solid #cccccc;
}Minified output (98 bytes):
.button-primary{background-color:#fff;color:#000;padding:0 16px;margin-top:0;border:1px solid #ccc}Typical savings across input sizes:
| Input | Raw size | Minified | Gzipped | Total reduction |
|---|---|---|---|---|
| Component styles | 2.4 KB | 1.1 KB | 540 B | 78% |
| Theme stylesheet | 35 KB | 14 KB | 3.8 KB | 89% |
| Framework reset + utilities | 120 KB | 48 KB | 11 KB | 91% |
| Tailwind production CSS | 350 KB | 110 KB | 28 KB | 92% |
Common use cases
- Production builds for marketing sites. Cuts critical CSS payload so the landing page paints in under one second on 4G.
- Inline
<style>for AMP and email. Both platforms enforce strict byte limits on inline styles. Minification keeps you under the cap. - WordPress and Shopify theme files. Most themes ship minified
.min.cssfiles alongside the source. The CSS minifier produces that file in one click. - Critical CSS extraction. After extracting above-the-fold rules with a tool like Critters, run the result through the minifier before inlining.
Frequently asked questions
Is minified CSS reversible?
Whitespace and comments cannot be restored once removed, since the information is gone. A CSS prettifier can re-indent the output for readability, but author comments and original formatting are lost forever. Keep your source files under version control.
Does minifying break my styles?
No, as long as the minifier sticks to safe transformations. The tool only removes characters the parser ignores. Specificity, cascade order, and inheritance behave identically. The single edge case is malformed CSS with missing semicolons, which the minifier will reject rather than silently fix.
What is the difference between minify and compress CSS?
Minification rewrites the stylesheet itself by removing characters, and the output is still valid CSS that any browser can parse directly. Compression (gzip, Brotli) wraps the byte stream in a binary encoding the server delivers and the browser decompresses. Both run together for maximum savings.
Should I minify CSS in development?
No. Minified CSS makes DevTools inspection harder, breaks source map line numbers in some setups, and hides authoring intent. Run the CSS minifier only as a production build step.
Will the minifier merge duplicate selectors?
Not by default. Merging duplicates can change cascade behavior when two rules with the same selector have different specificity contexts elsewhere in the file. The tool sticks to lossless transformations only.
Does minified CSS render faster?
Marginally at parse time, more meaningfully at transfer time. The browser’s CSS parser is fast either way, but smaller files arrive sooner over the network and unblock rendering earlier.
Can I minify CSS with custom properties or @container queries?
Yes. The minifier handles modern CSS including --variables, @container, @layer, nesting, and :has(). The output preserves the same syntax level as the input.
Will minification preserve license comments?
No, all comments are stripped by default. To keep a license header, prepend /*! (the bang comment) at the start of the file. Most minifiers preserve bang comments.
Related tools
- JavaScript Minifier - shrink JavaScript bundles by stripping whitespace and shortening identifiers.
- HTML Minifier - collapse whitespace and remove comments from HTML markup.
- SQL Minifier - flatten multi-line SQL into a single line for embedded queries.
- CSS Prettify - re-indent minified CSS for inspection and code review.
Related tools
ShotMark captures what you do here, in one click.
The traces, payloads, and tests you run by hand? ShotMark grabs the whole bug and hands it to your AI agent.