CSS Minifier / Beautifier

Shrink CSS by stripping comments and whitespace, or expand it back into cleanly indented, readable code — both directions, live.

1,256 views

How It Works

Minifying reduces file size by stripping everything that a machine parser doesn't need but a human reader would want: comments, line breaks, indentation, and the final semicolon before a closing brace. None of that is meaningful to how a browser applies styles — a stylesheet with every rule on one line and no whitespace behaves identically to a nicely formatted one, just smaller and faster to download. This matters in production because CSS blocks page rendering until it downloads and parses, so shaving kilobytes off the file directly improves page-load speed, especially on slow connections.

Beautifying is the reverse operation, and it is genuinely harder: it takes compressed or messy CSS and re-indents it with one declaration per line, one rule per block, consistent spacing around colons and braces. This is a kind of reverse engineering, because the original formatting — and especially any comments — is gone the moment a file is minified; only the structural formatting (which selector goes with which declarations) can be recovered, not the author's original line breaks or notes. For example, .btn{color:red;padding:8px} becomes a properly indented block with color: red; and padding: 8px; each on their own line inside .btn { }.

What You Should Know

  • Both directions preserve behavior exactly. Selectors, properties, values and cascade order are untouched — only whitespace and comments change, so specificity and inheritance work identically before and after.
  • This is a lightweight, regex-based tool, not a full CSS parser (like PostCSS). It handles standard CSS correctly, but content values containing literal {, } or ; inside quotes (rare in practice, mostly seen in generated content: values) may not format perfectly.
  • Sass/Less syntax isn't processed. Nesting, variables and mixins aren't valid CSS on their own, so they pass through largely unchanged rather than being compiled — you'll still need Sass or Less itself to turn those into plain CSS first.
  • Comments are the one thing minify permanently discards. If a comment documents a browser-specific hack or a "don't remove this" warning, keep a copy of the unminified source somewhere — the compressed output has no way to bring it back.

A concrete comparison: a beautified rule like .card { border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.1); } minifies down to .card{border-radius:8px;box-shadow:0 1px 3px rgba(0,0,0,.1)} — noticeably shorter, and across a full stylesheet with dozens of rules, comments and nested media queries, that saving typically runs from 20% to 40% of the original file size.

Frequently Asked Questions

Does minifying break my CSS?

No — it only removes comments and collapses whitespace around punctuation; every selector, property, value and rule stays functionally identical. A browser renders the minified and original versions exactly the same way, pixel for pixel.

Why does minifying speed up my site?

The browser has to download and parse the whole CSS file before it can safely render the page (this is why CSS is called "render-blocking"). A smaller file downloads faster, especially on mobile networks or slower connections, which shortens the time before the page becomes visible — directly improving metrics like First Contentful Paint.

Can beautify perfectly restore my original source code?

Not fully. Minifying is a one-way operation for anything beyond structure — comments and the developer's original line-break choices are permanently discarded the moment a file is compressed. Beautify reconstructs a clean, consistently indented version based purely on the structural syntax (selectors, braces, declarations) that survives minification, which is usually enough to make a stylesheet readable and diffable again, just not identical to the author's original file.

Does this handle SCSS or LESS syntax?

It's built for plain CSS. Sass/Less-specific syntax — nesting, variables like $color, mixins, @include statements — will pass through largely unchanged rather than being processed, since those constructs aren't valid CSS on their own and need their respective compilers (Sass or Less) to turn them into standard CSS first.

When should I minify vs. beautify?

Minify right before deploying to production, as the last step in your build process — the compressed file is what should ship to users, ideally alongside gzip or Brotli compression on the server for further savings. Beautify when you need to read, debug or diff a stylesheet that arrived minified, such as a third-party library's CSS, a file pulled from a live site's DevTools, or a build artifact you need to inspect by hand.

Comments

No comments yet — be the first to write one!

Similar Tools