You find the rule that is breaking your layout. It is right there in the browser's DevTools styles pane, and you copy it to keep, compare, or paste into your stylesheet. What arrives in your editor is a cramped block: declarations squeezed together, indentation following no pattern you recognise, sometimes a rule that looks half minified. The values are all correct. The text is just hostile to read, and it makes a mess of the tidy stylesheet it lands in.
The fix is a single formatting pass. This guide shows how to take CSS copied out of DevTools, run it through the free CSS Formatter on Ovatly, and get back one declaration per line with a consistent indent, ready to save or compare against the rule in your source. It is equally clear about the limits: the formatter tidies the text you give it, and it cannot tell you where that text came from.
Contents
- Quick answer
- What you actually copy out of DevTools
- How to format copied CSS, step by step
- Worked example: from cramped paste to readable rule
- What the formatter cannot tell you
- Limitations and alternatives
- Common mistakes
- FAQs
- Conclusion
Quick answer
Copy the rules from the DevTools styles pane, paste them into the CSS Formatter, choose an indent of 2 or 4 spaces, and press Format CSS. The CSS comes back with one declaration per line and consistent indentation, ready to copy into your stylesheet or download. Formatting changes whitespace and line breaks only, so selectors, values and declaration order are exactly what you copied.
What you actually copy out of DevTools
The styles pane shows CSS the way the browser has parsed it, not the way anyone wrote it in a source file. Copy from it and the text reflects that: rules can arrive compressed onto few lines, spacing can be uneven, and the ordering follows the pane, not your stylesheet. If the stylesheet behind the page was minified, what you copy can look minified too, even though you never opened the production file.
None of that makes the copied CSS wrong. It makes it raw material. It is a faithful copy of selectors and values, wrapped in a debugging tool's layout rather than a codebase's. Before it can live in a stylesheet or be compared line by line with an existing rule, it needs the layout your codebase uses. That is the entire job of the formatting pass: the formatter works on the text, not on the provenance. Everything it knows about your CSS is what you pasted.
How to format copied CSS, step by step
- In DevTools, select the rule or rules in the styles pane and copy them.
- Open the CSS Formatter and paste the copied CSS into the input box.
- Choose an indent size of 2 or 4 spaces, matching the stylesheet the CSS is heading for.
- Press Format CSS.
- Copy the formatted stylesheet, or download it, and paste it into place.
One tip: copy complete rules, from the selector to the closing brace. A copy that stops mid-rule is the most common reason a paste formats oddly.
Worked example: from cramped paste to readable rule
Start with the example the CSS Formatter itself uses, a single minified rule:
body{margin:0;color:red}
One pass with a 2-space indent returns:
body {
margin: 0;
color: red
}
Same selector, same values, same order; only the layout changed. Now the more realistic case: several rules copied together as one cramped block:
.card{padding:16px;margin:0 auto;background:#fff}.card h2{font-size:20px;margin:0 0 8px}.card p{line-height:1.5;color:#333}
Formatted with the same 2-space indent, it comes back as:
.card {
padding: 16px;
margin: 0 auto;
background: #fff
}
.card h2 {
font-size: 20px;
margin: 0 0 8px
}
.card p {
line-height: 1.5;
color: #333
}
Now the block can be read, searched and compared. If your stylesheet already has a .card rule, the two versions line up declaration by declaration, and any difference from your source stands out immediately. That comparison only works because the formatter preserves declaration order exactly instead of rearranging the rule into an order of its own.
What the formatter cannot tell you
This is the honest part, and it matters more than the mechanics. The formatter formats whatever you paste, and it has no idea what any of it is.
It does not know which of the rules you copied are yours and which are browser default styles shown alongside them. Paste a default rule into your stylesheet and you have duplicated the browser's own styling for no benefit; the formatter will lay it out beautifully and say nothing. It also cannot see which declarations were overridden in the pane. A declaration that lost the cascade and showed struck through is, once copied, just text like any other. Paste it into your stylesheet expecting it to take effect, and formatting will not warn you it was already losing to another rule. Selector lines the pane shows for pseudo states, such as a hover variant, are simply more text lines to the formatter. It formats them correctly as CSS, but whether that state rule belongs in your stylesheet is your call.
In short, the formatter answers the question "what does this CSS say?" in a readable form. Questions like "where did this rule come from?" and "is this declaration actually winning?" have to be answered in DevTools, before you copy.
Limitations and alternatives
Formatting changes whitespace and line breaks only. It never changes your selectors or values, which makes the round trip safe, but formatting cannot repair anything. A wrong value stays wrong, and a property the browser ignored stays in the text. The formatter works on plain CSS: SCSS nesting and Less variables are not supported, so pane copies are fine, but preprocessor source needs a different tool. A missing closing brace can throw the indentation off, and the tool tells you when the CSS cannot be formatted; with copied text, that message usually means the selection was cut off mid-rule.
The alternative to formatting is pasting the cramped copy into your stylesheet and fixing the layout by hand. For one small rule that is survivable. For several rules, the manual pass is slower and easier to get subtly wrong, because hand-editing invites accidental changes to values a formatter cannot make.
Common mistakes
- Pasting everything the pane showed. Copying every visible rule sweeps browser default styles into your stylesheet along with your own. Copy only the rules you need, and check any rule you do not recognise.
- Treating an overridden declaration as a live one. If a declaration was struck through in the pane, it was losing the cascade. Pasting it elsewhere without the rule that beat it, or with it, changes what your CSS does in ways formatting cannot flag.
- Copying half a rule. A selection that ends before the closing brace can throw the indentation off or fail to format. Select from the selector to the closing brace, every time.
- Editing values during the formatting pass. The point of the tool is that values cannot change. Adjust a value as a separate, visible edit in your stylesheet, not silently inside a cleanup paste.
- Choosing a different indent from your stylesheet. The formatter offers 2 or 4 spaces. Pick the one your file already uses, or the pasted block will stand out and future diffs get noisier.
FAQs
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, and CSS copied from a DevTools pane is the same kind of cramped text, so it formats the same way.
Does it sort my properties alphabetically? No. Declaration order is preserved exactly, because order matters in the cascade. The order you copied is the order you get back, just laid out readably.
What is the difference between this and the CSS Minifier? This tool adds structure and indentation for humans. The minifier removes them for production files. Formatting is what you want when CSS is coming back into your source; minifying is for when it leaves.
Does formatting change my selectors or values? No. Formatting changes whitespace and line breaks only, never your selectors or values, so the rule you paste back behaves exactly like the rule you copied.
What if the pasted CSS will not format cleanly? A missing closing brace can throw the indentation off, which is easy to do when a copy stops mid-rule, and the tool tells you when the CSS cannot be formatted. Check the end of your copied text for a cut-off rule.
Conclusion
CSS copied from DevTools is good evidence in a bad layout. One pass through the CSS Formatter turns it into one declaration per line with an indent that matches your stylesheet, without touching a selector, a value or the order of a single declaration: exactly what you need before saving or comparing it. Just remember that the tidying is all it does: which rules are yours, and which were winning, are questions to settle in the pane before you copy. For the team-level version, the companion guide on why consistent CSS formatting prevents merge conflicts covers what a shared format does to diffs and reviews, and the rest of the series lives in the Developer Tools guides archive.