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
| Sizing | Good default | Why |
|---|---|---|
| Font size | rem | Respects the reader's browser font-size setting. px font sizes do not. |
| Spacing tied to text | em or rem | em makes button padding grow with the button's text. |
| Borders, hairlines | px | Should stay thin when text grows. |
| Reading width | ch | max-width: 65ch follows the font. |
| Full-screen sections | svh or dvh | Plain vh can extend behind mobile browser toolbars. |
| Grid tracks | fr | Shares out free space after fixed tracks. |
| Components inside containers | cqi | Responds 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.
| Unit | Definition | In CSS px | Use |
|---|---|---|---|
| px | Reference pixel, 1/96 in | 1 | Borders and fine details. On high-density screens one CSS pixel covers several device pixels. |
| pt | Point, 1/72 in | 1.333 | Print stylesheets. |
| pc | Pica, 12pt | 16 | Print typography. |
| in | Inch | 96 | Print. |
| cm | Centimeter | 37.795 | Print. |
| mm | Millimeter | 3.780 | Print. |
| Q | Quarter-millimeter | 0.945 | Precise print layout. |
Font-relative units
| em | The 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. |
| rem | The root (html) element's font size. Browsers default to 16px unless the user or your CSS changes it. |
| ex | x-height of the current font, roughly the height of a lowercase x. |
| ch | Advance width of the "0" glyph. In proportional fonts many letters are narrower, so 65ch holds more than 65 characters of typical text. |
| cap | Height of capital letters in the current font. |
| ic | Advance of the CJK water ideograph (水). Useful for East Asian text. |
| lh | The element's computed line height. Good for vertical rhythm: margin-block: 1lh. |
| rlh | The root element's line height. |
| rex, rch, rcap, ric | Root-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 / vh | 1% 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 / vb | 1% of the viewport in the inline or block direction, following writing mode. |
| vmin / vmax | 1% of the smaller or larger viewport dimension. |
| svh / svw | Small viewport, measured with toolbars showing. Stable, and always fits. Also svi, svb, svmin, svmax. |
| lvh / lvw | Large viewport, measured with toolbars hidden. Stable, but can be partly covered. Also lvi, lvb, lvmin, lvmax. |
| dvh / dvw | Dynamic 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 / cqh | 1% of the container's width or height. |
| cqi / cqb | 1% of the container's inline or block size. cqi is the usual choice. |
| cqmin / cqmax | The smaller or larger of cqi and cqb. |
Grid sizing
| fr | A 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-content | Keywords for the narrowest and widest size the content allows. |
Percentages: what they refer to
| Property | % is based on |
|---|---|
| width, left, right | The containing block's width. |
| height, top, bottom | The containing block's height. height: % behaves as auto if the parent's height depends on content. |
| margin, padding | The containing block's width on all four sides, even top and bottom, in horizontal writing modes. |
| font-size | The parent's font size. |
| line-height | The 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 / turn | Angles. 1turn = 360deg = 400grad. |
| s / ms | Time, for transitions and animations. |
| dpi / dpcm / dppx / x | Resolution, mainly in media queries and image-set(). 1dppx = 1x = 96dpi. |
| Hz / kHz | Frequency. Defined in the spec, but no widely used CSS property takes them. |
Recipes
- Readable body text width:
max-width: 65ch - Full-height hero with no jump on mobile:
min-height: 100svh - Panel that tracks the visible area exactly:
height: 100dvh(expect it to resize as toolbars move) - Fluid font size:
font-size: clamp(1rem, 0.5rem + 2vw, 2rem). Keep a rem part in the middle value, because text sized only invwdoes not grow with browser zoom. - Responsive grid:
grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)). Themin()stops overflow on very narrow screens. - Equal-height rows:
grid-auto-rows: 1fr - Square element:
aspect-ratio: 1(same as1 / 1) - Padding that scales with the component's text:
padding: 0.5em 1em - Corner radius that follows font size:
border-radius: 0.5em - Card title that follows card width:
font-size: clamp(1rem, 5cqi, 1.5rem)insidecontainer-type: inline-size
To convert between absolute and root-relative units with your own root font size, use the CSS Unit Converter.
Last updated