🎨 CSS Minifier & Beautifier

Compress CSS for production or format it for readability — regex-powered, instant, 100% in-browser.

Input CSS
1
0 chars · 0 lines
Output CSS
1
0 chars · 0 lines
Options
Load Sample CSS Snippet

CSS Minification & Beautification Explained

What Minification Does

CSS minification strips all whitespace, newlines, and comments that are only needed for human readability. It also removes the last semicolon before a closing brace, collapses zero values (e.g. 0px → 0 ), shortens hex colors ( #ffffff → #fff ), and merges duplicate spaces in selector lists — all without changing the visual output of the stylesheet.

What Beautification Does

CSS beautification is the reverse: it reformats minified or poorly formatted CSS into a consistently indented, human-readable structure. Each rule gets its own line, properties are indented under their selector, at-rules like @media are properly nested, and blank lines are added between rule blocks for visual separation.

Performance Impact

Minified CSS reduces stylesheet file sizes by 30–80% depending on how many comments and how much whitespace the original contains. Smaller files mean faster HTTP transfers, reduced parse time in the browser's CSSOM construction phase, and improved Core Web Vitals scores — particularly FCP and LCP, since render-blocking stylesheets are fetched and parsed before any content is painted.

Minification and gzip are not the same thing — you need both
A question that comes up surprisingly often: "my server already uses gzip compression, so do I still need to minify?" Yes. They solve different problems.

Gzip finds repeated byte sequences and replaces them with shorter codes. Minification reduces the raw number of bytes before gzip ever runs. The two are complementary — a minified file compresses further with gzip than an unminified one, because removing whitespace and comments creates more opportunities for gzip to find repeatable patterns. In practice, minification alone typically saves 20–60%. Gzip on top of that saves another 60–80% of what remains. Skip minification and you’re leaving meaningful transfer size on the table even with compression enabled.

OptimisationWhat gets removed or shortenedRough savingRisk of breakage
Strip whitespaceSpaces, tabs, newlines between tokens20–60%None — whitespace is never semantically significant in CSS
Remove commentsAll /* ... */ blocks5–30%None, unless the comment is a /*! preserved license comment — see below
Shorten colors#ffffff#fff, rgb(0,0,0)#0001–5%None for hex shortening. Color name normalisation can occasionally conflict with legacy parsers.
Remove zero units0px0, 0em0SmallNone. Per CSS spec, units on zero values are always optional.
Drop last semicolonThe ; before a closing }1 byte per ruleNone in modern browsers. Old IE 6 had bugs here; nothing current.
Collapse shorthandmargin-top:0;margin-right:0;...margin:0Significant on verbose CSSLow, but check calc() values — some aggressive shorthanders misparse them

License comments: /*! (note the exclamation mark) tells most minifiers to preserve the comment. If you’re shipping CSS that includes open-source code with attribution requirements, check that the original comment uses this format. If it doesn’t, you’re responsible for not stripping it.

When a browser-based tool is the right choice — and when it isn’t
This tool is built for one-off tasks. It should not be part of your production pipeline.
Good use: debugging a third-party stylesheet

You get a minified .css file from a component library or a CMS and need to understand what it’s doing. Paste it here, hit beautify, and you can read the selectors and property cascade. This is the most common practical use for a browser-based beautifier — the actual build tooling question doesn’t apply here at all.

Good use: quick check on a one-off snippet

You’ve written a specific animation or keyframe block for a CodePen or a client deliverable and want to know how small it is. Paste it in, get the number, done. No npm install, no config file.

Not this tool: production CSS from a bundler

Vite, webpack, Parcel, and esbuild all minify CSS automatically on production builds. If you’re already running one of these, you don’t need a separate minification step — and manually running output through a second minifier won’t help because the bundler has already done it. The only thing you’d add is the risk of the second pass misinterpreting something.

Not this tool: anything that needs source maps

Source maps are essential for debugging minified CSS in production. They map compressed output back to your original source file and line number. This tool doesn’t generate source maps. For production with DevTools debugging, use cssnano (PostCSS plugin) or the clean-css npm package — both support source map output alongside the minified file.

The regex vs AST distinction matters for complex CSS

This tool uses regex-based processing, which handles 95% of real-world CSS correctly and is fast. Full AST-based processors like cssnano can safely merge identical rules, deduplicate selectors, and collapse longhand/shorthand properties because they actually parse the CSS structure. If you have complex at-rules, custom properties, or intricate cascade logic, the AST approach is more reliable for aggressive optimisation.

Beautify mode is also useful for spotting cascade issues

When you’re inheriting a codebase and the CSS is a mess, running it through the beautifier and then reading it top-to-bottom often reveals property conflicts and duplicate selectors that are invisible in the original unformatted file. It’s not a linter, but it makes the structure readable enough that human review becomes productive.

Other CSS Tools
Questions
Yes, if the original was already minified or was very short to begin with. Minification removes whitespace and comments — if there aren’t many to remove, you might save a handful of bytes. But the encoded form after gzip can also differ: minification changes byte patterns, and in rare edge cases on small files this can produce a slightly larger gzip output. This is not a bug and not worth worrying about — the savings become meaningful on files over a few kilobytes.
Not from this tool. Whitespace removal and comment stripping don’t affect custom property names or values. Where minifiers can go wrong with custom properties is overly aggressive value collapsing — some tools misidentify a custom property value as a zero or a color and “optimise” it incorrectly. Regex-based minifiers like this one preserve values as-is. If you’re using an AST-based minifier and seeing unexpected custom property behaviour, check whether it has a setting to opt out of value optimisation.
Technically yes, and it’s happened. The CSS spec requires whitespace around operators inside calc(): calc(100% - 20px) is valid; calc(100%-20px) is not. Aggressive whitespace strippers that don’t understand CSS syntax can remove that required space. Most modern minifiers are aware of this, but if you’re using an old tool or find that a minified stylesheet breaks layout, calc() expressions are one of the first things to check.
Two things, one practical and one marginal. The practical one: consistent ordering makes code review and merging easier in teams. When every developer writes properties in a different order, diffs are noisy. An enforced sort means changes are more visible. The marginal one: alphabetically sorted properties create more repeated byte sequences in the source file, which gzip can compress slightly more efficiently. The savings are real but small — don’t sort properties only for gzip; do it for readability and consistent code style.