--- id: css-relative-units title: "CSS Relative Units" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["CSS relative units", "em rem", "viewport units", "vw vh", "scalable units"] 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", "units", "relative", "responsive"] raw_sources: ["https://www.w3schools.com/css/css_units_relative.asp"] applied_in: [] github_commit: "" --- # [[CSS Relative Units]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) Relative units specify a length relative to another length property β€” a parent element, the root element, or the viewport β€” so they scale better across different screen sizes, making `em` and `rem` ideal for scalable, responsive websites. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Relative to another length** β€” relative units specify a length relative to another length property (parent element, root element, or viewport). [S1] - **Better scaling** β€” relative length units scale better between different screen sizes. [S1] - **`em`** β€” relative to the font-size of the parent element. [S1] - **`rem`** β€” relative to the font-size of the root HTML element. [S1] - **Viewport units** β€” `vw`/`vh` are relative to 1% of viewport width/height (100vw = full width, 100vh = full height); `vmin`/`vmax` to 1% of the viewport's smaller/larger dimension. [S1] - **`%`, `fr`, `ch`** β€” `%` is relative to the parent's size; `fr` is a fractional unit (1fr = 1 part of available space); `ch` is relative to the width of the "0" (zero) character. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **`em` chains to the parent** β€” child sizes multiply against the parent's font-size, so nested `em` values compound. [S1] - **`rem` anchors to the root** β€” `rem` always references the root element, giving consistent sizing independent of nesting. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **Relative Units** Relative units specify a length relative to another length property (like parent element, root element, or viewport). Relative length units scale better between different screen sizes. [S1] | Unit | Description | | --- | --- | | `em` | Relative to the font-size of the parent element [S1] | | `rem` | Relative to the font-size of the root HTML element [S1] | | `vw` | Relative to 1% of the width of the viewport; 100vw = full width [S1] | | `vh` | Relative to 1% of the height of the viewport; 100vh = full height [S1] | | `vmin` | Relative to 1% of the viewport's smaller dimension [S1] | | `vmax` | Relative to 1% of the viewport's larger dimension [S1] | | `%` | Relative to the size of the parent element [S1] | | `fr` | A fractional unit; 1fr equals 1 part of the available space [S1] | | `ch` | Relative to the width of the "0" (zero) character [S1] | **Em Font Sizing** Set font sizes with `em` (relative to the parent's font-size; with a 16px base, 2.5em = 40px): [S1] ```css body { font-size: 16px; /* Base font size */ } h1 { font-size: 2.5em; /* 2.5 * 16 = 40px */ } h2 { font-size: 1.875em; /* 1.875 * 16 = 30px */ } p { font-size: 1em; /* 1 * 16 = 16px */ } ``` **Rem Font Sizing** Set font sizes with `rem` (relative to the root element rather than the parent, giving more consistent results): [S1] ```css html { font-size: 16px; /* Set the root font size */ } h1 { font-size: 2.5rem; /* 2.5 * 16 = 40px */ } h2 { font-size: 1.875rem; /* 1.875 * 16 = 30px */ } p { font-size: 1rem; /* 1 * 16 = 16px */ } ``` **Tip:** The `em` and `rem` units are perfect for creating scalable and responsive websites! [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's applied cases are the `em` and `rem` font-sizing examples, each computing `h1`/`h2`/`p` sizes from a 16px base. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) em sizing relative to parent (language: CSS): ```css body { font-size: 16px; } h1 { font-size: 2.5em; } /* 40px */ ``` rem sizing relative to root (language: CSS): ```css html { font-size: 16px; } h1 { font-size: 2.5rem; } /* 40px */ ``` ## βš–οΈ 비ꡐ 및 선택 κΈ°μ€€ (Comparison & decision criteria) - **`em`** β€” relative to the parent element's font-size, so nested values compound; use when sizing should respond to the local context. [S1] - **`rem`** β€” relative to the root element's font-size, giving consistent results regardless of nesting; use for predictable global scaling. [S1] - **Viewport units (`vw`/`vh`/`vmin`/`vmax`)** β€” size relative to the viewport for full-screen-aware 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.88 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[CSS Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CSS Units]], [[CSS Absolute Units]], [[CSS Font Size]] - **μ°Έμ‘° λ§₯락:** Referenced when building scalable, responsive sizing that adapts to parent, root, or viewport. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” CSS Relative Units β€” https://www.w3schools.com/css/css_units_relative.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "CSS Relative Units" page (Astra wiki-curation, P-Reinforce v3.1 format).