liveBook · Manning

Collapsing margin

Also called margin collapse, margin collapsing

Collapsing margin is CSS behavior in which adjoining vertical margins combine into a single effective margin rather than being added together.

How 2 Manning books explain it

Acing the Frontend Interview

Margin collapsing is the CSS layout behavior in which adjoining vertical margins combine into a single effective margin instead of being added.

How it is used
Diagnoses unexpected vertical gaps in CSS layouts.
How deep it goes
Explains where vertical margins collapse, the resulting gap, and ways to prevent collapse without exploring browser internals.
Examples
Compares a 50px bottom margin with a 30px top margin to show a 50px gap rather than 80px.
What you can do after
Diagnose/debug unexpected spacing and choose layout rules that prevent unwanted collapse.

Read how Acing the Frontend Interview explains collapsing margin →

CSS in Depth, Second Edition

Margin collapsing is the CSS layout behavior in which adjacent top and bottom margins combine into a single margin whose size is determined by the largest applicable margin.

How it is used
Explains text-block spacing and diagnoses gaps that appear outside containers.
How deep it goes
Works through calculated two-margin and nested three-margin cases, then gives practical ways to prevent unwanted collapse.
Examples
Uses stacked paragraphs, a wrapped paragraph, a header background, and buttons in a padded container.
What you can do after
Diagnose/debug unexpected vertical gaps and choose padding, overflow, or sibling-targeted margins to place spacing where intended.

Read how CSS in Depth, Second Edition explains collapsing margin →

Also covered in

What to know first

Related concepts

Questions about collapsing margin

What is collapsing margin?

Collapsing margin is CSS behavior in which adjoining vertical margins combine into a single effective margin rather than being added together.

Which Manning books explain collapsing margin?

Acing the Frontend Interview and CSS in Depth, Second Edition.

What should I know before learning collapsing margin?

Manning books that teach collapsing margin usually introduce flexbox, padding and rem first.

What is the difference between collapsing margin and padding?

Collapsing margin is CSS behavior in which adjoining vertical margins combine into a single effective margin rather than being added together. Padding is the provision of extra values, characters, bytes, or space around or within data or an element to meet length, boundary, block-size, spacing, or alignment requirements.

What is collapsing margin also called?

Collapsing margin is also called margin collapse or margin collapsing.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.