Clamp Fluid Typography Responsive

Create fluid typography that scales between minimum and maximum sizes using the CSS clamp function with viewport units.

CssData Integrity

Code

csssnippet
19 lines
h1 {
  font-size: clamp(1.5rem, 4vw + 1rem, 3rem);
  line-height: 1.2;
}

h2 {
  font-size: clamp(1.25rem, 3vw + 0.75rem, 2.25rem);
  line-height: 1.3;
}

p {
  font-size: clamp(1rem, 1.5vw + 0.5rem, 1.125rem);
  line-height: 1.6;
}

.container {
  max-width: clamp(320px, 90vw, 1200px);
  margin: 0 auto;
}

What the code does

clamp() evaluates to [min, preferred, max] — the value scales fluidly but never leaves the bounds.

The rules target h1 — each selector names the element it restyles, in source order.

Interactive Tools for This Topic

FAQ

Which elements does this stylesheet target?
The rules bind to `h1`; when two rules tie in specificity, the one written later in the file wins.