DevTools Logo

CSS Unit Visualizer

CSS Unit Visualizer

Compare px, em, rem, %, vw, vh, ch and pt side by side as you change root size, viewport and font.

Runs in your browser

Stage settings

width context · system font

Unit comparator

8 units · 16 nominal
The stage simulates a viewport of the chosen width; vw/vh below are model-based readouts, not the browser's real viewport units.
16px16px
16em256px
16rem256px
16%163.84px
16vw163.84px
16vh122.88px
16ch136px
16pt21.33px

Nested context: parent at 1.5em (24px)

16em → 384px (compounds against the parent)

16rem → 256px (always the root)

Pixels per unit in the current context
UnitValuePixelsFormula
px16px16pxvalue as written — absolute
em16em256pxvalue × parent font-size
rem16rem256pxvalue × root font-size
%16%163.84pxvalue/100 × parent width (or parent font-size for font-size)
vw16vw163.84pxvalue/100 × viewport width
vh16vh122.88pxvalue/100 × viewport height
ch16ch136pxvalue × width of '0' in the current font
pt16pt21.33pxvalue × 96/72 — 1pt = 1.333px on screen
:root {
  font-size: 16px;
}
.stage {
  /* simulated viewport: 1024 × 768 */
  width: 1024px;
  font-family: system-ui, sans-serif;
  font-size: 16px;
}
.sample { width: 16px; }

Examples

Root size moves rem

Input
root 16 → 20px, nominal 16rem/16px
Output
rem sample 16px → 20px, px sample stays 16px

rem follows the root and px never changes, which is why rem is preferred for accessible type scales.

The ch unit depends on the font

Input
font system → monospace, nominal 16ch
Output
The monospace ch sample is wider

ch is the advance width of '0' in the current font at the current size.

About this tool

CSS Unit Visualizer makes relative units visible. The same nominal value is rendered in px, em, rem, %, vw, vh, ch and pt inside a comparator stage, with a pixel readout next to every sample and a table showing the formula behind it.

Change the root font-size and the rem blocks grow while px stays fixed. Change the simulated viewport and vw/vh react. Switch the measure from width to font-size and % suddenly resolves against the parent's font-size instead of the stage width. A nested-context section shows why em compounds through a 1.5em parent while rem always returns to the root.

The font selector changes what ch means: it is the width of the '0' glyph in the current font, so a monospace family produces a wider ch than a serif one. pt is shown with the fixed screen relationship 1pt = 96/72px. A generated CSS snippet reproduces the current setup, and viewport presets cover common mobile, tablet and desktop widths. All readouts are computed locally.

What this tool does not do

  • Viewport units are modeled from slider values rather than the actual browser viewport.
  • The ch model uses representative '0' advance widths per font family, not a live font measurement.
  • Only width and font-size contexts are modeled; height, padding and grid contexts have other percentage behavior.
  • The generated snippet recreates the stage settings, not every unit sample shown in the comparator.

How to use this tool

  1. Set the context

    Choose a root font-size, simulated viewport width, parent font-size and nominal value.

  2. Switch measures

    Toggle between width and font-size to see how % and em change meaning, then pick a font family to affect ch.

  3. Compare blocks

    Read the pixel value under every unit sample and compare it with the formula in the reference table.

  4. Copy the setup

    Use a viewport preset for quick checks, then copy the generated CSS snippet into your own page.

Use cases

Learn CSS units

See the difference between absolute and relative sizes while changing the context.

Audit a design system

Check whether a type scale responds to root font-size and user zoom as intended.

Workshops

Demonstrate em compounding and viewport units without writing live code.

What each unit resolves against

UnitResolves against
pxThe screen pixel grid
emParent element's font-size
remRoot element's font-size
%Parent width, or parent font-size for font-size
vw / vhViewport width / height
chWidth of the '0' glyph
pt96/72 px on screen

The visualizer simulates a viewport in the stage; real vw/vh in your page follow the browser window.

Common mistakes

Mistake:Using em for global spacing and getting compounding surprises.

Fix:Use rem for global scale and reserve em for component-local relationships.

Mistake:Expecting ch to be a fixed pixel width.

Fix:It changes with font family and font-size; use the font selector to see the difference.

Mistake:Using pt for screen layout.

Fix:pt is a print unit; on screen it is converted at 96/72 px and offers no advantage over px.

Frequently asked questions

When should I use rem vs em?

rem always resolves against the root font-size, so it is predictable for global spacing and type scales. em resolves against the parent's font-size and compounds in nested components, which is useful when a component should scale as a unit.

What is the ch unit actually?

One ch is the advance width of the '0' glyph in the current font at the current font-size. It is popular for capping line length and aligning monospace inputs, but its pixel size changes with the font.

How does % differ in width vs font-size?

For width, a percentage resolves against the containing block's width. For font-size, it resolves against the parent's font-size. The stage's Measure selector switches between those two contexts.

Does pt matter on screen?

Barely. CSS defines 1pt as 96/72 px, so on screen it is just another absolute unit. Use pt for print stylesheets and px/rem for screens.

How do I simulate a mobile viewport?

Use the Mobile 375 preset in the visualizer. It changes the stage's simulated width and recomputes vw and % readouts; it does not resize your actual browser window.

References & standards