Skip to content
Back to Concepts
CSS UniverseTrack 4: Units & MathCSS Units
1st Year CS Foundation · Core Track 4Core Concept 14

CSS Units (px, rem, em, vh, ch)

Never use raw pixels for font sizes again. Master relative scaling, accessible rem root calculations, viewport metrics (vh, dvh), and typographic ch constraints.

1. The Core Comparison

Why Professionals Build with `rem` Instead of `px`

Pixels (`px`): The Rigid Metal Ruler

If an elderly user increases their default browser font size from 16px to 24px for accessibility, font-size: 16px ignores their setting completely!
Only use px for: Thin 1px borders, subtle box-shadow offsets.

Root EM (`rem`): The Accessible Elastic Unit

1rem equals the root <html> font size (default 16px).
If the user changes their browser preferences, all rem dimensions scale proportionally across the entire site!

2. Live rem Calculator

See How Root Changes Propagate

Formula: 1.5rem × 16px =
24px Computed On-Screen
3. Units & Functions Workbench

Interactive Units Studio

Interactive Lab

Units & Functions

Play with clamp(), min(), and viewport units to build constraint-based sizing.

Clamp: 14px min → 28px max

Try these

  • Increase max to see upper bound loosen.
  • Drop min to watch minimum size shrink on narrow viewports.
  • Notice width uses min() to cap container across breakpoints.
Constraint-based sizing with clamp(), min(), and viewport units.

Adjust min/max to see the clamped range. Width uses min() to cap the container across breakpoints.

CSS
.utility {
  font-size: clamp(14px, 1vw + 1rem, 28px);
  width: min(90vw, 640px);
}
HTML
<div class="utility">Constraint-based sizing with clamp(), min(), and viewport units.</div>
Next in Track 4

15. Math Functions (calc, min, max, clamp)

Fluid typography, viewport constraints, and clamp() magic.

Continue to Math Functions