CSS Beautifier / Minifier

Beautify and minify CSS code

What a CSS Beautifier Does

A CSS beautifier (also called a CSS formatter or pretty-printer) takes compressed or messy CSS and lays it out one declaration per line, indented under its selector. A minifier does the reverse: it strips comments and every whitespace character the browser doesn’t need, so the file downloads faster.

Both directions should be invisible to the browser. This tool is built around one rule: only whitespace changes, and only where CSS ignores it. It tokenizes the stylesheet the way a browser does, so it knows where a string ends, where a url(...) ends and which spaces are combinators, instead of running find-and-replace over the text.

How to Use the CSS Beautifier

  1. Paste your CSS into the input area above.
  2. Click “Beautify” or press Ctrl+Enter to format it.
  3. Click “Minify” to compress it instead.
  4. Pick 2 spaces, 4 spaces or tabs in the Indent setting.
  5. Copy the result with “Copy” or Ctrl+Shift+C, and clear with Ctrl+L.

What Beautify Changes, and What It Leaves Alone

Beautify normalizes the layout:

  • One declaration per line, written as property: value;, with the trailing semicolon added if it was missing.
  • One selector per line in a selector list (h1, / h2, / h3 {), and { on the selector’s line.
  • A blank line between top-level rules. Blank lines you already had are kept, at most one in a row.
  • Single spaces around the >, + and ~ combinators, after commas in rgba(0, 0, 0, .5), and before !important.
  • @media(min-width:600px) becomes @media (min-width: 600px).

It never touches:

  • Strings. content: "a b" keeps all three spaces.
  • Unquoted url(...), including data URIs full of ; and ,.
  • Comments. A comment on the same line as a declaration stays on that line.
  • Custom property values (--x: ...), which are copied as written, because JavaScript can read their exact text.
  • The rows of grid-template-areas, which stay one per line so the grid layout is still readable.

Where Whitespace Matters in CSS

Most CSS whitespace is decoration. These are the places where it isn’t, and where simpler formatters break code:

  • The descendant combinator. .nav :hover matches any hovered element inside .nav, while .nav:hover matches the nav itself. .card ::before and .card::before differ in the same way.
  • calc(). calc(100% - 2rem) is valid. calc(100%-2rem) is not, because -2rem is read as a negative number with no operator in front of it. Spaces around + and - are required. Around * and / they’re optional.
  • Media queries. In screen and (max-width: 600px) the space after and matters: and( is read as a function name, and the whole query fails.
  • CSS escapes. In .\31 0 (a class named “10”), the space ends the \31 escape. Collapsing two spaces after an escape into one would turn a descendant selector into part of the class name.
  • Unquoted URLs. A line break inside url(data:image/png;base64,...) makes it a “bad URL”, and the browser throws the whole declaration away.

Minifying CSS for Production

The minifier removes comments, indentation and line breaks. It also removes the spaces around braces, semicolons and commas, after the colon in a declaration, around the >, + and ~ combinators, just inside parentheses, and before !important, plus the last semicolon in each block. License comments that start with /*! are kept. Everything listed in the section above stays as it is.

It doesn’t rewrite values. It won’t shorten #ffffff to #fff, merge duplicate rules or drop vendor prefixes. Those optimizations depend on your browser targets, and they’re what build tools like Lightning CSS, cssnano and esbuild are for. Use this tool for quick one-off jobs, like checking how much a stylesheet shrinks, minifying a snippet for an inline <style> tag, or “unminifying” production CSS from DevTools so you can read it.

Modern CSS: Nesting, Layers and Container Queries

The formatter follows the current CSS syntax spec. An item that reaches { before ; is a rule, and anything else is a declaration. That’s why native nesting works:

.card {
  color: red;
  &:hover {
    color: blue;
  }
  > .title {
    font-weight: 600;
  }
}

When minifying, the semicolon after color: red is kept, because without it the nested selector would be swallowed into the value. @layer, @container, @supports, @property and @font-face are formatted like any other block. Statements such as @import and @layer base, components; stay on one line.

Common CSS Errors the Beautifier Exposes

Formatting is often the fastest way to find a syntax error, because the indentation shows you how the browser actually reads the file:

  • Unclosed brace. Everything after a missing } gets indented one level deeper. The browser nests it the same way, so those rules only apply inside the unclosed rule. The beautifier closes the block at the end of the file, just as the browser does, and the indentation shows where the brace is missing.
  • A stray semicolon after }. At the top level, .a { } ; .b { } makes the ; part of the next selector, and the browser drops the whole .b rule. The beautifier puts the ; on its own line so you can see it.
  • // comments. CSS has no line comments. In plain CSS, // note becomes part of the next rule or declaration and kills it. The tool keeps such lines as written (so SCSS still works), but in a .css file, use /* ... */.
  • Unterminated strings. A missing closing quote ends the string at the line break, and the browser drops that declaration. The tool keeps that line break, so the error doesn’t spread to the next rule.
  • Missing semicolon. color: red background: blue is one invalid declaration, not two. After beautifying, both properties sit on a single line, which makes the problem obvious.

CSS Beautifier vs Prettier and Stylelint

Prettier is the standard choice when formatting is part of your project: it runs on save or in CI, so everyone’s CSS looks the same. It also knows SCSS and Less in depth. Stylelint is a linter rather than a formatter. It catches invalid properties, duplicate selectors and specificity problems, and it can enforce conventions, like a property order, that formatting can’t.

An online beautifier fits in where those tools aren’t set up: a snippet copied from DevTools, a minified stylesheet from a third-party site, CSS pasted from a chat, or a quick minify for an email template. Nothing to install or configure, and your code never leaves the browser.

Frequently Asked Questions

Does beautifying or minifying CSS change how it works?

It shouldn't, and this tool only touches whitespace that the CSS parser ignores. Strings, url() values, comments and custom property values are copied as written, and the space in a selector like .nav :hover is kept. Naive formatters get this wrong. Deleting that space turns .nav :hover (any hovered element inside .nav) into .nav:hover (the nav itself when hovered), and splitting url(data:image/png;base64,...) at the semicolon breaks the image.

Why does the minified output still contain spaces?

Some whitespace is part of the code. A space between two selectors is the descendant combinator, the spaces around + and - inside calc() are required, and the space in @media screen and (max-width: 600px) stops and( from being read as a function. The minifier removes whitespace around braces, semicolons, commas and combinators and after a declaration's colon, and keeps the rest.

Does the minifier remove license comments?

No. Comments that start with /*! are kept, the same convention cssnano, esbuild and most bundlers follow, so copyright notices survive. All other comments are removed.

Can I format SCSS or Less with it?

Partly. Nesting, variables like $color: red and @include lines are formatted, and // line comments are kept as written, with their line break, so the file still compiles. It doesn't understand Sass control flow or Less guards, and it doesn't compile anything. For a full Sass codebase, use Prettier or your editor's formatter.

Does it support native CSS nesting?

Yes. Rules nested inside other rules, & selectors, relative selectors like > .child and at-rules nested inside rules are all indented under their parent. Minify keeps the semicolon a declaration needs when a nested rule follows it.

Is my CSS sent to a server?

No. Beautifying and minifying run entirely in your browser in JavaScript. Nothing is uploaded, which you can confirm in the Network tab of your browser's developer tools.

When should I minify CSS?

Minify for production and keep the readable version in source control. Across 30 real-world stylesheets we tested, removing whitespace and comments saved 21 to 61 percent, with a median of about 29 percent. Heavily commented files save the most. Gzip or Brotli compression on the server comes on top of that.