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

Taught in

References