--- id: howto-css-center-vertical title: "How To - Center Elements Vertically" category: "Web_Recipes" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["vertical centering CSS", "transform translateY center"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.84 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["howto", "css", "w3schools", "layout", "centering", "flexbox"] raw_sources: ["https://www.w3schools.com/howto/howto_css_center-vertical.asp"] applied_in: [] github_commit: "" --- # [[HOWTO CSS Center Vertical]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) This page teaches THREE distinct centering techniques and, notably, does NOT declare one universally superior β€” the `position: absolute` + `transform: translate(-50%, -50%)` method centers an element whose OWN size is unknown at author time (the negative-percentage transform shifts it back by exactly half of ITS OWN rendered width/height, computed at runtime), while the third technique (`display: flex; justify-content: center; align-items: center;`) achieves the identical visual result with far less code but requires flex layout on the PARENT rather than absolute positioning on the child β€” two fundamentally different mechanisms (offset math vs. layout algorithm) converging on the same output. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Vertical-only centering** β€” `position: absolute; top: 50%; transform: translateY(-50%);` on a container with `position: relative`. [S1] - **Vertical + horizontal centering (absolute method)** β€” `position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);` β€” the transform shifts the element back by half its OWN width/height, which is why it works regardless of the element's actual size. [S1] - **Flexbox method** β€” `display: flex; justify-content: center; align-items: center;` on the PARENT centers ANY child, both axes, with no transform math at all. [S1] - **`-ms-transform` prefix** β€” included alongside the standard `transform` property for older IE/Edge compatibility. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Vertical-only: `.container { height: 200px; position: relative; } .vertical-center { margin: 0; position: absolute; top: 50%; transform: translateY(-50%); }`. [S1] - Both axes (absolute method): `.center { margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }`. [S1] - Both axes (flexbox method): `.center { display: flex; justify-content: center; align-items: center; height: 200px; }`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) μ—†μŒ β€” μ‹ κ·œ λ ˆμ‹œν”Ό, κΈ°μ‘΄ λ¬Έμ„œμ™€ λͺ¨μˆœλ˜λŠ” λ‚΄μš© μ—†μŒ. ## πŸ› οΈ 적용 사둀 (Applied in summary) 같은 ν…μŠ€νŠΈλ₯Ό μ„Έλ‘œλ§Œ 쀑앙 μ •λ ¬, μ„Έλ‘œ+κ°€λ‘œ 쀑앙 μ •λ ¬(absolute), 그리고 flexbox둜 쀑앙 μ •λ ¬ν•˜λŠ” 3κ°€μ§€ 방식이 μ›λ¬Έμ—μ„œ λ‚˜λž€νžˆ 비ꡐ μ œμ‹œλ¨. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Three centering techniques compared β€” absolute+transform vs. flexbox (CSS): ```css /* Absolute + transform -- works for unknown element size */ .center-absolute { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); } /* Flexbox -- simplest, centers any child on both axes */ .center-flex { display: flex; justify-content: center; align-items: center; height: 200px; } ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference) - **μ‹ λ’° 점수:** 0.84 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[W3Schools HOW TO]] - **κ΄€λ ¨ κ°œλ…:** [[HOWTO CSS Center Button]], [[HOWTO CSS Center List]], [[HOWTO CSS Split Screen]] - **μ°Έμ‘° λ§₯락:** CSS Layout & Positioning μ„Ήμ…˜. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” How To - Center Elements Vertically β€” https://www.w3schools.com/howto/howto_css_center-vertical.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "How To - Center Elements Vertically" recipe (Astra wiki-curation, P-Reinforce v3.1 format).