Reference

CSS units.

Every CSS unit, grouped by what it's measured against. Tap any to copy it.

Tap any row to copy the value in the first column.

Absolute

UnitEqualsNotes
px1 CSS pixelThe everyday absolute unit
pt1/72 inchPrint; common in typography
in96pxInch — print
cm37.8pxCentimetre — print
mm3.78pxMillimetre — print

Font-relative

UnitRelative toNotes
emElement's font sizeCompounds when nested
remRoot (html) font sizeDoesn't compound — preferred
chWidth of the '0' glyphHandy for text column widths
exx-height of the fontRarely used

Viewport-relative

UnitRelative toNotes
vw1% of viewport widthResponsive widths
vh1% of viewport heightFull-height sections
vmin1% of the smaller sideSmallest viewport dimension
vmax1% of the larger sideLargest viewport dimension
%The parent / contextPercentage of the container

Grid, angle & time

UnitMeasuresNotes
frA fraction of free spaceCSS Grid track sizing
degDegreesRotations and gradients
turn1 full turn = 360degRotations
sSecondsAnimations and transitions
msMillisecondsAnimations and transitions

Absolute vs relative

CSS units split into two camps. Absolute units like px are fixed sizes — a pixel is a pixel regardless of context — which makes them predictable but unresponsive. Relative units are measured against something else, which is what makes layouts adapt. The two that matter most for type are em and rem: em is relative to the element's own font size and compounds when you nest elements, while rem is always relative to the root font size, so it stays predictable — which is why rem is the usual choice for scalable typography and spacing. For layout, the viewport units (vw, vh) size things against the screen, and fr distributes leftover space across CSS Grid tracks. A good default is rem for type and spacing, % or fr for layout widths, and px only where a fixed size is genuinely wanted, like a 1px border.

FAQ

What's the difference between em and rem?
em is relative to the font size of the current element and compounds through nesting; rem is relative to the root (html) font size and doesn't compound. rem is usually preferred for consistent, scalable sizing.
When should I use rem instead of px?
Use rem for font sizes, padding and margins so everything scales if the user changes their base font size, improving accessibility. px is fine for things that shouldn't scale, like a hairline border.

More references