CSS Formatter
Developer Tools · Added
Format CSS with consistent indentation, or minify it for delivery. The parser tracks strings, comments and url() bodies, so a brace inside a content string or a semicolon inside a data URI cannot be mistaken for structure.
How to use the css formatter
- 1Paste your CSS.
- 2Choose Beautify to expand it with one declaration per line, or Minify to compress it.
- 3For beautifying, pick two spaces, four spaces or tabs.
- 4For minifying, choose whether to drop comments. A /*! … */ licence header is kept either way.
- 5Copy the result or download it as a file.
Examples
Expanding a minified stylesheet
- Input
- .card,.card--wide{display:flex;padding:1rem}
- Result
- Each selector on its own line, each declaration indented and spaced
Selector lists are split one per line, which makes a long list of selectors readable and diffs far easier to review.
Minifying for delivery
- Input
- A formatted stylesheet with comments and indentation
- Result
- One line, comments dropped, redundant final semicolons removed
Savings of 15–25% before compression are typical. After gzip the difference is much smaller, because gzip is already very good at repeated whitespace.
A data URI that would break a naive minifier
- Input
- a{background:url(data:image/png;base64,AAA)}
- Result
- The url() body is returned unchanged
The semicolon inside the data URI is not the end of a declaration. url() bodies, quoted strings and comments are all captured as units before any whitespace is touched.
About the css formatter
What a CSS parser has to get right
CSS looks like it can be processed with search and replace, and mostly it can — right up to the point where it cannot. Three constructs can contain characters that otherwise mean something structural: a quoted string can contain braces and semicolons, a url() body can contain them unquoted, and a comment can contain anything at all. A minifier that collapses whitespace across the whole file will corrupt every one of them.
The consequences are quiet. content: " Note: " losing its spacing does not throw an error; it just renders differently. A data URI truncated at its first semicolon does not fail loudly; the background simply does not appear. Because nothing breaks visibly at build time, these bugs tend to be found by users rather than by developers, which is why this tool captures all three as units before touching anything.
Formatting as a diff tool
The most useful thing about a beautifier is often not readability but comparability. A stylesheet that arrives minified, or written in someone else's brace style, produces a diff where every line has changed and nothing can be reviewed. Running both versions through the same formatter first reduces that to the lines that genuinely differ.
Splitting selector lists one per line serves the same purpose. A rule with eight selectors on one line shows up in a diff as a single changed line no matter which selector moved; split across eight lines, the change is exactly one of them. It costs a little vertical space and repays it the first time you have to review someone else's stylesheet.
Frequently asked questions
Does it change my CSS, or only its layout?
Does it handle nesting and modern at-rules?
Will minifying break a content string?
How much will minifying actually save?
Is my stylesheet uploaded?
Related tools
HTML Formatter
Developer Tools
Beautify and indent HTML markup, or minify it for production.
CSS Gradient Generator
Developer Tools
Build a linear, radial or conic CSS gradient visually and copy the declaration.
CSS Unit Converter
Converters
Convert px, rem, em, pt, %, vw and vh against a root font size you set.