How to Beautify CSS: Making Minified Stylesheets Readable

Last updated: · 5 min read

When you investigate a styling problem on a live site, what you usually find is a .min.css file squeezed onto one line: comments stripped, whitespace gone, every rule run into the next. That is fine for a browser, but a person can hardly see which selector carries which declaration. The CSS Beautifier rewrites such text with two-space indentation and one declaration per line. This guide explains exactly what formatting changes, which spaces the tool deliberately leaves untouched, and why the information lost during minification does not come back. The output in the example is the tool's real result.

Formula

Rules:
1. The text is read character by character; strings, comments and the contents of url(...) are kept exactly as they are.
2. Every { opens a block and adds two spaces of indentation; every } closes it.
3. Comma-separated selectors are written on separate lines, with the opening brace after the last one.
4. Each declaration goes on its own line, with one space after the first colon and a ; at the end (added if the last declaration of a block lacks it).
5. A blank line is inserted between rules; a comment outside a block is written on its own line.
6. Runs of spaces and line breaks are collapsed into a single space.
7. No spaces are added inside values, after commas or inside the parenthesised conditions of at-rules such as @media.

Input:
/* buttons */.btn,.btn-primary{color:#fff;background:url(img/bg.png) no-repeat;margin:0 auto}@media (min-width:600px){.btn{padding:8px 16px;font-family:Arial,sans-serif}}

Output:
/* buttons */
.btn,
.btn-primary {
  color: #fff;
  background: url(img/bg.png) no-repeat;
  margin: 0 auto;
}

@media (min-width:600px) {
  .btn {
    padding: 8px 16px;
    font-family: Arial,sans-serif;
  }
}

This is a rewriting algorithm, not a formula. According to CSS Syntax Module Level 3, a stylesheet is a list of rules, each consisting of a prelude and a block in curly braces; the whitespace between them carries no meaning. The tool only rearranges that insignificant whitespace. Selectors, property names, values and the order of the rules are untouched, so the page renders exactly as before.

What the inputs mean

CSS
The CSS text to format: a minified file or a fragment whose indentation has gone astray. @media, @supports and @keyframes blocks and nested rules are indented by level. Up to 1,000,000 characters are processed.

Worked example: Expanding a minified button style

  1. The leading comment /* buttons */ is kept and written on a line of its own.
  2. The selector list .btn,.btn-primary is split at the comma: .btn, on one line and .btn-primary { on the next.
  3. The three declarations are written on separate lines with two spaces of indentation. color:#fff becomes color: #fff; and margin:0 auto, which has no semicolon in the input, is completed as margin: 0 auto;.
  4. The contents of url(img/bg.png) are not touched; the address inside the parentheses stays as it is.
  5. A blank line follows the rule and the @media block begins. The condition (min-width:600px) is left as written, with no space after the colon. The inner .btn rule is indented one level and its declarations two; no space is added after the comma in Arial,sans-serif either.

Result: The one-line input becomes a 14-line stylesheet indented with two spaces. Selectors, values and rule order are identical to the input; only line breaks, indentation and the space after the colon have changed.

🖌️ CSS Beautifier

Free, no sign-up; your data stays in your browser.

Open the calculator →

How to read the result

Beautifying does not undo minification; it only makes the result easier to read. Comments removed by the minifier, variables from a Sass or Less source, nesting and the split into files are absent from the output because they are simply not in the minified file. The route back to the original is the source map produced by the build; when the browser's developer tools find one, they show which source file a rule came from. The tool does not validate CSS: a misspelt property or an invalid value passes straight through. If you want one consistent style across a team, a formatter wired into the build is the better place to enforce it. This is general information.

Common mistakes

  • Taking the beautified file for the original source. Comments, variables and file structure are not restored; make your edits in the source files.
  • Expecting the tool to catch mistakes. A wrong property such as colr:red is written out as colr: red;; only the balance of braces and comments is checked.
  • Pasting a block that is never closed. For .a{color:red the tool reports "Unbalanced braces: 1 block(s) not closed (missing “}”)."
  • Expecting spacing to be fixed everywhere. Arial,sans-serif, a>b and (min-width:600px) stay exactly as they were typed.
  • Deploying the beautified file. Indentation and line breaks make it larger; ship the minified version.
  • Pasting Sass or Less source. The tool is built for plain CSS and does not recognise line comments starting with //.

Frequently asked questions

Does beautifying change how the page looks?

No. The tool only rearranges whitespace between rules and declarations. Selectors, values and rule order stay the same, so the cascade and specificity are unaffected.

Can I get the original file back from minified CSS?

Not entirely. You get readable CSS, but removed comments and the preprocessor source do not return. For that you need the source map generated by the build.

Does the tool change values or colours?

No. #fff, RED or 0 0 0 0 stay as written; nothing is shortened, re-cased or sorted.

How are @media and @keyframes blocks written?

Every rule that opens a block adds one level of indentation. The from, to and percentage steps inside @keyframes are indented as blocks of their own, and block-less rules such as @import stay on one line.

Is my CSS uploaded to a server?

No, formatting happens in your browser and the text is not sent to a server.

The result is not exact or binding and is for information only; it is not an official document and cannot be used in official procedures. Confirm it with the competent authority or a professional before acting; no liability is accepted for losses arising from its use.

Sources

Choose your cookie preference to continue

Records the site needs to work (theme, language, favourites) stay in your browser.

This site is free and funded by ads.

With your consent, Google Analytics cookies measure visits and Google AdSense cookies are used to show ads; the data is processed on Google servers abroad.

If you reject, the site works just the same.

Cookie Policy · KVKK notice