CSS size units (px rem em vh)

Prefer rem for UI type scales; use px for hairline borders when you must.

Updated:

UnitRelative toTypical use
pxDevice pixel (CSS pixel)Borders, precise icons
remRoot element font-sizeType scale, spacing
emParent font-sizeComponent-local sizing
%Parent propertyWidths, flexible layouts
vw1% viewport widthFull-bleed sections
vh1% viewport heightHero height (mind mobile UI)
vmin / vmaxSmaller/larger viewport sideSquare-ish responsive sizing
chWidth of “0” glyphCode blocks, monospace fields
exx-height of fontRare fine typography
svh / lvh / dvhSmall/large/dynamic viewportMobile browser chrome-safe height

Notes