CSS size units (px rem em vh)
Prefer rem for UI type scales; use px for hairline borders when you must.
| Unit | Relative to | Typical use |
|---|---|---|
| px | Device pixel (CSS pixel) | Borders, precise icons |
| rem | Root element font-size | Type scale, spacing |
| em | Parent font-size | Component-local sizing |
| % | Parent property | Widths, flexible layouts |
| vw | 1% viewport width | Full-bleed sections |
| vh | 1% viewport height | Hero height (mind mobile UI) |
| vmin / vmax | Smaller/larger viewport side | Square-ish responsive sizing |
| ch | Width of “0” glyph | Code blocks, monospace fields |
| ex | x-height of font | Rare fine typography |
| svh / lvh / dvh | Small/large/dynamic viewport | Mobile browser chrome-safe height |
Notes
- 100vh on mobile can include hidden browser chrome — prefer dvh/svh when supported.
- User font-size settings affect rem — that is usually desirable for a11y.