CSS Units Reference

What each unit is relative to, and which one to choose.

By BoltQuickTools team · Updated November 8, 2026

Which unit to use

SizingGood defaultWhy
Font sizeremRespects the reader's browser font-size setting. px font sizes do not.
Spacing tied to textem or remem makes button padding grow with the button's text.
Borders, hairlinespxShould stay thin when text grows.
Reading widthchmax-width: 65ch follows the font.
Full-screen sectionssvh or dvhPlain vh can extend behind mobile browser toolbars.
Grid tracksfrShares out free space after fixed tracks.
Components inside containerscqiResponds to the container, not the window.

Absolute units

These have fixed ratios to each other and do not respond to font settings. Browser zoom still scales them. On screens, CSS anchors 1in to 96 CSS pixels, so a CSS inch will not usually measure one real inch with a ruler. Physical units are only dependable in print.

UnitDefinitionIn CSS pxUse
pxReference pixel, 1/96 in1Borders and fine details. On high-density screens one CSS pixel covers several device pixels.
ptPoint, 1/72 in1.333Print stylesheets.
pcPica, 12pt16Print typography.
inInch96Print.
cmCentimeter37.795Print.
mmMillimeter3.780Print.
QQuarter-millimeter0.945Precise print layout.

Font-relative units

emThe element's own computed font-size. On the font-size property itself, it refers to the parent's font size. That is why nested font-size: 1.2em compounds at each level.
remThe root (html) element's font size. Browsers default to 16px unless the user or your CSS changes it.
exx-height of the current font, roughly the height of a lowercase x.
chAdvance width of the "0" glyph. In proportional fonts many letters are narrower, so 65ch holds more than 65 characters of typical text.
capHeight of capital letters in the current font.
icAdvance of the CJK water ideograph (水). Useful for East Asian text.
lhThe element's computed line height. Good for vertical rhythm: margin-block: 1lh.
rlhThe root element's line height.
rex, rch, rcap, ricRoot-based forms of ex, ch, cap and ic. Newer, so check browser support.

In media queries, em and rem are based on the browser's initial font size, not on your html { font-size } rule.

Viewport units

Mobile browsers show and hide toolbars while you scroll, so "viewport height" has more than one possible value. The small, large and dynamic variants let you say which you mean.

vw / vh1% of viewport width or height. On mobile, vh generally matches the large viewport, so 100vh can be taller than the visible area while toolbars are showing.
vi / vb1% of the viewport in the inline or block direction, following writing mode.
vmin / vmax1% of the smaller or larger viewport dimension.
svh / svwSmall viewport, measured with toolbars showing. Stable, and always fits. Also svi, svb, svmin, svmax.
lvh / lvwLarge viewport, measured with toolbars hidden. Stable, but can be partly covered. Also lvi, lvb, lvmin, lvmax.
dvh / dvwDynamic viewport. Changes as toolbars move, which can cause layout shifts during scrolling. Also dvi, dvb, dvmin, dvmax.

Scrollbars: 100vw includes a classic vertical scrollbar, so a full-width element sized with it can cause horizontal overflow. width: 100% avoids that.

Container query units

Relative to the nearest ancestor that has container-type set. With no such ancestor, they fall back to the small viewport size.

cqw / cqh1% of the container's width or height.
cqi / cqb1% of the container's inline or block size. cqi is the usual choice.
cqmin / cqmaxThe smaller or larger of cqi and cqb.

Grid sizing

frA share of the free space left after fixed tracks and gaps. 1fr 2fr splits it 1:2. Valid only in grid track sizes.
minmax(min, max)A function, not a unit. minmax(200px, 1fr) sets a track's limits.
fit-content(limit)A function. Sizes to content, up to the limit.
min-content / max-contentKeywords for the narrowest and widest size the content allows.

Percentages: what they refer to

Property% is based on
width, left, rightThe containing block's width.
height, top, bottomThe containing block's height. height: % behaves as auto if the parent's height depends on content.
margin, paddingThe containing block's width on all four sides, even top and bottom, in horizontal writing modes.
font-sizeThe parent's font size.
line-heightThe element's font size, computed once and then inherited as a fixed length. A unitless value avoids this.
transform: translate()The element's own box.

Non-length units

deg / rad / grad / turnAngles. 1turn = 360deg = 400grad.
s / msTime, for transitions and animations.
dpi / dpcm / dppx / xResolution, mainly in media queries and image-set(). 1dppx = 1x = 96dpi.
Hz / kHzFrequency. Defined in the spec, but no widely used CSS property takes them.

Recipes

To convert between absolute and root-relative units with your own root font size, use the CSS Unit Converter.

Last updated