Skip to content
Everyday Utilities Free • No signup • Instant results

CSS Minifier

Minify CSS files by stripping comments and unnecessary whitespace.

About the CSS Minifier

The CSS Minifier compresses stylesheets by removing comments, collapsing whitespace, and stripping unnecessary characters from selectors, properties, and values. For a typical 50KB CSS file, minification saves 15-25% of the file size, which improves page load time and reduces bandwidth costs on high-traffic sites.

CSS is forgiving of extra whitespace. Spaces around {, }, :, ;, and , are ignored by the parser. Comments are stripped entirely. Trailing semicolons before closing braces can be removed. All of these can be safely eliminated without changing how the browser interprets the stylesheet.

This tool performs pattern-based minification: it removes comments, collapses runs of whitespace to a single space, strips whitespace around CSS punctuation, removes trailing semicolons, and trims the result. For more aggressive optimization (removing duplicate rules, merging selectors, shortening hex colors, converting units), use a dedicated tool like cssnano or clean-css.

How It Works

The minification runs in five passes:

  1. Comment removal: /\/\*[\s\S]*?\*\//g matches C-style comments (/* ... */) and removes them. CSS does not have line comments (//), so only block comments are stripped.
  2. Whitespace collapse: \s+ is replaced with a single space, turning multi-line indented CSS into a single line.
  3. Punctuation cleanup: \s*([{}:;,>~+])\s* matches whitespace before and after CSS structural characters and replaces it with just the character, removing spaces around {, }, :, ;, ,, and the combinator characters.
  4. Semicolon removal: ;} is replaced with }, removing the optional trailing semicolon before a closing brace.
  5. Trim: Leading and trailing whitespace is removed.

The order matters. Comment removal must happen first because comments may contain characters that look like CSS syntax. Whitespace collapse must happen before punctuation cleanup so the regexes match consistently.

Worked Examples

The default input is a multi-line CSS block with comments and indentation. Minifying produces .btn{display:inline-block;padding:10px 20px;background-color:#3b82f6;color:#fff;border:none;border-radius:4px;font-size:14px}.btn:hover{background-color:#2563eb} — a single line, no comments, no unnecessary whitespace. The file size drops from about 280 characters to about 145 characters, a 48% reduction.

For a real-world stylesheet like Bootstrap (about 230KB unminified), minification reduces the size to about 30KB — an 87% reduction. Combined with gzip compression, the transferred size is around 25KB. Without minification, the gzipped size would be about 30KB — minification still helps because gzip works better on text without redundant whitespace.

If your CSS uses media queries with complex selectors, the minification preserves the selectors intact — only the whitespace around them is removed. @media (max-width: 768px) { .container { padding: 0 15px; } } becomes @media (max-width:768px){.container{padding:0 15px}}, which is functionally identical.

When to Use This Tool

  • Compressing CSS for production deployment to improve page load time.
  • Reducing bandwidth costs on high-traffic websites.
  • Preparing CSS for inline embedding in HTML email templates.
  • Minifying CSS before bundling with a build tool that does not already minify.
  • Compressing CSS snippets for embedding in CMS rich-text editors.
  • Reducing the size of third-party CSS libraries before inclusion.
  • Pre-minifying CSS for use in browser extensions or embedded widgets.

Limitations & Disclaimer

This tool performs pattern-based minification and does not parse CSS into an AST. It may mangle edge cases like CSS containing /* inside a string value (rare but possible in content properties), nested @media queries with unusual formatting, or CSS variables with whitespace-sensitive values. It does not perform value optimization (shortening hex colors, converting 0px to 0, merging duplicate rules). For production-grade minification, use cssnano, clean-css, or esbuild which use a proper CSS parser. See our disclaimer for full terms.

Frequently Asked Questions

Will minification break my CSS?

No, as long as your CSS is valid. The tool removes only whitespace and comments, which the CSS parser ignores. However, if your CSS contains syntax errors (unbalanced braces, missing semicolons), minification may produce output that does not render correctly — always validate your CSS before minifying.

Should I minify CSS in development?

No — keep your source CSS readable during development with comments and indentation. Minify only when building for production, ideally as part of your build pipeline (Webpack, Vite, Gulp). Debugging minified CSS is painful because all the structure is gone.

Does this tool shorten hex colors or convert units?

No. The tool removes only whitespace and comments &mdash; it does not optimize values. Tools like cssnano and clean-css can shorten <code>#ffffff</code> to <code>#fff</code>, convert <code>0px</code> to <code>0</code>, merge duplicate selectors, and remove unused rules. For production, use a dedicated tool.

What about CSS-in-JS or CSS modules?

This tool minifies plain CSS text. If you are using CSS-in-JS (styled-components, emotion) or CSS modules, your build tool handles minification automatically as part of the bundling process. Use this tool only when you have raw CSS text that needs minification outside a build pipeline.

How much size can I expect to save?

Typically 15-25% on hand-written CSS, less on already-minified output. The savings depend on how much whitespace, how many comments, and how many trailing semicolons your source contains. Combined with gzip compression (which the web server applies automatically), the total reduction is usually 70-80%.

Is my CSS uploaded anywhere?

No. Minification happens entirely in your browser using JavaScript string operations. Your CSS &mdash; including any proprietary styles or trade-secret animations &mdash; never leaves your device.

Last updated: July 21, 2026  ·  Author: HT99 Tools Editorial Team  ·  Reviewed by: HT99 Tools Editorial Team