Collapsing margin
Collapsing margin is CSS behavior in which adjoining vertical margins combine into a single effective margin rather than being added together.
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
- flexboxFlexbox is a CSS one-dimensional layout model for arranging, sizing, aligning, and distributing items along a row or column.
- paddingPadding 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.
- remThe rem is a CSS relative length unit whose value equals the computed font size of the document’s root element.
Related concepts
- margin propertyuses · The CSS margin property specifies the outer space around an element’s border, separating it from neighboring content.
- overflow propertyaddressed by · The CSS overflow property specifies how content exceeding an element’s box is displayed, clipped, or made scrollable.
- paddingalternative to · 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.
- inline-blockaddressed by · Inline-block is a CSS display value that places an element in inline flow while retaining block-like sizing and layout behavior.
- absolute positioningaddressed by · Absolute positioning is a CSS layout technique that removes an element from normal flow and positions it relative to a containing block, typically established by a positioned ancestor.
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.

