Skip to content
toolbelt
Back to Guides

Understanding the Stylesheet You Inherited

By ·

Updated

Compressed CSS is technically CSS, but nobody has ever debugged it on one line. Expanding it is step one.

What is this tool?

A CSS formatter puts each selector and declaration on its own line, so you can see what belongs to what.

How it works

Prettier parses the stylesheet and re-prints it with consistent indentation. Because it parses rather than splits on semicolons, values that contain semicolons — data URIs, for example — survive intact.

Example

Before:
.a{color:red;margin:0}.b{color:blue;padding:8px}

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

.b {
  color: blue;
  padding: 8px;
}

When to use it

Reading a vendor stylesheet. Finding which rule actually overrides yours. Auditing a third-party widget before you agree to include it.

Optimization Tips

Once it is expanded, search for the property you are fighting rather than the selector. Anything with !important is where your bug lives about 80 percent of the time, and it is easy to miss when the file is one blob.

Frequently Asked Questions

Does it change how the CSS works?
No. Whitespace and newlines have no meaning in CSS outside of string values.
Will it reformat modern syntax?
Yes — nesting, custom properties and container queries all parse. It is current Prettier, not an old grammar.
Why did my data URI get mangled?
It should not. If it did, paste the error and I will look — that would be a bug.
Should I commit it formatted?
Yes, source CSS should always be readable. Only minify at build time.

Ready to try it out?

Put this knowledge into practice with our free tool.

Go to Tool

Related tools