--- id: css-box-sizing title: "CSS Box Sizing" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["box-sizing", "border-box", "content-box", "CSS box model sizing", "include padding border in width"] 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", "box-model", "layout"] raw_sources: ["https://www.w3schools.com/css/css3_box-sizing.asp"] applied_in: [] github_commit: "" --- # [[CSS Box Sizing]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) The `box-sizing` property controls whether an element's declared width/height include its padding and border, and setting it to `border-box` makes sizing predictable so padded boxes don't grow larger than intended. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Default behavior** β€” by default, an element's actual rendered width and height include the padding and border *added on top of* the specified `width`/`height`. [S1] - **The sizing formula (default)** β€” `width + padding + border = actual width of an element`, and `height + padding + border = actual height of an element`. [S1] - **The problem** β€” two divs with identical `width: 300px` / `height: 100px` appear different sizes if one has padding; the padded one is larger. [S1] - **The fix** β€” `box-sizing` lets you include padding and borders within the total declared width/height. [S1] - **Recommended default** β€” applying `box-sizing: border-box` to all elements via `*` makes layout sizing consistent. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **border-box pattern** β€” set `box-sizing: border-box;` so the declared width/height *contain* padding and border instead of being added to them. [S1] - **Universal reset pattern** β€” `* { box-sizing: border-box; }` applies predictable sizing to every element. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) By default, the actual width and height of an element include the padding and borders added to the specified dimensions: [S1] - `width + padding + border = actual width of an element` [S1] - `height + padding + border = actual height of an element` [S1] This means two divs given the same `width` (300px) and `height` (100px) can appear different β€” the one with 50px padding is larger because the padding is added to the specified width/height. The `box-sizing` property solves this by allowing padding and borders to be included in the total width/height calculation. [S1] **Example 1 β€” without `box-sizing` (the problem)** [S1] ```css .div1 { width: 300px; height: 100px; border: 1px solid blue; } .div2 { width: 300px; height: 100px; padding: 50px; border: 1px solid red; } ``` **Example 2 β€” with `box-sizing: border-box` (the solution)** [S1] ```css .div1 { width: 300px; height: 100px; border: 1px solid blue; box-sizing: border-box; } .div2 { width: 300px; height: 100px; padding: 50px; border: 1px solid red; box-sizing: border-box; } ``` **Example 3 β€” recommended universal application** [S1] ```css * { box-sizing: border-box; } ``` **Property reference** [S1] | Property | Description | |----------|-------------| | `box-sizing` | Defines how the width and height of an element are calculated: should they include padding and borders, or not | ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's applied examples contrast `.div1` and `.div2` first without `box-sizing` (they render at different sizes) and then with `box-sizing: border-box` (they render identically), and finally recommend the `* { box-sizing: border-box; }` universal reset. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Predictable element sizing (language: CSS): ```css .box { width: 300px; height: 100px; padding: 50px; border: 1px solid red; box-sizing: border-box; } ``` Universal reset (language: CSS): ```css * { box-sizing: border-box; } ``` ## βš–οΈ 비ꡐ 및 선택 κΈ°μ€€ (Comparison & decision criteria) - **Default (content-box) sizing** β€” `width`/`height` describe only the content area; padding and border are added on top, so the rendered box is larger than the declared size. Use when you specifically want the content area to be a fixed size. [S1] - **`border-box` sizing** β€” padding and border are included within the declared `width`/`height`, so a `300px` box stays `300px` regardless of padding. The page recommends this (including applying it to all elements via `*`) for predictable layouts. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (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 Box Model]], [[CSS Padding]], [[CSS Border]], [[CSS Width and Max-width]] - **μ°Έμ‘° λ§₯락:** Referenced whenever layout sizing must stay predictable across elements that carry padding or borders. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” CSS Box Sizing β€” https://www.w3schools.com/css/css3_box-sizing.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "CSS Box Sizing" page (Astra wiki-curation, P-Reinforce v3.1 format).