CSS Beautifier and Formatter

Turn minified or messy stylesheets into readable code. This CSS beautifier (CSS formatter) indents every rule, puts each selector on its own line, separates rules with blank lines and keeps your comments.

Press Ctrl+Enter (⌘+Enter on Mac) to run now.

Linecolumn

Beautify and Format CSS Online

A minified stylesheet is efficient for browsers and painful for people: a whole framework squeezed onto one line, with no way to see where a rule starts or which media query it belongs to. This CSS beautifier, also called a CSS formatter or unminifier, puts every declaration on its own line, indents rules inside @media and @supports blocks and separates rules with blank lines.

Use it to read a third-party theme, debug styles copied from dev tools, clean up CSS written in a hurry or make a diff readable. It also points out the first unclosed brace, comment or string it finds, which is the most common reason a stylesheet silently stops working halfway. Formatting uses js-beautify and runs in your browser.

Minified CSS beautified into indented rulesa{color: color:CSSBeautifier

How to beautify CSS

  1. Paste your CSS or open a .css file. Minified files, single rules and whole frameworks all work.
  2. Choose the indentation and brace style: opening braces on the same line as the selector (most common) or on the next line.
  3. Decide on layout details: one selector per line in comma-separated lists, blank lines between rules, spaces around >, + and ~.
  4. Keep or remove comments. Removing them still keeps /*! … */ license comments.
  5. Copy or download the formatted stylesheet. A yellow note appears if the CSS has an unclosed block, comment or string.

Before and after

A minified rule like .btn,.btn-primary{display:inline-flex;padding:10px 18px}@media (min-width:768px){.card{padding:28px}} becomes:

.btn,
.btn-primary {
  display: inline-flex;
  padding: 10px 18px
}

@media (min-width:768px) {
  .card {
    padding: 28px
  }
}

Selectors, property names and values are copied exactly. The beautifier changes whitespace and line breaks only, so the formatted stylesheet behaves the same as the original. Note that it does not add back semicolons that a minifier removed after the last declaration of a rule, because they are optional in CSS.

CSS beautifier options

OptionEffectDefault
Indent2 spaces, 4 spaces or tabs per nesting level2 spaces
Opening brace“Same line”: a {. “Next line”: brace on its own line (Allman style)Same line
Blank linesHow many empty lines in a row from your input are keptKeep up to 1
One selector per lineSplits h1, h2, h3 into one selector per lineOn
Blank line between rulesAdds an empty line after every closing braceOn
Spaces around > + ~.card>h2+p becomes .card > h2 + pOn
Keep commentsUntick to strip /* … */ comments (license comments stay)On
End with a newlineAdds a final line break for Git and lintersOn

SCSS, Less and modern CSS

The formatter understands nesting, so SCSS and Less files with nested rules, &:hover selectors and // line comments are generally formatted correctly. Modern CSS features such as custom properties (--brand: #4f46e5), native nesting, @layer, @container and @supports are handled as ordinary rules and blocks. Very unusual preprocessor syntax, such as Sass’s indented syntax without braces, is not supported because it has no braces to indent by.

Tips

  • Find the broken rule fast: when styles stop applying after a certain point, the note under the boxes shows where an unclosed {, comment or string starts.
  • Make diffs readable: one selector and one declaration per line means a version-control diff shows exactly which property changed.
  • Formatting is not optimization. For production, compress the stylesheet again with the CSS Minifier, which also shortens colors and merges duplicate rules.
  • Converting units? After formatting, the PX to REM converter helps turn fixed pixel sizes into scalable rem values; the CSS Gradient Generator and Box Shadow Generator write clean declarations you can paste in.

Frequently Asked Questions

Common questions about beautifying and formatting CSS.

Paste the CSS into the left box. The formatted stylesheet appears on the right with one declaration per line; adjust the options, then copy it or download it as a .css file.

Yes. Both names describe a tool that re-indents CSS and adds line breaks. “Unminify CSS” means the same thing when the input is a minified file.

No. Only whitespace and line breaks change. Selectors, properties, values and the order of rules stay exactly the same.

Nested SCSS and Less rules are generally formatted correctly, including & selectors and // comments. The brace-free indented Sass syntax is not supported.

Yes, by default every comment is kept in place. Untick “Keep comments” to remove them; /*! … */ license comments are kept either way.

It does not rewrite your code, but it reports the first unclosed block, comment or string with its line and column so you can fix it yourself.

Yes. Paste the formatted CSS into the CSS minifier to remove whitespace and comments again and see how many bytes you save.

No. The formatter library is loaded once and all formatting happens in your browser.