CSS Unit Visualizer
Compare px, em, rem, %, vw, vh, ch and pt side by side as you change root size, viewport and font.
Stage settings
width context · system fontUnit comparator
8 units · 16 nominalNested context: parent at 1.5em (24px)
16em → 384px (compounds against the parent)
16rem → 256px (always the root)
| Unit | Value | Pixels | Formula |
|---|---|---|---|
| px | 16px | 16px | value as written — absolute |
| em | 16em | 256px | value × parent font-size |
| rem | 16rem | 256px | value × root font-size |
| % | 16% | 163.84px | value/100 × parent width (or parent font-size for font-size) |
| vw | 16vw | 163.84px | value/100 × viewport width |
| vh | 16vh | 122.88px | value/100 × viewport height |
| ch | 16ch | 136px | value × width of '0' in the current font |
| pt | 16pt | 21.33px | value × 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
root 16 → 20px, nominal 16rem/16pxrem sample 16px → 20px, px sample stays 16pxrem follows the root and px never changes, which is why rem is preferred for accessible type scales.
The ch unit depends on the font
font system → monospace, nominal 16chThe monospace ch sample is widerch 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
Set the context
Choose a root font-size, simulated viewport width, parent font-size and nominal value.
Switch measures
Toggle between width and font-size to see how % and em change meaning, then pick a font family to affect ch.
Compare blocks
Read the pixel value under every unit sample and compare it with the formula in the reference table.
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
| Unit | Resolves against |
|---|---|
| px | The screen pixel grid |
| em | Parent element's font-size |
| rem | Root element's font-size |
| % | Parent width, or parent font-size for font-size |
| vw / vh | Viewport width / height |
| ch | Width of the '0' glyph |
| pt | 96/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
Related tools
Aspect Ratio Calculator
Calculate dimensions and ratios for images and videos.
Border Radius Generator
Visually craft CSS border-radius values — including the advanced 8-value slash syntax for organic blob shapes — with a live preview and one-click copy.
Box Shadow Generator
Visual CSS box-shadow generator. Create beautiful shadows with live preview and copy the CSS code.
CSS :has() Selector Playground
Try the CSS :has() parent selector on live editable HTML and CSS, with ten patterns, dropped-rule detection and specificity notes.
CSS Button Generator
Design buttons with hover, active, focus-visible and disabled states — gradients, shadows, borders, icons — and copy clean CSS or Tailwind.
CSS Clip-Path Generator
Draw clip-path shapes visually: drag polygon points, tune circle/ellipse/inset presets, paste an SVG path and copy responsive CSS.