margin collapsing
The CSS rule that when two vertical margins of blocks touch, they merge into one margin equal to the larger of the two instead of adding up.
In more detail
A heading with a 24px bottom margin above a paragraph with a 16px top margin leaves 24px between them, not 40px. Flex and grid containers and new block formatting contexts stop their children's margins from collapsing.
Related terms
- margin — Transparent space outside an element's border that pushes neighbouring elements away.
- block formatting context — A self-contained layout region in which blocks are laid out one after another and whose margins do not collapse with anything outside it.
- display: flow-root — A display value that makes an element a normal block which also starts a new block formatting context.
Taught in
- Modern Box Model, Box Sizing, Display Types And Flow Layout — Frontend Architecture & Web Platform