CSS Formatter & Minifier

Turn a one-line stylesheet into readable, indented CSS, or squeeze readable CSS down for production.

Format vs. minify

Format puts each rule and declaration on its own indented line so the code is easy to read and review. Minify removes unnecessary whitespace so the file is smaller to send over the network.

A note on minifying

Keep your readable source file. Minified CSS is for delivery, and is hard to edit by hand.

How to use it

  1. Paste your CSS into Input CSS.
  2. Press Format or Minify.
  3. Copy the Output.

Formatting example

This one-line stylesheet:

body{margin:0;background:#fff;color:#333}h1{font-size:2em;}

becomes indented rules with one declaration per line.

Common use cases

What the formatter does and does not do

Both buttons are simple text transforms, not a CSS parser, which is good to know when something looks odd. Format starts a new line after every { and every ;, indents declarations by two spaces, and puts each closing brace on its own line followed by a blank line. It does not add a space after a colon and it does not add a missing final semicolon, so .a{color:red;margin:0 auto} becomes:

.a {
  color:red;
  margin:0 auto
}

Minify deletes comments, collapses runs of whitespace and removes spaces around { } ; : ,. The input .a > .b { margin: 0 auto; /* note */ color: red; } becomes .a > .b{margin:0 auto;color:red;}. The last semicolon is kept, and the combinator spaces around > are preserved.

Known gotchas

For a full production build use a real tool such as cssnano or Lightning CSS, which understand the grammar. This page is best for quickly reading or shrinking snippets.

A sensible workflow

When you receive minified CSS to debug, paste it and press Format, find the rule, make your change in your real source file, and never commit the minified or reformatted copy. If a rule looks wrong after formatting, compare it to the original, since the cause is usually one of the gotchas above rather than a mistake in your CSS. A quick check after minifying is to run Format again on the minified output: it should give back the same rules.

Frequently asked questions

What does a CSS formatter do?

It re-indents CSS so each selector and declaration is on its own line.

Does minifying change how my page looks?

It removes whitespace and comments, so the styling should be the same in normal cases. One known exception is a descendant selector such as .nav :hover, which loses its space and changes meaning; see the gotchas on this page.

Can it fix invalid CSS?

No. It formats what you give it; it is not a validator.

Is my data uploaded?

No. This tool runs entirely in your browser, so what you type or paste is not sent to our servers.

Does it add a space after the colon?

No. Format keeps your spacing around the colon, so 'color:red' stays 'color:red'. Only indentation and line breaks are changed.

Why did my data URI get split across lines?

Format breaks after every semicolon, including those inside url(data:...;base64,...). Keep long data URIs out of the pasted snippet or rejoin the lines.

Related tools

Explore all developer tools →