Minify or beautify CSS — without losing a single rule
Paste a stylesheet and press Minify CSS (or Ctrl+Enter) to get the smallest file that still renders the same, ready to copy or download as .min.css. Press Beautify CSS to do the opposite: expand minified CSS from a website or a theme into readable, indented rules with one declaration per line. The stats bar shows the size before and after, the gzipped size, how many rules, declarations and !important flags the file has, how many selectors are repeated, and a palette of every colour used — click a swatch to copy it.
All processing happens in your browser with libraries bundled into this page. Your stylesheet is never uploaded, and the tool keeps working offline once loaded.
Why “safe fallback” matters
Many online CSS minifiers are built on CSSO, an excellent structural optimiser. But the current CSSO release predates two features that every modern browser now supports: CSS nesting (writing &:hover { … } inside a rule) and range media queries such as @media (width >= 600px). In our tests, CSSO silently drops nested rules and whole range media queries — the output is smaller because part of your design is missing.
This tool protects you in two ways. First, before optimising, it scans for syntax CSSO cannot handle — nesting, range media queries, @scope and @starting-style — and switches to safe mode automatically. Second, after CSSO runs, it compares the class names, custom properties and at-rules in your input with the output. If anything that should be there has disappeared, the CSSO result is thrown away and the safe minifier is used instead. Either way you see a note explaining what happened.
What the two modes do
- CSSO optimisation (the default for classic CSS) removes comments and whitespace, shortens colours (
#ffffff→#fff,#ff0000→red), drops units from zero values (0px→0), collapses shorthands (margin: 0 0 0 0→margin:0), removes empty rules and, with Merge rules ticked, combines rules that share selectors or declarations. Untick Merge rules if your design depends on the exact order of rules in the cascade. - Safe mode only removes comments and whitespace where the grammar makes it optional — around braces, semicolons, commas and the child combinator — and the last semicolon in each block. It keeps the space in
nav a(the descendant combinator), before:hoverina :hover, and around+and-insidecalc(), where removing it would change or break the value. Strings andurl()values are copied exactly.
Licence comments that start with /*! are kept by default, because many open-source licences require the notice to travel with the code.
How much will I save?
Hand-written stylesheets typically shrink by 15–40% when minified; framework output that is already compact shrinks less. Compression saves even more: servers send CSS compressed with gzip or Brotli, and Google's web.dev guidance is to minify and then compress. That is why the stats show the gzipped size, measured in your browser with the Compression Streams API — it is the number that affects your page's loading speed and Core Web Vitals.
Beautify minified CSS
Beautify expands CSS with your choice of 2 spaces, 4 spaces or tabs, puts each declaration on its own line, adds a blank line between rules, and can put each selector of a group on its own line. It understands media queries, @supports, @layer, @container, keyframes and nested rules. It is the quickest way to read the CSS of a theme or a site you are debugging, or to clean up a stylesheet before committing it.
Built-in checks
Before anything is minified, the tool checks that every { has a matching }, that comments are closed and that strings end. A missing brace is the most common reason for a broken stylesheet, because the browser then swallows every rule after it. If there is a problem you see the line, a snippet with a caret and a Go to error button, and nothing is minified until it is fixed.
The statistics help with cleanup too. A high number of !important flags usually means specificity problems. Repeated selectors are candidates for merging. A palette with twenty slightly different greys is a sign that the design needs colour variables (--brand, --text-muted).
Common questions from WordPress and Blogger users
If you paste CSS into the WordPress Customizer's “Additional CSS” box, a page builder or a Blogger theme, minifying is optional — those boxes are usually small, and readable CSS is easier to change later. Minify when you add large blocks, or when you copy a stylesheet into a single HTML file such as an email template or a landing page. Keep a readable copy somewhere: beautifying minified CSS restores the layout but not the comments you wrote. When a caching plugin already minifies CSS, do not minify it twice; check the plugin's output instead, and use the stats here to compare sizes.
Tips for smaller, faster CSS
- Remove unused rules first — a tool such as PurgeCSS or your framework's content scan saves far more than minification. Minifying never removes a rule your HTML might use.
- Serve CSS with Brotli or gzip compression and long cache lifetimes.
- Inline only the critical, above-the-fold CSS and load the rest normally.
- Use custom properties for colours and spacing so values are not repeated.
- Keep the readable source in version control and minify as a build step; this page is ideal for quick one-off jobs, WordPress “Additional CSS” boxes and email templates.
SCSS and Less
Plain CSS output from Sass or Less can be minified here. Uncompiled SCSS or Less with variables, mixins and @include is not CSS yet — compile it first. Beautify will still lay out SCSS nesting readably.
Privacy, offline use and limits
Everything runs locally. Drafts, options and the last 12 inputs are stored only in this browser's localStorage and can be cleared from the History dialog. The tool has been tested with stylesheets over 1 MB. Minification never fixes invalid CSS; if a rule is broken, fix it first.
Sources and references
- W3C, CSS Syntax Module Level 3 — tokens, comments and where whitespace matters.
- W3C, CSS Nesting Module and Media Queries Level 4 — range syntax.
- MDN Web Docs, Using CSS nesting.
- web.dev (Google), Minify and compress network payloads.
- CSSO (MIT) and js-beautify (MIT), bundled locally with this page.
Frequently asked questions
Is my CSS uploaded?
No. CSSO and js-beautify are bundled with this page and run in your browser. Nothing is sent to a server, and the page works offline after loading.
Will minifying break my CSS nesting or @media (width >= 600px)?
No. Those features are detected and minified in safe mode, which only removes comments and optional whitespace. After every CSSO run the tool also checks that no class, custom property or at-rule went missing.
What is the difference between the two modes?
CSSO also shortens colours and values and can merge rules, so it saves more. Safe mode removes only comments and optional whitespace, so the output is guaranteed to contain every rule in the original order.
Should I untick Merge rules?
Untick it if your design relies on the exact order of rules in the cascade. Merging is safe for most stylesheets but can move a rule.
How much smaller will my CSS get?
Usually 15–40% for hand-written CSS before compression. The gzipped size shown is what browsers actually download when your server uses gzip.
Can I minify SCSS or Less?
Compile it to CSS first. Plain CSS output from Sass or Less minifies fine; beautify also lays out SCSS nesting.