CSS length units fall into three groups: absolute units such as px, pt and cm, which are fixed to each other (1in = 96px = 2.54cm); font-relative units such as em, rem and ch, which depend on a font size or font metric; and viewport units such as vw, vh, svh, lvh and dvh, which are 1 percent of a viewport dimension. For example, 2rem is twice the root font size, 32px with the common 16px browser default, and 100dvh is the current visible height of the viewport. The definitions were checked on 27 November 2026 against the W3C CSS Values and Units Module Level 4 (the Working Draft dated 12 March 2024 on the W3C TR page) and the MDN length reference.
Absolute units
The spec says the absolute units are fixed in relation to each other and that px is their canonical unit. On screens the pixel is the anchor, so a CSS centimetre on a monitor is often not a real centimetre; in print the physical units are the anchor.
| Unit | Name | W3C definition | In CSS pixels |
|---|---|---|---|
px | Pixel | 1px = 1/96th of 1in | 1 |
in | Inch | 1in = 2.54cm = 96px | 96 |
cm | Centimetre | 1cm = 96px/2.54 | 37.795 |
mm | Millimetre | 1mm = 1/10th of 1cm | 3.780 |
Q | Quarter-millimetre | 1Q = 1/40th of 1cm | 0.945 |
pt | Point | 1pt = 1/72nd of 1in | 1.333 |
pc | Pica | 1pc = 1/6th of 1in | 16 |
The pixel values in the last column were calculated from the W3C equivalences and rounded to three decimals. So 12pt is exactly 16px, and the spec notes that a print length like 2 picas 3 points can be written as calc(2pc + 3pt). For turning print sizes into image pixels at a given DPI, which is a different question, see paper sizes in pixels.
Font-relative units
| Unit | Relative to | Fallback the spec requires | Root version |
|---|---|---|---|
em | The computed font-size of the element itself (of the parent when used in font-size) | None needed | rem |
ex | The x-height of the first available font | 0.5em if the x-height cannot be found | rex |
cap | The cap-height of the first available font | The font ascent if the cap-height cannot be found | rcap |
ch | The advance of the 0 (zero, U+0030) glyph | 0.5em wide, or 1em in upright vertical text | rch |
ic | The advance of the CJK water ideograph (U+6C34) | 1em | ric |
lh | The computed line-height of the element | normal is converted using the first available font | rlh |
Each root version (rem, rex, rcap, rch, ric, rlh) is the same measurement taken on the root element, usually <html>. MDN notes that a common browser default root font size is 16px, but that user preferences can change it, which is the main reason to size text in rem: a reader who sets a larger default font gets larger text everywhere.
Worked example: why em compounds and rem does not
| Element | CSS | Computed font size with a 16px root |
|---|---|---|
| html | font-size: 16px | 16px |
| section | font-size: 1.5em | 16 × 1.5 = 24px |
| p inside section | font-size: 1.2em | 24 × 1.2 = 28.8px |
| p inside section, using rem | font-size: 1.2rem | 16 × 1.2 = 19.2px |
Because em in font-size is taken from the parent, nested elements multiply. The same 1.2em rule gives a different size at every level of nesting, while 1.2rem always gives 19.2px here. When em is used for anything other than font-size, such as padding, the W3C example shows it is measured against the element's own font size, so padding: 1em grows with the text of that element, which is often exactly what you want for buttons.
Viewport units: vh, svh, lvh and dvh
Phone browsers show and hide their address bar and toolbars as you scroll, so there is more than one viewport height. Level 4 defines three, and every viewport unit comes in a small, large and dynamic form:
| Prefix | Measured against | Stable while scrolling? | Typical use |
|---|---|---|---|
sv* (svh, svw) | The small viewport: browser bars assumed shown | Yes | A full-screen block that must never be hidden behind the bars |
lv* (lvh, lvw) | The large viewport: browser bars assumed hidden | Yes | Backgrounds that should cover the screen once the bars hide |
dv* (dvh, dvw) | The dynamic viewport: whatever is visible now | No, it changes as bars show and hide | A layout that exactly fits the visible area |
v* (vh, vw) | The large viewport | Yes | Same as lv*; the spec says this mapping is presumed required for web compatibility |
That last row is why height: 100vh on a phone can push the bottom of a page behind the toolbar: plain vh equals lvh, the size with the bars hidden. The spec calls the small units safer in general, and warns that dynamic units can make content resize while the user scrolls, which can be disturbing and costly in performance.
| Unit | Equal to |
|---|---|
vw, svw, lvw, dvw | 1% of the viewport width |
vh, svh, lvh, dvh | 1% of the viewport height |
vi, svi, lvi, dvi | 1% of the viewport size in the inline axis (the width in horizontal text) |
vb, svb, lvb, dvb | 1% of the viewport size in the block axis (the height in horizontal text) |
vmin and its s, l, d forms | The smaller of the matching vw and vh |
vmax and its s, l, d forms | The larger of the matching vw and vh |
The W3C example: with a viewport 200mm wide, font-size: 8vw gives 16mm.
Which unit to use
| Job | Good choice | Why |
|---|---|---|
| Body and heading font sizes | rem | Follows the reader font preference and does not compound |
| Padding and gaps inside a button or badge | em | Scales with that element's own text |
| Readable line length | ch, for example max-width: 65ch | Counts roughly in characters of the current font |
| Borders and hairlines | px | A fixed, crisp width |
| Full-height mobile hero | svh, or dvh if it must track the bars | Plain vh can hide content behind the toolbar |
| Print style sheets | pt, mm, cm, in | Physical units are the anchor in print |
For animation timing units such as s and ms, see our CSS Keyframe Builder; for colour values, use the Color Converter. Other developer charts on this site include the ASCII table and the HTML entities list.
Sources and dates
| Page | Read | Used for |
|---|---|---|
| W3C: CSS Values and Units Module Level 4 | 27 November 2026 | Definitions of every length unit, fallbacks, absolute equivalences, small, large and dynamic viewports, the vh to lvh mapping |
| MDN: <length> | 27 November 2026 | Common 16px browser default root font size, changed by user preferences |
Frequently asked questions
What is the difference between em and rem?
em is relative to the font size of the element, or of its parent when used in font-size, so it compounds when elements are nested. rem is always relative to the root element font size, commonly 16px by default, so 1.5rem is the same size everywhere on the page.
What is the difference between vh and dvh?
vh is 1 percent of the large viewport, the height with phone browser bars hidden, so 100vh can be taller than the visible area. dvh is 1 percent of the height that is visible right now, and changes as the bars show and hide.
How many pixels is 1rem?
1rem equals the root font size. With the common browser default of 16px, 1rem is 16px, but if the user or your CSS changes the root font size, 1rem changes with it.
How many pixels is 1pt in CSS?
In CSS 1pt is 1/72 of an inch and 1in is 96px, so 1pt is 96/72, about 1.333px. 12pt is exactly 16px.
What does the ch unit measure?
ch is the width of the 0 (zero) character in the current font. It is exact in monospace fonts and an approximation in others, and falls back to 0.5em when the width cannot be measured.