CSS Beautifier

Format CSS with consistent indentation.

Local Your input is processed locally in your browser. The first run loads the open-source Prettier library from this site; your input is not sent anywhere. Found a problem? Report an issue

What the CSS Beautifier does

The CSS Beautifier formats CSS with Prettier 3.3.3, an open-source code formatter, running in your browser. It supports Standard CSS including at-rules and custom properties.

CSS Beautifier examples

The built-in sample

Input

a{color:red;margin:0 auto}.b{padding:4px}

Output

a {
  color: red;
  margin: 0 auto;
}
.b {
  padding: 4px;
}

This is the input that the Load sample button fills in.

Values that are normalised and values that are not

Input

a{COLOR:#FFF;transition:all .3s;margin:0px;font:12PX/1.5 Arial}a::after{content:'x'}

Output

a {
  color: #fff;
  transition: all 0.3s;
  margin: 0px;
  font: 12px/1.5 Arial;
}
a::after {
  content: "x";
}

The property name and the hex colour are lower-cased, .3s gains a leading zero, the unit PX is lower-cased and the string gets double quotes. 0px is not shortened to 0: the formatter changes spelling, not values.

Each output was produced by running this tool on the input above it.

How it works

The code is parsed with Prettier's css parser and printed again from its syntax tree, using Prettier's default options: lines up to 80 characters and two-space indentation. The result therefore does not depend on how the input was laid out. If the code cannot be parsed, the parser's message with its line and column is shown instead of output.

Details and limits

  • Each selector in a comma-separated list goes on its own line, and each declaration ends with a semicolon.
  • Comments are kept where they are.
  • Property names are not checked: a misspelt property is formatted like a correct one. Only syntax that cannot be parsed, such as a missing closing brace, is an error.
  • Keyword values keep their case (Red stays Red), while hex colours and units are lower-cased.

Common errors

Message or symptomWhat it means
CssSyntaxError with a line and columnA missing brace or semicolon. The line and column point to where parsing stopped.

Questions

Is my data uploaded when I use CSS Beautifier?

No. The tool runs in your browser, so what you paste or open is processed on your own device and is not sent to a server.

What does CSS Beautifier do?

The CSS Beautifier formats CSS with Prettier 3.3.3, an open-source code formatter, running in your browser. It supports Standard CSS including at-rules and custom properties.

How does CSS Beautifier work?

The code is parsed with Prettier's css parser and printed again from its syntax tree, using Prettier's default options: lines up to 80 characters and two-space indentation. The result therefore does not depend on how the input was laid out.

Are there any limits I should know about?

Each selector in a comma-separated list goes on its own line, and each declaration ends with a semicolon. Comments are kept where they are.

Is there a size limit?

There is no fixed size limit. Everything happens on your device, so very large inputs depend on its memory and can take longer on a phone than on a computer.

Does it work on phones, and is it free?

Yes. It works in any current browser on Android phones, iPhones, tablets and computers. It is free and needs no account or sign-up.