<length>
A CSS data type representing a distance value. It consists of a number followed by a unit (like 'px', 'em', 'rem', 'vw', etc.). Lengths fall into two big buckets: absolute units that map to physical sizes, and relative units that resolve based on context (the font, the viewport, the container, the line height).
What's modern
From web-features, MDN's browser data and our snippets, checked dailyClassic, with newer partsIt has worked everywhere since July 2015, and it keeps getting newer values.
rcap unitBaseline Jan 2026rch unitBaseline Jan 2026rex unitBaseline Jan 2026ric unitBaseline Jan 2026cap unitBaseline Dec 2023, Widely Jun 2026lh unitBaseline Nov 2023, Widely May 2026rlh unitBaseline Nov 2023, Widely May 2026Container query length units cqw, cqh, cqi, cqb, cqmin, cqmaxBaseline Feb 2023, Widely Aug 2025
See how modern your own CSS is.Check your CSS →
Quick example
h1 {
/* A few common lengths */
font-size: 2.5rem;
margin-top: 1lh;
width: 50cqi;
min-height: 100dvh;
}All units
Font-relative units
Resolve based on the font of the current element or the root element.
| Unit | Measures | Notes | Baseline |
|---|---|---|---|
em | Current element's font size | Compounds when nested. The most common pitfall: an em on a child resolves against the child's own font-size if it's been set. | Widely |
rem | Root element's font size | Doesn't compound. A common choice for type sizes and spacing. | Widely |
ex | x-height of the current font | Baseline to the top of a lowercase 'x'. If the font has no x-height data, it falls back to 0.5em. | Widely |
rex | x-height of the root font | Root-level version of ex. | Newly (2026) |
cap | Cap height of the current font | Baseline to top of an uppercase letter. Useful for aligning icons to the visual top of text. | Widely |
rcap | Cap height of the root font | Root-level version of cap. | Newly (2026) |
ch | Width of the '0' (zero) character | Best for setting reading-width limits on prose: max-width: 65ch. | Widely |
rch | Width of '0' in the root font | Root-level version of ch. | Newly (2026) |
ic | Advance width of the CJK ideograph 水 | Sizing boxes of Chinese or Japanese text by character count, in horizontal or vertical text. | Widely |
ric | Advance width of CJK 水 in the root font | Root-level version of ic. | Newly (2026) |
lh | Computed line height of the current element | Vertical rhythm tied to type. Resolves to a real pixel value usable for any length. | Widely |
rlh | Computed line height of the root element | Root-level version of lh. | Widely |
Viewport-relative units
Each axis has four variants: the original (vw, vh) plus small (svw, svh), large (lvw, lvh) and dynamic (dvw, dvh) versions that account for mobile browser chrome.
| Unit | Measures | Notes | Baseline |
|---|---|---|---|
vw | 1% of viewport width | Measured against the large viewport, as if mobile browser bars were hidden. | Widely |
vh | 1% of viewport height | Same as vw: sized as if mobile browser bars were hidden, so bars can cover part of a 100vh box. Use svh or dvh for full-screen mobile layouts. | Widely |
vi | 1% of viewport inline axis | Writing-mode aware version of vw. | Widely |
vb | 1% of viewport block axis | Writing-mode aware version of vh. | Widely |
vmin | 1% of the smaller of vw or vh | Useful for sizing that should never exceed the smaller viewport edge. | Widely |
vmax | 1% of the larger of vw or vh | Inverse of vmin. | Widely |
svw / svh / svi / svb | Small viewport (browser chrome visible) | Returns the viewport size with mobile bars showing. Stable, won't jump on scroll. | Widely |
lvw / lvh / lvi / lvb | Large viewport (browser chrome hidden) | Returns the viewport size with mobile bars hidden. | Widely |
dvw / dvh / dvi / dvb | Dynamic viewport, follows chrome state in real time | What you usually want for full-screen mobile elements. The element grows and shrinks with the address bar. | Widely |
svmin / lvmin / dvmin | vmin variants for small / large / dynamic viewport | Same idea as vmin, with mobile-aware viewports. | Widely |
svmax / lvmax / dvmax | vmax variants for small / large / dynamic viewport | Same idea as vmax, with mobile-aware viewports. | Widely |
Container-relative units
Each axis resolves against the nearest ancestor that is a size container on that axis. Without one, they use the small viewport size for that axis.
| Unit | Measures | Notes | Baseline |
|---|---|---|---|
cqw | 1% of query container's width | In horizontal text, needs an ancestor with container-type: inline-size or size. | Widely |
cqh | 1% of query container's height | In horizontal text, needs an ancestor with container-type: size. | Widely |
cqi | 1% of query container's inline size | Writing-mode aware version of cqw. Works with container-type: inline-size or size. | Widely |
cqb | 1% of query container's block size | Writing-mode aware version of cqh. Needs container-type: size. | Widely |
cqmin | 1% of the smaller of cqi or cqb | Container-relative version of vmin. | Widely |
cqmax | 1% of the larger of cqi or cqb | Container-relative version of vmax. | Widely |
Absolute units
Fixed ratios to each other: 1in is 96px. On screens, browsers anchor them to px, so 1cm may not match a real centimeter.
| Unit | Measures | Notes | Baseline |
|---|---|---|---|
px | 1 CSS pixel (1/96 of an inch) | Despite the name, not always one device pixel. The fundamental absolute unit on the web. | Widely |
cm | 1 centimeter (= 96/2.54 px) | Mostly useful for print stylesheets. | Widely |
mm | 1 millimeter (= 1/10 cm) | Print stylesheets. | Widely |
Q | Quarter-millimeter (= 1/40 cm) | Print typography. Rare on the web. | Widely |
in | 1 inch (= 96 px) | Print stylesheets. | Widely |
pt | 1 point (= 1/72 of an inch) | Standard typographic unit in print. | Widely |
pc | 1 pica (= 12 pt, 1/6 of an inch) | Print typography. Rarely seen on the web. | Widely |