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
- Paste your CSS into the input area above.
- Click “Beautify” or press
Ctrl+Enterto format it. - Click “Minify” to compress it instead.
- Pick 2 spaces, 4 spaces or tabs in the Indent setting.
- Copy the result with “Copy” or
Ctrl+Shift+C, and clear withCtrl+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 inrgba(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 :hovermatches any hovered element inside.nav, while.nav:hovermatches the nav itself..card ::beforeand.card::beforediffer in the same way. calc().calc(100% - 2rem)is valid.calc(100%-2rem)is not, because-2remis 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 afterandmatters: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\31escape. 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.brule. The beautifier puts the;on its own line so you can see it. //comments. CSS has no line comments. In plain CSS,// notebecomes part of the next rule or declaration and kills it. The tool keeps such lines as written (so SCSS still works), but in a.cssfile, 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: blueis 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.