--- id: css-margins title: "CSS Margins" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["margin", "CSS margins", "margin-top", "margin shorthand", "margin auto centering"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.9 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.asp"] applied_in: [] github_commit: "" --- # [[CSS Margins]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) The CSS margin properties are used to create space around elements, outside of any defined borders β€” set individually per side, with the `margin` shorthand, with `auto` to horizontally center an element, or with `inherit` to take the parent's margin. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Purpose** β€” margins are used to create space around elements, outside of any defined borders. [S1] - **Full control** β€” CSS has properties for specifying the margin for each side of an element: `margin-top`, `margin-right`, `margin-bottom`, `margin-left`. [S1] - **Allowed values:** `auto` β€” the browser calculates the margin; `length` β€” specifies a margin in px, pt, cm, etc.; `%` β€” specifies a margin in % of the width of the containing element; `inherit` β€” specifies that the margin should be inherited from the parent element. [S1] - **Negative values** β€” negative values are allowed. [S1] - **Shorthand** β€” the `margin` property is a shorthand for setting all four margins in one declaration with one to four values. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **One-to-four value box model** β€” `margin` accepts 1/2/3/4 values mapping to all sides / vertical+horizontal / top+horizontal+bottom / clockwise per-side. [S1] - **`margin: auto` centering** β€” set a width and `margin: auto` to horizontally center an element within its container. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **CSS Margins** [S1] The CSS margin properties are used to create space around elements, outside of any defined borders. With CSS, you have full control over the margins. **Margin - Individual Sides** [S1] CSS has properties for specifying the margin for each side of an element: - `margin-top` - `margin-right` - `margin-bottom` - `margin-left` All the margin properties can have the following values: [S1] | Value | Meaning | |-------|---------| | `auto` | The browser calculates the margin | | *length* | Specifies a margin in px, pt, cm, etc. | | `%` | Specifies a margin in % of the width of the containing element | | `inherit` | Specifies that the margin should be inherited from the parent element | **Tip:** Negative values are allowed. [S1] **Example** β€” setting each side individually: [S1] ```css p { margin-top: 100px; margin-bottom: 100px; margin-right: 150px; margin-left: 80px; } ``` **Margin - Shorthand Property** [S1] To shorten the code, it is possible to specify all the margin properties in one property. The `margin` property is a shorthand property for the individual margin properties. The number of values determines which sides they apply to: [S1] - **four values** `margin: 25px 50px 75px 100px;` β€” top 25px, right 50px, bottom 75px, left 100px - **three values** `margin: 25px 50px 75px;` β€” top 25px, right and left 50px, bottom 75px - **two values** `margin: 25px 50px;` β€” top and bottom 25px, right and left 50px - **one value** `margin: 25px;` β€” all four margins 25px **Example** β€” shorthand with four values: [S1] ```css p { margin: 25px 50px 75px 100px; } ``` **The auto Value** [S1] You can set the margin property to `auto` to horizontally center the element within its container. The element will then take up the specified width, and the remaining space will be split equally between the left and right margins. **Example** β€” centering with `auto`: [S1] ```css div { width: 300px; margin: auto; border: 1px solid red; } ``` **The inherit Value** [S1] This example lets the left margin of an element be inherited from the parent element. **Example** β€” inheriting the left margin: [S1] ```css div { border: 1px solid red; margin-left: 100px; } p.ex1 { margin-left: inherit; } ``` ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's own applied examples are the stylesheets above: per-side margins, the four-value shorthand, the `margin: auto` centering rule, and the `inherit` parent/child pair. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Per-side margins (language: CSS): ```css p { margin-top: 100px; margin-bottom: 100px; margin-right: 150px; margin-left: 80px; } ``` Horizontal centering with auto: ```css div { width: 300px; margin: auto; border: 1px solid red; } ``` ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) No contradictions found in the source. ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual (μ‹€μ œ 적용 사둀 발견 μ‹œ applied/validated둜 승격 κ°€λŠ₯) - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.90 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[CSS Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CSS Margin Collapse]], [[CSS Border Shorthand]], [[CSS Border Sides]] - **μ°Έμ‘° λ§₯락:** The outer spacing layer of the CSS box model; paired with borders and padding when laying out elements. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” CSS Margins β€” https://www.w3schools.com/css/css_margin.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "CSS Margins" page (Astra wiki-curation, P-Reinforce v3.1 format).