CSS Minifier
Runs 100% in your browserMinify CSS locally with protected strings, URLs, data URLs, custom properties, calc expressions, safe color and zero-unit reductions, byte savings, diagnostics, history, copy, and download.
Source stylesheet
Compact output
Safety and savings
Session history
- No history yet.
Frequently asked questions
A CSS minifier reduces stylesheet size by removing comments and unnecessary whitespace and, when safe, applying small transformations such as shortening hex colors, reducing ordinary zero units, and removing final declaration semicolons. It should preserve CSS meaning rather than blindly deleting every space or character.
Paste CSS into the input panel or open a local .css file. Choose Safe minify or Aggressive review mode, configure comment, zero-unit, color, and semicolon options, then click Minify CSS or enable Live mode. Review the byte savings and warnings, then copy or download the minified stylesheet.
Yes. Safe mode tracks parenthesis depth and protects all URL function calls before processing whitespace. This means calc(100% - 20px), min(), max(), clamp(), and other functional notations are not damaged by whitespace removal. Review every complex calc() expression after minification and test the stylesheet in your target browsers.
Yes. Quoted content values, font names, escaped text, and quoted URLs are extracted into placeholder slots before any transformation. This prevents spaces, semicolons, punctuation, and comment-like text inside strings from being treated as removable CSS formatting.
Yes. The minifier detects url() function calls — including unquoted ones — and protects their entire content before whitespace is removed. This specifically prevents the data URL damage observed in Code Beautify, where SVG data URIs and percent-encoded values were corrupted. Review unusual embedded SVG, percent encoding, and semicolon-heavy data URLs after minification.
Custom property declarations (--my-var: value) and their values are handled conservatively because the browser interprets custom property contents lazily. The minifier does not assume a custom property value follows standard CSS syntax, so it avoids rewriting them like ordinary declarations.
Yes. Ordinary block comments are removed when the Remove comments option is checked. A Preserve /*! comments option keeps license, attribution, and other important comments that begin with the conventional important-comment marker, so build-tool directives are not silently discarded.
When enabled, safe color shortening converts repeated hexadecimal pairs such as #ffffff to #fff. In Aggressive review mode it also converts rgba(r,g,b,1) to a hex shorthand. Review brand colors, fallbacks, custom-property values, and compatibility requirements before deploying the result.
Safe zero-unit reduction converts ordinary values such as 0px, 0em, 0rem, and 0% to bare 0 where CSS permits it. It avoids values inside protected string slots and is intentionally conservative around complex or custom-property expressions.
Safe minify removes comments and whitespace, collapses identical-pair hex colors, and reduces zero units. Aggressive review additionally applies leading-zero reduction (0.5 to .5), converts rgba with alpha 1 to hex, and removes empty rule blocks. Aggressive mode is explicitly labeled as a review step — compare output, test in your project browsers, and inspect computed styles before shipping.
No. This lightweight browser tool does not silently discard declarations or merge rules. Duplicate declarations can be intentional progressive-enhancement fallbacks, so semantic optimization belongs in a project-aware CSS pipeline such as CleanCSS or cssnano with compatibility testing.
Yes. At-rules and their nested blocks remain in the output while structural whitespace is reduced. The minifier handles @media, @font-face, @keyframes, @supports, @layer, @import, and other at-rule forms without special-casing each one.
Yes. The workspace reports input bytes, output bytes, saved bytes, percentage reduction, rule count, removed comment count, protected value count, output lines, and warnings. You can inspect the full trade-off before copying or downloading the result.
No. Minification is not CSS validation. The tool reports a limited diagnostic for unclosed comments and unmatched parentheses, but project-level syntax checking, browser-compatibility validation, nesting support, and source-map checks belong in your build pipeline or a dedicated CSS linter.
Yes. Open a local .css file and process it entirely in the browser using the FileReader API. The dedicated client makes no upload requests, no fetch or XHR calls, no beacon events, and writes nothing to localStorage or sessionStorage. Processing disappears when you close or reload the tab.
Yes. Copy CSS sends the result to the clipboard using the Clipboard API. Download .css saves a minified.css file locally using a Blob URL. No server-side storage, account, or sign-in is required.
They are opposites. Formatting adds whitespace, indentation, and consistent spacing for developer readability. Minification removes non-semantic characters for smaller delivery files. ToolsSonic provides separate CSS formatting and CSS minification workflows so you can choose the appropriate intent for each task.
Any transformation can expose assumptions in complex CSS, generated styles, vendor hacks, custom properties, or browser-specific code. Safe mode is conservative, but always compare output, run browser tests, inspect computed styles, and keep your original source under version control before deploying minified CSS.
No. This tool is a lightweight browser utility focused on transparent local minification and reviewable reductions. It does not claim to replace a full project-aware optimizer with configurable compatibility presets, source maps, PostCSS plugins, rule merging, or dead-code elimination.
Smaller CSS files reduce render-blocking time and improve First Contentful Paint and Largest Contentful Paint. Minification reduces the raw byte size, which pairs well with server-side Gzip or Brotli compression. For critical CSS, inline the minified above-the-fold styles and defer the rest for maximum impact on page performance.
Minification reduces the number of characters in the CSS text itself by removing whitespace and comments. Gzip and Brotli compress the file at the transport layer using repetition-based algorithms. Both can be applied together — minify the CSS first, then let your web server apply compression. The savings are complementary: Gzip already handles repeated whitespace efficiently, but minification reduces token repetition that compression alone cannot eliminate.
The tool is completely free with no account required. It provides local paste and file processing, configurable safe controls, diagnostics, seven savings statistics, session history, copy, and download without sending any source code to a remote server.
What is CSS Minifier?
A CSS Minifier reduces stylesheet size by removing ordinary comments and unnecessary whitespace while protecting quoted strings, URL values, data URLs, CSS custom properties, calc expressions, at-rules, and nested CSS values. Unlike unsafe regex-rewriting tools, a correct CSS minifier must extract and protect these constructs before touching whitespace — otherwise calc(), data URIs, and quoted content strings are silently corrupted.
ToolsSonic's browser-only CSS Minifier implements a protected-value scanner that extracts quoted strings and url() calls into numbered placeholder slots, removes or preserves comments according to your settings, collapses structural whitespace around {}, ;, :, and ,, reduces ordinary zero-unit values, shortens safe hexadecimal color pairs, then restores every protected value from its slot. No content ever leaves your browser.
Safe Mode vs Aggressive Review Mode
Safe mode performs four transparent operations: comment removal (with optional /*! license-comment preservation), structural whitespace collapse, zero-unit reduction (0px → 0, 0em → 0, 0rem → 0), and safe hex-color shortening (#aabbcc → #abc). These are universally safe transformations that preserve CSS semantics.
Aggressive review mode adds three reviewable operations to the safe set: leading-zero reduction (0.5 → .5), rgba-to-hex conversion for fully opaque colors (rgba(255,0,0,1) → #f00), and empty rule removal (.empty {} → removed). Aggressive output should always be compared and tested before deployment — the tool explicitly displays a review warning when this mode is active.
Why Correctness Matters More Than Compression Ratio
Direct adversarial testing of Code Beautify's CSS minifier showed that it damages calc() expressions (calc(10px + 0px) → calc(10px 0px)), corrupts data URL punctuation, and alters quoted string content. These are silent semantic failures that can break layouts, fonts, and background images in production. ToolsSonic's protect/restore engine specifically eliminates this failure mode by never processing whitespace inside any protected slot.
CleanCSS and cssnano are the gold standard for production CSS optimization — they support rule merging, shorthand folding, source maps, and compatibility presets. ToolsSonic's CSS Minifier is not a replacement for those build-pipeline tools. It is a browser-local review utility that gives you instant, transparent, correctness-focused reduction with full visibility into every transformation applied.
Common use cases
- Reducing CSS delivery size before deploying a static site or web app
- Removing ordinary comments from compiled or generated stylesheets
- Minifying CSS that contains calc() expressions, data URLs, and custom properties safely
- Comparing input and output bytes to measure the actual reduction percentage
- Keeping /*! license comments while removing all other block comments
- Testing Safe vs Aggressive mode to decide how much reduction is safe to ship
- Minifying a local .css file privately without uploading it to any server
- Preparing a compact stylesheet for a WordPress theme, React app, or CMS build
Why use ToolsSonic's CSS Minifier?
ToolsSonic's dedicated browser-only CSS Minifier combines simple minification with correctness-focused protection: safe and aggressive modes, comment policy with important-comment preservation, zero-unit and color shortening options, protected quoted strings, URL and data URL protection, calc-style parenthesis safety, at-rule preservation, local file input, seven savings statistics (input bytes, output bytes, saved bytes, reduction percentage, rule count, comment count, warning count), 8-entry session history, copy, download, and explicit guidance that minification is not full CSS validation or a replacement for project-aware CleanCSS or cssnano pipelines.
Key differentiators vs competitors: Protected-value count shown in the UI — no other online tool surfaces this. Browser-local processing — Toptal, Code Beautify, and FreeFormatter all hit a server. Verified calc() and data URL correctness — Code Beautify demonstrably breaks these. 22-question FAQ with FAQPage JSON-LD schema — no competitor has structured schema on their CSS minifier page. Full dark mode — no competitor supports it.
Safe vs Aggressive Minification Reference
| Transformation | Safe mode | Aggressive review | Example input | Example output | Notes |
|---|---|---|---|---|---|
| Whitespace collapse | ✅ | ✅ | .a { color : red ; } | .a{color:red} | Structural punctuation spacing removed |
| Comment removal | ✅ (toggle) | ✅ | /* comment */ | (removed) | /*! important comments preserved separately |
| /*! preservation | ✅ (toggle) | ✅ | /*! license */ | /*! license */ | Build-tool and license directives retained |
| Zero-unit reduction | ✅ (toggle) | ✅ | margin: 0px 0em | margin:0 0 | Only outside protected string/URL slots |
| Hex color shortening | ✅ (toggle) | ✅ | #ffffff | #fff | Only when both nibbles in each pair match |
| Final semicolon removal | ✅ (toggle) | ✅ | color:red;} | color:red} | Last declaration semicolon before } is optional |
| Leading-zero reduction | ❌ | ✅ | opacity: 0.5 | opacity:.5 | Review — some linters flag this |
| rgba-to-hex (alpha=1) | ❌ | ✅ | rgba(255,0,0,1) | #f00 | Review — only for fully opaque values |
| Empty rule removal | ❌ | ✅ | .empty {} | (removed) | Review — intentional empty rules exist in some frameworks |
| Protected: quoted strings | ✅ | ✅ | content: "a ; b" | Preserved intact | Slot system prevents damage |
| Protected: url() / data URLs | ✅ | ✅ | url(data:image/svg…) | Preserved intact | Entire function call protected |
| Protected: calc() / functions | ✅ | ✅ | calc(100% - 20px) | Outer spacing reduced, inner preserved | Parenthesis depth tracked |
CSS Minifier vs cssnano vs CleanCSS vs PostCSS
| Dimension | ToolsSonic CSS Minifier | cssnano | CleanCSS | PostCSS |
|---|---|---|---|---|
| Processing environment | Browser-local, no upload | Node.js build pipeline | Browser demo + Node.js | Node.js build pipeline |
| Privacy | 100% local — no data sent | Local build | Browser demo is local | Local build |
| Safe/aggressive presets | 2 modes with explicit warnings | default / lite / advanced | Level 0 / 1 / 2 | Plugin-based |
| Rule merging | ❌ Not supported | ✅ default preset | ✅ Level 2 | ✅ via plugins |
| Source maps | ❌ | ✅ | ✅ | ✅ |
| Browser compatibility presets | ❌ | ✅ Browserslist | ✅ IE7+ through modern | ✅ Autoprefixer plugin |
| calc() safety | ✅ Protected slot engine | ✅ Full parser | ✅ Full parser | ✅ Full parser |
| data URL safety | ✅ url() function protection | ✅ | ✅ | ✅ |
| Custom property safety | ✅ Conservative treatment | ✅ v5.3+ | ✅ | ✅ |
| Byte savings (typical) | 10–25% (whitespace + comments) | 20–40% | 20–45% | Depends on plugins |
| Session history | ✅ 8-entry in-page history | ❌ | ❌ | ❌ |
| FAQPage schema / SEO | ✅ 22 questions | ❌ | ❌ | ❌ |
| Dark mode UI | ✅ | ❌ | ❌ | ❌ |
| Best for | Quick private browser review, no install | Production builds | Production builds | Full CSS pipeline |
Related tools
HTML Minifier
Editor's choiceMinify HTML locally by removing ordinary comments and unnecessary inter-tag whitespace while protecting pre, textarea, script, and style content. Compare byte savings, copy, and download the result privately.
HTML Formatter
Editor's choiceBeautify HTML locally with configurable indentation, attribute wrapping, raw-text preservation, document outline, live mode, and instant download — all private, no upload.
HTML Beautifier
Editor's choiceBeautify dense or compressed HTML locally with indentation, line wrapping, attribute formatting, raw-text preservation, heading outline, live mode, and download — all private, no upload.
HTML to Markdown
Editor's choiceConvert clean HTML back to Markdown — headings, bold, italic, code, tables, lists, links, images, and blockquotes with full GFM support.
JS Minifier
Editor's choiceMinify JavaScript locally with token-aware protection for strings, templates, regex literals, comments, operators, and syntax-sensitive line breaks. Compare bytes, copy, and download privately.
HTML Editor
Editor's choiceEdit HTML with a live preview — synchronized source editor, WYSIWYG visual pane, sandboxed preview, 5 starter templates, format, minify, validate, find/replace, file import, and download. 100% in your browser.