You open a pull request and the diff lights up: three hundred lines changed. Your teammate insists they only adjusted one colour and a margin. Both of you are right. They did change two values, but their editor rewrote the layout of the stylesheet, so the diff shows a file that looks rewritten from top to bottom. Somewhere inside that noise, a genuine second change hides, and the reviewer will never spot it.
This is not really a people problem. It is a line problem, and CSS is unusually vulnerable to it. This guide explains why a shared format, applied with a tool like the CSS Formatter, shrinks diffs to the changes that happened, and makes merge conflicts rarer and code review honest again.
Contents
- Quick answer
- Diffs and merges work line by line
- Why CSS makes formatting noise so easily
- What a shared format changes
- How to format CSS, step by step
- Worked example: one change, two diffs
- Limitations and alternatives
- Common mistakes
- FAQs
- Conclusion
Quick answer
Version control compares the old and new versions of a file line by line, and a merge conflict is what happens when two people change the same lines in different ways. If every stylesheet follows one shape, one declaration per line with a consistent indent, a one-value change produces a one-line diff, and two people editing different rules rarely touch the same lines at all. Running CSS through the CSS Formatter before committing gives everyone the identical shape: paste the CSS, choose an indent of 2 or 4 spaces, press Format CSS, and copy or download the result.
Diffs and merges work line by line
A version control system does not understand CSS. It stores and compares text, and the unit of comparison is the line. When you ask what changed between two versions, it answers with lines removed and lines added. When two branches change the same line differently, it cannot pick a winner, so it stops and asks a human: that stop is a merge conflict.
Two consequences follow. First, the size of a diff is measured in lines, not in meaning. A change that alters one value inside a very long line is a whole line removed and a whole line added, and a reader must scan the whole line to find the one token that differs. Second, layout differences count as changes. If one version indents a rule with two spaces and the next uses four, or one puts a rule on a single line and the next spreads it over six, the comparison reports those lines as changed, though the stylesheet behaves identically in the browser.
Merging inherits both problems. Two developers can edit different rules in the same file and still collide, because the lines their edits sit on were rewritten by formatting differences. The conflict is real to the tool and meaningless to the team, and resolving it costs attention, the one thing review is supposed to protect.
Why CSS makes formatting noise so easily
CSS invites this because the same rule has many legal layouts. A rule can live on a single line or spread across ten, with an indent of two spaces, four spaces or a tab. None of it changes what the browser does, so nothing pushes back when styles drift apart inside one file.
Real stylesheets collect these styles like sediment. One section was written by hand, another pasted from a minified production file, a third copied from a framework example. Together they guarantee the next edit produces a diff far larger than the change itself.
What a shared format changes
A shared format attacks the problem at the line level. When every rule has the same shape, one declaration per line with consistent indentation, the diff of a change shows exactly the lines that carry the change. Change a colour and one line turns red and one turns green. Reviewers read the change itself, not the whole file.
Conflicts shrink for the same reason. Two developers editing different declarations in the same rule now touch different lines, so the merge succeeds on its own. The conflicts that remain are the honest kind: both sides really did change the same value, and a human needs to decide. Formatting removes the fake conflicts, the collisions caused by layout rather than intent.
The catch is that the format has to be reproducible, not just agreed. A style guide that says "be consistent" produces five interpretations on a five-person team. A formatter produces one output for a given input, whoever runs it. That is the whole value of a tool like the CSS Formatter: the shape stops being a matter of taste and becomes a mechanical step anyone can repeat.
How to format CSS, step by step
- Open the CSS Formatter and paste your CSS into the input box.
- Choose an indent size of 2 or 4 spaces, the one your team has agreed on, and use it every time.
- Press Format CSS.
- Copy the formatted stylesheet, or download it, and commit that version. A team adopting this should format each stylesheet in its own dedicated commit first, with no value changes mixed in, so later diffs stay small.
Worked example: one change, two diffs
Take the minified rule the CSS Formatter uses as its own example:
body{margin:0;color:red}
Suppose a teammate changes the text colour from red to blue. On the one-line version, the diff is the whole line removed and the whole line added, and the reviewer must compare both lines character by character to find it. Now run the same rule through the formatter:
body {
margin: 0;
color: red
}
The rule is identical in meaning: formatting changes whitespace and line breaks only, never your selectors or values. But the colour change touches one line, the color: red line becoming a color: blue line, while the margin line sits untouched on both sides. Multiply that by a full stylesheet and it is the difference between a review that happens and one that gets waved through.
Limitations and alternatives
The formatter has a deliberately narrow job, and its limits matter for this workflow. It changes whitespace and line breaks only: it will not sort declarations alphabetically, because declaration order is preserved, and it will not fix a wrong value or a broken rule. It works on plain CSS, so SCSS nesting and Less variables are not supported. A missing closing brace can throw the indentation off, and the tool tells you when the CSS cannot be formatted.
Most importantly for teams: the tool does not integrate with Git. There is no repository connection, no pre-commit hook and no enforcement. It runs in your browser, on CSS you paste into it. The prevention described here comes from the habit, a team agreeing that CSS goes through the formatter before it is committed, not from any automation in the tool.
Common mistakes
- Mixing a format pass with real changes. Reformat a file and change values in the same commit and the diff is unreadable. Separate the two: one commit for layout, one for meaning.
- Letting everyone pick their own indent. The formatter offers 2 or 4 spaces, but a team must pick one. Two indents in rotation recreate the noise the format was meant to remove.
- Expecting the formatter to sort properties. It preserves declaration order exactly, because order matters in the cascade. Alphabetical order has to be written into the source by hand.
- Assuming formatting prevents every conflict. When two people change the same declaration, the conflict is real and needs a decision. Formatting clears away the accidental ones so the real ones get attention.
FAQs
Does the CSS Formatter connect to Git or my repository? No. It runs in your browser: you paste CSS in and copy or download the formatted result. There is no repository integration, no commit hook and no enforcement, so the team still has to agree to format before committing.
Will formatting change how my CSS behaves? No. Formatting changes whitespace and line breaks only, never your selectors or values, and declaration order is preserved exactly because order matters in the cascade.
Why does one small change sometimes show as a whole-file diff? Because the comparison is line by line. If a rule sits on one long line, changing any part of it changes the whole line, and if the layout differs between versions, nearly every line reads as changed even when the values are identical.
Does it sort my properties alphabetically? No. Declaration order is preserved exactly, because order matters in the cascade. If your team wants an alphabetical convention, that ordering belongs in the source, not the formatter.
What CSS can it not handle? Plain CSS only. SCSS nesting and Less variables are not supported, and a missing closing brace can throw the indentation off; the tool tells you when the CSS cannot be formatted.
Conclusion
Merge conflicts in CSS are usually not disagreements about styling. They are accidents of layout, from a line-based tool comparing files whose shapes drifted apart. One shared format, one declaration per line with a consistent indent, turns diffs back into honest records of what changed. The CSS Formatter makes that format a thirty-second step instead of a style debate. Its natural companion is the guide on how to format CSS copied from DevTools, and the rest of the series lives in the Developer Tools guides archive.