Why do adjacent vertical margins collapse instead of adding together?
Quick answer
In normal block flow, adjoining vertical margins can collapse into one margin instead of adding together. For two positive margins, the larger one sets the gap, not their sum. This commonly happens between siblings and in certain parent-child cases. Add a border or padding, establish a new block formatting context, or use flex/grid with gap when you want a clearer spacing rule. [S1] [S2]
The question, the details, the next step.
A practical checklist
Confirm the boxes are in normal block flow and the margins are vertical.
Check whether adjacent positive margins are collapsing; the larger value sets the gap.
Inspect parent-child boundaries for padding, borders, content, sizing, or a new block formatting context.
Use flex or grid with
gapfor consistent spacing between items in those layouts.If keeping block flow, assign spacing consistently and check the surrounding markup.
A few more useful answers
Do horizontal margins collapse too?
No. The margin-collapsing behavior described here concerns vertical margins on block boxes in normal flow. [S1]
Will `gap` space ordinary block-flow elements?
The cited guidance documents gap for multi-column, flex, and grid layouts, not ordinary block flow. Use it when the items are in one of those layout modes. [S2]
Does `display: flow-root` stop every margin collapse inside the parent?
It prevents the parent’s margins from collapsing with its children. It does not, by itself, establish that sibling margins inside the parent cannot collapse. [S1]
Sources
References used for this guide.
- [S1] Mastering margin collapsing — CSS | MDN developer.mozilla.org · Checked
- [S2] gap CSS property — CSS | MDN developer.mozilla.org · Checked
