--- id: css-margin-collapse title: "CSS Margin Collapse" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["margin collapse", "collapsing margins", "CSS margin collapsing", "vertical margin collapse", "largest margin wins"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.89 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["css", "web", "frontend", "w3schools", "margin", "box-model"] raw_sources: ["https://www.w3schools.com/css/css_margin_collapse.asp"] applied_in: [] github_commit: "" --- # [[CSS Margin Collapse]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) Top and bottom margins of elements are sometimes collapsed into a single margin that is equal to the largest of the two margins β€” this only happens with top and bottom margins, never left and right. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Definition** β€” top and bottom margins of elements are sometimes collapsed into a single margin that is equal to the largest of the two margins. [S1] - **Largest wins** β€” the resulting single margin equals the larger of the two adjacent margins, not their sum. [S1] - **Vertical only** β€” this does not happen on left and right margins, only top and bottom margins. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **max, not sum** β€” when two vertical margins meet, the gap is `max(margin_a, margin_b)`, not `margin_a + margin_b`. [S1] - **Horizontal exemption** β€” never rely on collapse for left/right spacing; it applies only to top/bottom. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **CSS Margin Collapse** [S1] Top and bottom margins of elements are sometimes collapsed into a single margin that is equal to the largest of the two margins. This does not happen on left and right margins! Only top and bottom margins! [S1] **Example** β€” an `h1` with a bottom margin and an `h2` with a top margin: [S1] ```css h1 { margin: 0 0 50px 0; } h2 { margin: 20px 0 0 0; } ``` The `h1` element has a bottom margin of 50px and the `h2` element has a top margin set to 20px. Common sense would seem to suggest that the vertical margin between the `h1` and the `h2` would be a total of 70px (50px + 20px). But due to margin collapse, the actual margin ends up being 50px. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's own applied example is the `h1`/`h2` stylesheet above, which demonstrates that adjacent 50px and 20px vertical margins collapse to a single 50px gap rather than summing to 70px. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Adjacent vertical margins that collapse to the larger value (language: CSS): ```css h1 { margin: 0 0 50px 0; } h2 { margin: 20px 0 0 0; } ``` ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) No contradictions found in the source. ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual (μ‹€μ œ 적용 사둀 발견 μ‹œ applied/validated둜 승격 κ°€λŠ₯) - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.89 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[CSS Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CSS Margins]], [[CSS Border Sides]], [[CSS Border Shorthand]] - **μ°Έμ‘° λ§₯락:** A box-model gotcha to keep in mind whenever vertical spacing between stacked elements matters. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” CSS Margin Collapse β€” https://www.w3schools.com/css/css_margin_collapse.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "CSS Margin Collapse" page (Astra wiki-curation, P-Reinforce v3.1 format).