🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to CSS Notes
Topic #28

Margin Collapse


CSS Margin Collapse

Margin collapse is when two margins collapse into a single margin.

Top and bottom margins of elements are sometimes collapsed into a single margin that is equal to the largest of the two margins.

Note: Margin collapse only happens with top and bottom margins! Not left and right margins!

In the following example, the

element has a bottom margin of 50px and the

element has a top margin of 20px. So, the vertical margin between the

and the

would be a total of 70px (50px + 20px). But due to margin collapse, the actual margin ends up being 50px:

Example

h1 {
  margin-bottom: 50px;
}

h2 {
  margin-top: 20px;
}

In the following example, each

element has a top margin of 30px and a bottom margin of 30px. So, the vertical margin between the

elements should have been 60px (30px + 30px). However, due to margin collapse, the actual margin ends up being 30px:

Example

  p {
  margin-top: 30px;
  margin-bottom: 30px;
}

All CSS Margin Properties

Property Description
margin A shorthand property for setting all the margin properties in one declaration
margin-bottom Sets the bottom margin of an element
margin-left Sets the left margin of an element
margin-right Sets the right margin of an element
margin-top Sets the top margin of an element

Want to go beyond the notes?

Join CodingNow 2.0's CSS course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Margin Collapse – FAQs

Quick answers about learning Margin Collapse in CSS.

This free note from CodingNow 2.0 explains Margin Collapse in CSS — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every CSS topic on CodingNow 2.0, including Margin Collapse, is 100% free with no signup required.
With focused practice, most students grasp Margin Collapse in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now