--- id: howto-css-aspect-ratio title: "How To - CSS Aspect Ratio" category: "Web_Recipes" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["padding-top aspect ratio hack", "aspect-ratio property"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.83 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["howto", "css", "w3schools", "layout", "responsive"] raw_sources: ["https://www.w3schools.com/howto/howto_css_aspect_ratio.asp"] applied_in: [] github_commit: "" --- # [[HOWTO CSS Aspect Ratio]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) The classic aspect-ratio hack exploits a CSS quirk that trips up many developers the first time they see it: percentage `padding-top` on a block element is calculated relative to the PARENT'S WIDTH, not its own height β€” which is precisely why `padding-top: 56.25%` (9Γ·16) produces a perfect 16:9 box regardless of how wide the container actually is, before the modern `aspect-ratio` property existed to make the intent explicit and readable. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Percentage `padding-top` hack** β€” `padding-top: X%` on a full-width block is computed against the element's OWN WIDTH (since padding percentages always resolve against the containing block's width), so setting it to a ratio-derived percentage locks the height to a fixed proportion of the width. [S1] - **Ratio-to-percentage formulas**: 1:1 β†’ 100%; 16:9 β†’ 56.25% (9Γ·16); 4:3 β†’ 75% (3Γ·4); 3:2 β†’ 66.66% (2Γ·3); 8:5 β†’ 62.5% (5Γ·8). [S1] - **`position: relative` + absolutely-positioned child** β€” needed if text/content must sit inside the ratio-locked box, since the box itself has no "real" height from content. [S1] - **Modern `aspect-ratio` property** β€” `aspect-ratio: 3 / 2;` directly expresses the same intent in newer browsers (support from roughly Chrome 88 / Firefox 89 / Safari 15 / Edge 88), no padding math required. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - 1:1 box: `.container { width: 100%; padding-top: 100%; position: relative; }`. [S1] - Text inside a ratio-locked box: `.text { position: absolute; top: 0; left: 0; bottom: 0; right: 0; }`. [S1] - Modern equivalent: `.container { aspect-ratio: 3 / 2; }`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) μ—†μŒ β€” μ‹ κ·œ λ ˆμ‹œν”Ό, κΈ°μ‘΄ λ¬Έμ„œμ™€ λͺ¨μˆœλ˜λŠ” λ‚΄μš© μ—†μŒ. ## πŸ› οΈ 적용 사둀 (Applied in summary) 16:9, 4:3, 3:2, 8:5 λ“± μ—¬λŸ¬ λΉ„μœ¨μ„ padding-top λ°±λΆ„μœ¨λ‘œ κ΅¬ν˜„ν•˜λŠ” μ˜ˆμ œλ“€μ΄ μ›λ¬Έμ—μ„œ 직접 λ‚˜λž€νžˆ μ œμ‹œλ¨. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Legacy padding-top hack vs. modern aspect-ratio property (CSS): ```css /* Legacy hack -- 16:9 */ .container-legacy { width: 100%; padding-top: 56.25%; /* 9 / 16 */ position: relative; } /* Modern equivalent */ .container-modern { aspect-ratio: 16 / 9; } ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference) - **μ‹ λ’° 점수:** 0.83 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[W3Schools HOW TO]] - **κ΄€λ ¨ κ°œλ…:** [[HOWTO CSS Fullscreen Video]], [[HOWTO CSS Image Responsive]] - **μ°Έμ‘° λ§₯락:** CSS Layout & Positioning μ„Ήμ…˜. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” How To - Aspect Ratio β€” https://www.w3schools.com/howto/howto_css_aspect_ratio.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "How To - Aspect Ratio" recipe (Astra wiki-curation, P-Reinforce v3.1 format).