Advertisement
Complete Specification Guide

CSS Units Reference Matrix

A definitive handbook covering the relationship between CSS reference pixels, font-relative scales, viewport dimensions, and physical print units.

All CSS Length Units

UnitNameCategoryRelative ToFormula / Screen DefinitionExample
remRoot EmfontRoot font sizepx = rem × rootFontSize1rem
pxPixelabsoluteCSS reference pixelCanonical unit (identity)16px
emEmfontParent/current font sizepx = em × contextFontSize1em
ptPointabsolute1/72 inch (CSS pixel ratio)px = pt × (96 / 72)12pt
pcPicaabsolute12 points = 16pxpx = pc × 161pc
inInchabsolute96 CSS pixelspx = in × 961in
cmCentimeterabsolute96 / 2.54 pixelspx = cm × (96 / 2.54)1cm
mmMillimeterabsolute96 / 25.4 pixelspx = mm × (96 / 25.4)10mm
exx-HeightfontFont's x-height (approx. 0.5 × context)px = ex × (contextFontSize × 0.5)2ex
ch0-WidthfontFont's '0' character widthpx = ch × (contextFontSize × 0.5)20ch
vwViewport WidthviewportViewport widthpx = (vw / 100) × viewportWidth10vw
vhViewport HeightviewportViewport heightpx = (vh / 100) × viewportHeight50vh
vminViewport MinimumviewportSmaller viewport dimensionpx = (vmin / 100) × min(viewportWidth, viewportHeight)10vmin
vmaxViewport MaximumviewportLarger viewport dimensionpx = (vmax / 100) × max(viewportWidth, viewportHeight)10vmax
%PercentagerelativeContext reference valuepx = (% / 100) × referenceValue50%

rem vs. em: The Real Difference

Both units scale dynamically with font sizes, but their reference elements differ significantly:

  • rem (Root Em): Directly proportional to the font size of the root (<html>) element only. It never compounds down the DOM tree. If the root is 16px, 1.5rem is always 24px anywhere in the application.
  • em (Element Em): Relative to the font size of its immediate parent or current element. This causes compounding when nested: 3 levels of 1.5em font sizes will scale by 1.5 × 1.5 × 1.5 = 3.375×!

💡 Rule of thumb: Use rem for layout, spacing, and base font sizes for predictability. Use em when a component (like a button icon or badge) should scale in proportion to its parent text.

Viewport Units (vw, vh, vmin, vmax)

Viewport units represent a percentage of the browser window’s initial containing block:

  • 1vw = 1% of the viewport width. On a 1440px monitor, 10vw = 144px.
  • 1vh = 1% of the viewport height. On a 900px screen, 50vh = 450px.
  • 1vmin = 1% of the smaller dimension. Ideal for square hero elements or mobile responsive bounds.
  • 1vmax = 1% of the larger dimension.

⚠️ Notice: Converting viewport units to pixels requires knowledge of the active viewport resolution. DevCraft asks for this context so your calculations are mathematically exact.

Physical Units & The CSS Reference Pixel

In CSS, units like inches (in), centimeters (cm), millimeters (mm), points (pt), and picas (pc) are strictly mapped to the CSS reference pixel at 96 DPI:

1in = 96px
1cm = 96 / 2.54 px ≈ 37.7953px
1mm = 96 / 25.4 px ≈ 3.7795px
1pt = 96 / 72 px ≈ 1.3333px
1pc = 12pt = 16px

Because monitors have varying pixel densities (retina displays with 200–400 physical hardware pixels per inch), holding a physical ruler up to a screen will not match a CSS centimeter. These units are intended for print media stylesheets (@media print) or fixed coordinate systems.