--- id: css-padding-and-box-sizing title: "CSS Padding and Box Sizing" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["padding box sizing", "box-sizing border-box", "padding width", "border-box", "content-box"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.88 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["css", "web", "frontend", "w3schools", "padding", "box-sizing", "box-model"] raw_sources: ["https://www.w3schools.com/css/css_padding_box-sizing.asp"] applied_in: [] github_commit: "" --- # [[CSS Padding and Box Sizing]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) The `width` property sets only the content area, so padding adds to the total rendered width β€” unless `box-sizing: border-box` makes the declared width include padding and border. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Width is content-only by default** β€” the CSS `width` property specifies the width of the content area; padding applied to an element with a defined width extends the total element width beyond that value. [S1] - **The `box-sizing` property** β€” controls how width and height calculations include or exclude padding and borders. [S1] - **`content-box` (default)** β€” width and height include only the content; padding and borders are added separately. [S1] - **`border-box`** β€” width and height include content, padding, and border together. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Unexpected widening** β€” adding padding to a fixed-`width` element grows its total size, which is often undesirable. [S1] - **Predictable sizing with `border-box`** β€” set `box-sizing: border-box` so the declared width is preserved and padding eats into the content space instead of expanding the box. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **Padding and element width** The CSS `width` property specifies only the width of the content area. When padding is applied to an element with a defined width, the padding extends the total element width beyond the specified value. [S1] For example: [S1] ```css div { width: 300px; padding: 25px; } ``` Here the actual rendered width becomes `350px` (300px content + 25px left padding + 25px right padding), which is often undesirable. [S1] **Solution: the `box-sizing` property** The `box-sizing` property controls how the width and height of an element are calculated with respect to padding and borders. It accepts two primary values: [S1] - `content-box` (default): width and height include only the content; padding and borders are added separately. - `border-box`: width and height include the content, padding, and border together. Recommended example: [S1] ```css div { width: 300px; padding: 25px; box-sizing: border-box; } ``` With `border-box`, the element keeps exactly `300px` width; increasing padding reduces the available content space rather than expanding the total width. [S1] **Related padding properties** The page includes a reference table of five padding properties: `padding` (shorthand), `padding-bottom`, `padding-left`, `padding-right`, and `padding-top`. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) The two `div` examples are the page's own applied cases: the first shows the widening problem; the second fixes it with `box-sizing: border-box`. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Keep a fixed footprint while still using padding (language: CSS): ```css div { width: 300px; padding: 25px; box-sizing: border-box; } ``` ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) No contradictions found in the source. ## βš–οΈ 비ꡐ 및 선택 κΈ°μ€€ (Comparison & decision criteria) - **`content-box` (default)** β€” choose when you want `width` to mean strictly the content area and you intend to add padding/border on top of it. [S1] - **`border-box`** β€” choose when you want the declared `width`/`height` to remain the element's total footprint regardless of padding and border; padding then reduces inner content space instead of enlarging the box. [S1] ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual (μ‹€μ œ 적용 사둀 발견 μ‹œ applied/validated둜 승격 κ°€λŠ₯) - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.88 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[CSS Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CSS Padding]], [[CSS Box Model]], [[CSS Height and Width]] - **μ°Έμ‘° λ§₯락:** Referenced when fixed-width layouts must stay predictable despite added padding. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” CSS Padding and Box Sizing β€” https://www.w3schools.com/css/css_padding_box-sizing.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "CSS Padding and Box Sizing" page (Astra wiki-curation, P-Reinforce v3.1 format).