Skip to the tool
DevToolBench

CSS Beautifier

Unminify and indent CSS, one declaration per line.

0 chars
Rules and blocks
0
Declarations
0
Lines
0

Everything runs in your browser. Nothing you type is sent to a server.

Found a bug in this tool? Report it.

Share this tool

What this CSS beautifier does

This CSS beautifier turns a wall of minified or badly indented CSS into something you can read: one selector per line in a list, one declaration per line in a block, and every nested block — @media, @supports, @container, native & nesting — indented one step further than its parent. Choose 2 spaces, 4 spaces or tabs, and the result updates as you type, in your browser.

It shares its tokeniser with the CSS minifier on this site. The two tools read a stylesheet into the same tree and write it out in opposite directions, so what one flattens the other can open back up.

How to use it

  1. Paste the CSS you want to format online into the input box.
  2. Pick an indentation: 2 spaces, 4 spaces or a tab.
  3. Read the formatted output, with a count of blocks, declarations and lines underneath.
  4. Copy it, or download it as styles.css.

What changes, and what does not

The output gets a space after each colon in a declaration, after each comma in a value, around the >, + and ~ combinators in a selector, and before !important. Blank lines separate blocks from one another, while a comment sits directly above the rule it describes, as people write it by hand.

What does not change is anything with meaning. Strings keep their inner spacing. A url() is left as a single piece, so a data URI with semicolons in it survives. Custom properties are only collapsed, never reshaped, because their value is text that JavaScript may read back. Inside parentheses, such as :nth-child(2n+1) or calc(100% - 2rem), whitespace is kept as it was found: a formatter has no business deciding that a minus sign is a hyphen.

When you need to unminify CSS

The usual reason is debugging. The DevTools panel shows a rule, you click through to the source, and the source is a single line of forty thousand characters. Pasting it here gives you something you can search, diff against an older copy, or read to understand how a third-party theme builds its layout.

The other reason is inheritance. A site arrives with no build step and one compressed stylesheet that someone has been editing by hand for years. Formatting it first makes every later change reviewable, and a text diff of the formatted versions shows exactly what each edit did.

Beautifier or linter

A beautifier fixes layout. It does not tell you that a property is misspelt, that two rules fight over the same element, or that a vendor prefix has been obsolete for a decade. For that you want a linter such as Stylelint in your editor. The two work well together: format first so the file is readable, then let the linter point at the problems.

Two spaces, four spaces or tabs

There is no correct answer, only a house style. Two spaces is the most common choice in front-end projects and the default in Prettier, and it keeps deeply nested @media and @supports blocks from drifting off the right edge. Four spaces reads more clearly at a glance. Tabs let each person set the width in their own editor. Whichever you pick, match the rest of the codebase, so a later diff shows real changes rather than a reindented file.

Frequently asked questions

Will beautifying change how my CSS behaves?

No. Only whitespace is added or removed, and only where CSS gives whitespace no meaning. Values, strings, url() contents and attribute selectors come out exactly as they went in, and the spaces that do matter — around + and - inside calc(), or before the colon in a :hover selector — are kept as you wrote them.

Why is a :hover not joined into a:hover?

Because they select different things. a:hover is a link under the pointer. a :hover, with the space, is any hovered element inside a link — the space is a descendant combinator. A formatter that tidied it away would quietly change your stylesheet, so this one keeps whatever spacing it found in front of a colon in a selector.

Can it unminify CSS from a production site?

Yes, that is the most common use. Paste the minified file, pick an indentation and you get one declaration per line with nested @media, @supports and native nesting blocks indented. Comments the minifier removed cannot come back, of course, and neither can the original variable names if a preprocessor compiled them away.

Does it sort properties or fix errors?

No. Reordering declarations can change the cascade when shorthands and longhands are mixed, and guessing at a fix produces CSS that says something you never wrote. Broken input — an unclosed string, comment or block — is reported with the line number instead.

Is my CSS uploaded to format it?

No. The CSS formatter runs entirely in your browser, so the stylesheet never leaves your device.

Related tools

Updated