Open a stylesheet you did not write, or one you wrote six months ago, and the problem is rarely the CSS itself. The problem is the layout. Rules arrive flattened onto single lines, indentation wanders from block to block, and three declarations share a line so a changed value hides in the middle of it. The styles work, but nobody can review them, and every edit feels risky because nothing lines up.
Most unreadable CSS fails in the same handful of ways, and most of them are layout mistakes rather than knowledge mistakes. This guide walks through the five common ones and fixes the mechanical ones with the free CSS Formatter on Ovatly, which turns compressed or sloppily indented stylesheets into readable CSS with one declaration per line and consistent indentation. It is just as clear about the mistake a formatter cannot fix: tidy formatting is not proof that the CSS is valid.
Contents
- Quick answer
- Why readability mistakes are expensive
- Mistake 1: whole rules on one line
- Mistake 2: indentation that drifts from rule to rule
- Mistake 3: several declarations crammed on one line
- Mistake 4: hand-reformatting that reorders the cascade
- Mistake 5: assuming tidy formatting means valid CSS
- How to fix the layout mistakes, step by step
- Worked example: one minified rule, formatted
- Limitations and honest boundaries
- FAQs
- Conclusion
Quick answer
Four of the five mistakes are pure layout: rules flattened onto one line, indentation that changes from block to block, several declarations sharing a line, and hand edits that shuffle declaration order while tidying. Paste the stylesheet into the CSS Formatter, choose an indent of 2 or 4 spaces, and press Format CSS. The output puts one declaration per line with consistent indentation, and because formatting changes whitespace and line breaks only, never selectors or values, the result behaves exactly like the original. The fifth mistake is different: a missing closing brace breaks CSS no matter how tidy it looks, and formatting will not repair it.
Why readability mistakes are expensive
CSS is read far more often than it is written. It gets reviewed in pull requests, searched during bug hunts, and edited under time pressure by people who did not write it. Every layout mistake taxes those moments. A reviewer scanning a one-line rule has to parse it character by character. A developer hunting for where a colour is set has to read whole blocks instead of glancing down a column of property names.
Mistake 1: whole rules on one line
Minified production CSS is the extreme case: an entire stylesheet with the line breaks removed, built for browsers rather than people. The same shape appears in hand-written code whenever someone writes a quick rule inline and never expands it. A rule on one line cannot be scanned, diffed or safely edited, because there is no visual difference between its selector, its properties and its values. Expanding it is the formatter's main use: one-line production CSS comes out as a normally indented stylesheet.
Mistake 2: indentation that drifts from rule to rule
One rule indented with two spaces, the next with four, a third with a tab, a fourth flush against the margin. Each block is readable on its own, but together they destroy the one thing indentation is for: showing structure at a glance. When neighbouring rules indent differently, you cannot tell whether a rule sits at the top level or inside something else without reading it closely. Consistent indentation is a mechanical property, which makes it a mechanical fix.
Mistake 3: several declarations crammed on one line
When three or four declarations share a line, a review diff shows the whole line as changed even when only one value moved. The change a reviewer most needs to see, the single value that was edited, is buried in the middle of an unchanged line. One declaration per line fixes this structurally: each property gets its own line, so a changed value stands alone in the diff and an unchanged one never moves.
Mistake 4: hand-reformatting that reorders the cascade
Tidying CSS by hand carries a risk that tidying by tool does not. It is easy, while splitting lines and aligning things, to drag a declaration above another one, and in CSS order is meaning: when two declarations in a rule set the same property, the later one wins. A well-meaning tidy can quietly change which value applies. The formatter cannot make this mistake, because it never reorders anything. Declaration order is preserved exactly, for precisely this reason, and its properties are not sorted alphabetically either. What changes is whitespace and line breaks, nothing else.
Mistake 5: assuming tidy formatting means valid CSS
The most dangerous mistake is the conclusion drawn from a clean result: the stylesheet looks structured, so it must be sound. It does not follow. Formatting is not validation. A missing closing brace breaks everything after it in the file, and no amount of indentation repairs that. In fact the formatter gives you a useful signal here: a missing closing brace can throw the indentation off, and the tool tells you when the CSS cannot be formatted at all. Treat that message as a symptom worth investigating, not as a problem the tool failed to solve. Fix the brace yourself, then format again.
How to fix the layout mistakes, step by step
- Copy the stylesheet, or the section of it you need to read, and paste it into the CSS Formatter.
- Choose an indent size of 2 or 4 spaces. Pick the one your project already uses, so the output matches the surrounding code.
- Press Format CSS.
- Read the result: one declaration per line, steady indentation, declaration order untouched.
- Copy the formatted stylesheet, or download it, and work from that copy.
If the tool reports that the CSS cannot be formatted, stop and look for a structural fault such as a missing closing brace before trying again. That is Mistake 5 announcing itself.
Worked example: one minified rule, formatted
The formatter's own example is a single compressed rule:
body{margin:0;color:red}
One line, no spaces, nothing to scan. After one pass through the tool with a 2-space indent, it comes back as:
body {
margin: 0;
color: red
}
Nothing about the rule changed: same selector, same two declarations, same order, same values. What changed is only the layout, and with it everything the mistakes above were costing you. Each declaration now sits on its own line, so editing the colour later produces a one-line diff. The block is indented the same way every other block in the file will be. And because the formatter produced this rather than a person, there is no chance the two declarations swapped places on the way.
Limitations and honest boundaries
The formatter works on plain CSS only. SCSS nesting and Less variables are not supported, so preprocessor files need compiling to plain CSS first. It does not validate: broken CSS stays broken, and the tool's cannot-format message is a warning, not a repair. It does not sort properties, rename anything, merge rules or remove unused CSS; those are different tools with different risks. And it runs in your browser, so your stylesheet is not uploaded anywhere. For the opposite job, shrinking a readable stylesheet back down for production, you want a minifier rather than a formatter. The same discipline of knowing exactly what a tool removes, and what it leaves alone, applies there too: our companion guide on how much file size JavaScript minification actually saves works through real counted examples instead of guessed percentages.
More guides for working with code, markup and stylesheets live in the developer tools guides.
FAQs
Does formatting sort my CSS properties alphabetically? No. Declaration order is preserved exactly, because order matters in the cascade. The formatter changes whitespace and line breaks only, never your selectors, values or the order of declarations.
Can formatting change how my CSS behaves? No. Because only whitespace and line breaks change, the formatted stylesheet does exactly what the original did. The risk runs the other way: hand-reformatting can accidentally reorder declarations and change the cascade, which the formatter never does.
Will the formatter fix a broken stylesheet? No. A missing closing brace can throw the indentation off, and the tool tells you when the CSS cannot be formatted. That message is a useful warning, but repairing the brace is still your job.
Can it format CSS copied from a minified file? Yes, that is its main use. One-line production CSS comes out as a normally indented stylesheet with one declaration per line, ready to read or edit.
Does it work on SCSS or Less? No. The formatter works on plain CSS only. SCSS nesting and Less variables are not supported, so compile those files to plain CSS first.
Conclusion
Unreadable CSS is usually five specific mistakes wearing a trench coat: one-line rules, drifting indentation, crammed declarations, hand edits that shuffle the cascade, and tidy output mistaken for valid code. The first four are layout, and layout is safe to fix mechanically, because a formatter that changes only whitespace and line breaks cannot change behaviour. The fifth is a reminder to keep the jobs separate in your head: format to read, validate to trust. Run your next inherited stylesheet through the formatter before you edit it, and you will feel the difference in the first minute.