Every CSS unit, explained
CSS has more units than most stylesheets ever touch: lengths, angles, times, resolutions and percentages. This reference groups them by what they measure.
This page covers 60 CSS units across 5 data types. Each section below covers one type: what it represents, the units that belong to it and a link to the full reference page for that type. It leaves out fr, which only works in grid track sizes, and the frequency units Hz and kHz, which no CSS property uses yet.
Convert between units
- 24px
- 1.5rem
- 1.5em
- 18pt
- 150%
- 1.667vw
- 2.667vh
Browsers start the root at 16px unless the reader changes their font size setting, which is why rem respects it and px doesn't. 1pt is 1/72 of an inch and 1px is 1/96, so 1pt is 1.333px.
Which unit should I use?
| For | Use | Why |
|---|---|---|
| Font sizes | rem | Follows the reader's font size setting in the browser; px doesn't. |
| Headings that grow with the screen | clamp() with rem and vw | Grows with the screen between a smallest and a largest size. See how |
| Padding and gaps inside a component | em | Scales with the component's own font size. |
| Spacing between page sections | rem | The same everywhere, and still follows the reader's font size. |
| Readable line length | ch | max-width: 65ch keeps lines near 65 characters. |
| Full-screen sections on phones | svh or dvh | 100vh is sized as if the browser bars were hidden, so the bars can cover part of it. See how |
| Sizes that follow a component's container | cqi | Scales with the container, not the page. See how |
| Line height | a number, like 1.5 | Children inherit the ratio, not a fixed size. |
| Borders and hairlines | px | Exact, and they don't need to scale. |
| Animation and transition times | ms or s | The only time units CSS has. |
| Rotations | deg or turn | turn reads well for whole spins: 0.25turn is 90deg. |
<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).
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 |
<angle>
A basic CSS type for rotation values. It can be expressed in degrees (deg), radians (rad), gradians (grad) or turns (turn).
Angle units
Used for rotations, gradient directions, conic-gradient stops and color hues.
| Unit | Measures | Notes | Baseline |
|---|---|---|---|
deg | Degrees | Most common. A full circle is 360deg. | Widely |
grad | Gradians | A full circle is 400grad. Rare on the web. | Widely |
rad | Radians | A full circle is 2π rad (≈6.2832rad). Useful when porting math from code. | Widely |
turn | Turns | A full circle is 1turn. Best when expressing fractional rotations: 0.25turn = 90deg. | Widely |
<time>
The standard CSS data type for durations. It can be defined in seconds (s) or milliseconds (ms).
Time units
Used for transition and animation durations and delays.
| Unit | Measures | Notes | Baseline |
|---|---|---|---|
s | Seconds | Cleaner for human-readable durations: 0.3s, 1s. | Widely |
ms | Milliseconds | Better when chaining or doing math with JS-derived durations. | Widely |
<resolution>
A CSS data type for pixel density, written with dpi, dpcm, dppx or x. You use it in resolution media queries and image-set() to give higher-quality images only to screens that can show the difference.
Open the <resolution> reference →
Resolution units
Used in the resolution media query and in image-set() to match or describe pixel density.
| Unit | Measures | Notes | Baseline |
|---|---|---|---|
dpi | Dots per inch | Common in print. 96dpi = 1dppx. | Widely |
dpcm | Dots per centimeter | Metric counterpart to dpi. Rarely used. | Widely |
dppx | Dots per CSS pixel | Most useful on the web. 1dppx is standard density. 2dppx is a typical high-density screen. | Widely |
x | Alias for dppx | Shorthand. 2x is the same as 2dppx. | Widely |
<percentage>
A CSS data type representing a value relative to something else (usually the parent element's size or another property's value).
Open the <percentage> reference →
Percentage
A value relative to another value. The reference depends on the property. Width resolves against the containing block's width. Padding on all four sides resolves against the containing block's inline size. Line-height resolves against the element's own font size. Check the property's spec when in doubt.
| Unit | Measures | Notes | Baseline |
|---|---|---|---|
% | Relative to a contextual reference value | What the percentage measures depends on the property: the containing block's width or height, the font size, the line height or something else. | Widely |
Where to go from here
If you're picking up CSS units for the first time, start with rem, % and dvh for layout, and add container query units (cqi, cqb) when you build components that need to scale independently of the page. The article Modern CSS units you should know walks through the most useful new ones with examples.