Skip to content
Private: files never leave your device

CSS Units Cheat Sheet

CSS has more than forty length units, and most bugs with them come from not knowing what each one is measured against. This cheat sheet lists every length unit in CSS Values and Units Level 4, grouped by what it is relative to, with pixel equivalents for the absolute units, the fallback values browsers must use, and the difference between vh, svh, lvh and dvh on phones.

Absolute CSS units are fixed, with 1 inch equal to 96 pixels. em is relative to the font size of the element, rem to the font size of the root element, and vh, svh, lvh and dvh are each 1 percent of a viewport height

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.

UnitNameW3C definitionIn CSS pixels
pxPixel1px = 1/96th of 1in1
inInch1in = 2.54cm = 96px96
cmCentimetre1cm = 96px/2.5437.795
mmMillimetre1mm = 1/10th of 1cm3.780
QQuarter-millimetre1Q = 1/40th of 1cm0.945
ptPoint1pt = 1/72nd of 1in1.333
pcPica1pc = 1/6th of 1in16

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

UnitRelative toFallback the spec requiresRoot version
emThe computed font-size of the element itself (of the parent when used in font-size)None neededrem
exThe x-height of the first available font0.5em if the x-height cannot be foundrex
capThe cap-height of the first available fontThe font ascent if the cap-height cannot be foundrcap
chThe advance of the 0 (zero, U+0030) glyph0.5em wide, or 1em in upright vertical textrch
icThe advance of the CJK water ideograph (U+6C34)1emric
lhThe computed line-height of the elementnormal is converted using the first available fontrlh

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

ElementCSSComputed font size with a 16px root
htmlfont-size: 16px16px
sectionfont-size: 1.5em16 × 1.5 = 24px
p inside sectionfont-size: 1.2em24 × 1.2 = 28.8px
p inside section, using remfont-size: 1.2rem16 × 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:

PrefixMeasured againstStable while scrolling?Typical use
sv* (svh, svw)The small viewport: browser bars assumed shownYesA full-screen block that must never be hidden behind the bars
lv* (lvh, lvw)The large viewport: browser bars assumed hiddenYesBackgrounds that should cover the screen once the bars hide
dv* (dvh, dvw)The dynamic viewport: whatever is visible nowNo, it changes as bars show and hideA layout that exactly fits the visible area
v* (vh, vw)The large viewportYesSame 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.

UnitEqual to
vw, svw, lvw, dvw1% of the viewport width
vh, svh, lvh, dvh1% of the viewport height
vi, svi, lvi, dvi1% of the viewport size in the inline axis (the width in horizontal text)
vb, svb, lvb, dvb1% of the viewport size in the block axis (the height in horizontal text)
vmin and its s, l, d formsThe smaller of the matching vw and vh
vmax and its s, l, d formsThe larger of the matching vw and vh

The W3C example: with a viewport 200mm wide, font-size: 8vw gives 16mm.

Which unit to use

JobGood choiceWhy
Body and heading font sizesremFollows the reader font preference and does not compound
Padding and gaps inside a button or badgeemScales with that element's own text
Readable line lengthch, for example max-width: 65chCounts roughly in characters of the current font
Borders and hairlinespxA fixed, crisp width
Full-height mobile herosvh, or dvh if it must track the barsPlain vh can hide content behind the toolbar
Print style sheetspt, mm, cm, inPhysical 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

PageReadUsed for
W3C: CSS Values and Units Module Level 427 November 2026Definitions of every length unit, fallbacks, absolute equivalences, small, large and dynamic viewports, the vh to lvh mapping
MDN: <length>27 November 2026Common 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.