CSS Units Reference

All CSS length, angle, time, frequency and resolution units with a live converter

Searchable CSS units reference covering absolute, font-relative, viewport, container, angle, time and resolution units, with a live px to rem, em, pt and viewport-percentage converter. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

What is the difference between em and rem?

rem is always relative to the root (html) font-size, so it stays predictable across the document. em is relative to the element's own font-size, or to the parent's font-size when used on the font-size property itself, which means ems can compound through nested elements.

CSS keeps adding units — viewport, container, and the small/large/dynamic viewport variants — and the relative ones depend on context that is easy to get wrong. This reference lists every common unit with its basis and includes a live converter for the length units you switch between most.

How it works

The converter takes a px length plus the values that the relative units depend on: the root font-size for rem, the element font-size for em, and the viewport size for vw and vh. It divides accordingly and also derives the print units using CSS’s fixed anchor of 1in = 96px (so 1pt = 96/72 px and 1cm = 96/2.54 px). The reference table tags each unit by type and explains its basis; the search box matches the unit, type, description, and basis.

Unit categories explained

Absolute units

Absolute units (px, pt, in, cm, mm, pc) do not change with context. On screens, CSS anchors 1in to exactly 96px and derives the rest from there — so 1pt = 1.333px, 1cm = 37.8px. This means they match a physical ruler only in print; on screen they are just predictable fractions of a pixel grid. The main use case for absolute units is print stylesheets where physical dimensions genuinely matter.

Font-relative units

rem and em are the workhorses of scalable design:

UnitResolves against
remThe root html font-size (usually 16px by default)
emThe element’s own font-size; on the font-size property itself, the parent’s value
chThe width of the 0 glyph in the current font
exThe x-height of the current font
lhThe computed line-height of the element

The key difference: em values compound through nesting. A paragraph inside a 0.8em-sized section inside another 0.8em section renders at 0.64em of the root — which can produce surprising results. rem always refers back to the root, so it never compounds.

Viewport units and the mobile address-bar problem

The original vw and vh measure the layout viewport — the full browser window including any toolbars. On mobile, this means 100vh is taller than the visible area when the address bar is showing, causing the classic bottom-of-screen overflow. The solution is the three-tier system introduced in 2022:

  • svh / svwsmall viewport: measured with toolbars visible (the shortest safe area)
  • lvh / lvwlarge viewport: measured with toolbars hidden (the maximum size)
  • dvh / dvwdynamic viewport: updates live as toolbars show and hide

Use dvh for elements that must genuinely fill the visible screen at all times, svh for a safe minimum, and avoid bare vh for full-height mobile layouts.

Container query units

Container units resolve against the nearest containment context — an ancestor that declares container-type: size or container-type: inline-size. Without one, they behave like small viewport units.

UnitResolves against
cqwContainer width
cqhContainer height
cqiContainer inline size (width in horizontal writing modes)
cqbContainer block size
cqmin / cqmaxSmaller / larger of cqi and cqb

These are most useful for reusable components that should size themselves to their container rather than the viewport — carousels, card grids, and sidebars that exist in multiple layout contexts.

Practical conversion example

With a 16px root font-size and a 1440px viewport:

Valueremem (at 16px)vwpt
16px1rem1em1.11vw12pt
24px1.5rem1.5em1.67vw18pt
48px3rem3em3.33vw36pt

Tips and notes

  • Prefer rem for type and spacing so a single root font-size scales the whole UI; reach for em when you want a value to track the local font-size.
  • Use dvh (or svh/lvh) instead of vh for full-height mobile layouts to avoid the address-bar overflow problem.
  • Container units (cqw, cqi, …) only resolve inside an element with a declared container-type; otherwise they fall back to viewport sizing.
  • Absolute units are consistent with px on screen but only physically accurate in print.

The relative conversions above are exact given the basis values you enter; change the root or viewport fields to match your own stylesheet.