Instead of writing three media queries for mobile, tablet, and desktop heading sizes, CSS clamp(min, preferred, max) scales smoothly between two viewport bounds with zero JavaScript.

Open CSS Clamp Generator
Calculate exact rem + vw slope values visually with live drag preview

The Linear Slope Formula

To scale cleanly from 1.5rem (24px) at 360px viewport up to 3rem (48px) at 1200px viewport:

slope = (maxSize - minSize) / (maxViewport - minViewport) × 100
      = (48 - 24) / (1200 - 360) × 100 = 2.86vw

intercept = minSize - (slope/100 × minViewport) = 0.86rem

h1 {
  font-size: clamp(1.5rem, 0.86rem + 2.86vw, 3rem);
}

Using clamp() Beyond Fonts

Apply the exact same math to section padding, card radii, and gaps inside your CSS Flexbox or CSS Grid containers so mobile screens breathe nicely without manual breakpoints.

Frequently Asked Questions

Why mix rem and vw in the preferred argument?

Keeping a rem base preserves browser zoom accessibility (WCAG), whereas pure vw locks text sizes so users cannot zoom up comfortably.

Can clamp() scale spacing properties too?

Yes—any length property like padding, gap, and margin works with clamp() cleanly.