EthicalFusion

CSS Beautifier

Format and indent minified or messy CSS into clean, readable style rules.

Was this tool helpful?

Thanks for the feedback!

The CSS Beautifier takes minified or messy stylesheet code and lays it out with one declaration per line and two-space indentation, so you can see which properties belong to which selector. It is most useful for reading a compressed theme or plugin file, such as a style.min.css, when you need to find the rule that sets a colour or margin.

Before and after

The sample input body{margin:0;padding:0}a{color:red} comes out as:

body {
  margin:0;
  padding:0
}
a {
  color:red
}

Nested blocks get deeper indentation. A media query such as @media (max-width:600px){.nav{display:none}.menu a{padding:8px 12px;color:#333}} becomes:

@media (max-width:600px) {
  .nav {
    display:none
  }
  .menu a {
    padding:8px 12px;
    color:#333
  }
}

Exactly what gets changed

  • A space and line break are added after each opening brace, a line break after every semicolon, and each closing brace goes on its own line.
  • Indentation follows the brace depth, two spaces per level.
  • Nothing is renamed, reordered or removed. Property values stay exactly as written, so margin:0 keeps its missing space after the colon and a final declaration without a semicolon stays that way.
  • Comments are kept, although a comment may end up on the same line as the selector that follows it.

Where the formatting can go wrong

The beautifier splits lines at every semicolon, including ones inside values. A data URI like url(data:image/png;base64,…) is broken across two lines, and a line break inside url() or a quoted string makes that declaration invalid. The same happens with content: ";". Read the formatted output freely, but if you plan to save it as your working file, rejoin those values first.

It also doesn't validate. A missing closing brace makes the indentation of everything after it drift one level to the right, which is actually a quick way to find the spot where the brace went missing.

The indentation is also the fastest way to answer a common debugging question: does this rule apply everywhere, or only inside a media query? In a minified file the @media wrapper may be hundreds of characters away from the selector you found. After beautifying, any rule indented under an @media or @supports line only applies when that condition is true, which often explains why a style works on desktop but not on mobile.

A practical workflow

  1. Beautify the minified file and search it for the selector or colour you need.
  2. Make your change in the readable version, or better, in your own source file or child theme.
  3. Compress it again for production with the CSS Minifier.

Browser developer tools can also pretty-print a stylesheet, but pasting the code here gives you a plain-text copy you can keep, compare with an older version, or send to a colleague. For page markup, the HTML Formatter does the same job.

Frequently asked questions

Does the CSS beautifier fix errors in my code?
No. It only adds line breaks and indentation. A missing brace will show up as indentation that drifts to the right from that point on.
Why is there no space after the colon in the output?
The tool keeps each declaration exactly as written and only changes the layout around braces and semicolons. Add spaces by hand or with an editor setting if you prefer them.
Will beautified CSS change how my page looks?
Normally not, because whitespace between declarations has no effect. The exception is a semicolon inside a url() data URI or quoted string, where the added line break makes that value invalid.
Can it format SCSS or LESS?
Simple nested rules indent correctly because the layout follows braces, but the tool knows nothing about SCSS-specific syntax, so check mixins and // comments by eye.
How do I shrink the CSS again after editing?
Paste it into the CSS Minifier, which strips comments and whitespace for production use.

Related tools

People also used

Embed this tool on your site

Paste it into any blog or website. Free, with a credit link.