Skip to main content

CSS Units Reference Guide

Complete reference for all CSS units (px, em, rem, vw, vh, %, pt, and more). Includes type, description, best use cases, and interactive converter.

100% client-side - your data never leaves your browser.

Absolute Units

UnitDescriptionExampleWhen to use
pxPixels. 1px = 1/96th of an inch on screen. Most common absolute unit.font-size: 16pxBorders, shadows, precise fixed sizes. Avoid for font sizes and layout (prefer rem).
ptPoints. 1pt = 1/72nd of an inch. Common in print.font-size: 12ptPrint stylesheets only. Avoid on screen.
cmCentimeters. 1cm = ~37.8px.margin: 1cmPrint layouts.
mmMillimeters. 1mm = ~3.78px.border: 1mm solidPrint layouts.
inInches. 1in = 96px on screen.width: 8.5inPrint page sizes (letter, A4).
pcPicas. 1pc = 12pt = 1/6th inch.margin: 1pcTraditional typographic unit. Rarely used.

Relative Font Units

UnitDescriptionExampleWhen to use
emRelative to the font-size of the element (or parent if used in font-size). Compounds with nesting.padding: 1.5emSpacing proportional to the element font size (padding, margin on components). Beware nesting.
remRelative to the root (<html>) font-size. Does not compound. Default root = 16px.font-size: 1.25remFont sizes, spacing. Preferred over em for consistency across components.
exRelative to x-height (lowercase letter height) of the current font.line-height: 2exFine typographic adjustments. Rarely used.
chRelative to the width of the "0" glyph in the current font.max-width: 60chOptimal line length for readability (50-75ch is ideal for body text).
lhRelative to the line-height of the element.margin-top: 1lhSpacing that aligns with the text rhythm.

Viewport Units

UnitDescriptionExampleWhen to use
vw1% of the viewport width.width: 50vwFull-width sections, responsive typography. Beware horizontal scrollbar affecting vw.
vh1% of the viewport height.height: 100vhFull-screen sections. Can be unreliable on mobile (address bar).
vmin1% of the smaller viewport dimension (width or height).font-size: 5vminElements that must fit in both orientations.
vmax1% of the larger viewport dimension.width: 50vmaxRarely used. Square elements that scale with viewport.
svwSmall viewport width - excludes mobile browser UI.width: 100svwMobile layouts where the address bar changes height.
svhSmall viewport height - excludes mobile browser UI (address bar shown).min-height: 100svhSafe full-height on mobile with browser chrome visible.
dvwDynamic viewport width - updates as browser UI shows/hides.width: 100dvwWhen you need the exact current viewport with live browser chrome changes.
dvhDynamic viewport height - updates as browser UI changes.height: 100dvhMost accurate full-height on mobile. May cause layout shifts when scrolling.
lvwLarge viewport width - assumes browser UI is hidden.max-width: 100lvwWhen designing for the maximum possible viewport.
lvhLarge viewport height - assumes browser UI is hidden.height: 100lvhMaximum possible height (browser chrome hidden).

Container Query Units

UnitDescriptionExampleWhen to use
cqw1% of the query container width. Requires container-type on ancestor.font-size: 5cqwComponent-level responsive design. Scales with container, not viewport.
cqh1% of the query container height.height: 50cqhContainer height-relative sizing. Container must have a defined height.
cqi1% of the container inline size (usually width).padding: 2cqiWriting-mode agnostic container width.
cqb1% of the container block size (usually height).margin: 1cqbWriting-mode agnostic container height.

Flexible Units

UnitDescriptionExampleWhen to use
frFraction of remaining free space in a grid container. Only valid in grid-template-* and grid contexts.grid-template-columns: 1fr 2fr 1frCSS Grid column and row sizing. Distributes leftover space proportionally.
%Percentage of the parent element dimension (width, font-size, etc). Context-sensitive.width: 50%Fluid layouts. Relative to parent dimension. Use carefully (behavior differs per property).

Want automated scanning?

SCOUTb2 runs 25+ accessibility, performance, SEO, and security checks on any page automatically.

Install SCOUTb2 Free