Fluid Typography with clamp()
You'll learn how to create type that automatically scales smoothly between minimum and maximum sizes without media queries.
The Core Idea
Fluid typography means your text size responds to the viewport width continuously, rather than jumping at breakpoint thresholds. The CSS clamp() function makes this easy by letting you define three values: a minimum size, an ideal flexible size, and a maximum size. The browser automatically keeps your type within those bounds.
Think of it like adjusting your car's cruise control with a minimum speed (50 mph), maximum speed (70 mph), but letting the car adapt dynamically to hills in between—never too slow, never too fast.
The Syntax
font-size: clamp(minimum, flexible-value, maximum);
The middle value is typically a viewport-relative unit that grows with screen size.
Practical Example
:root {
--font-body: clamp(1rem, 0.875rem + 0.5vw, 1.25rem);
--font-heading: clamp(1.5rem, 1rem + 2vw, 3rem);
}
body {
font-size: var(--font-body);
}
h1 {
font-size: var(--font-heading);
}
Here, body text stays between 1rem (16px) and 1.25rem (20px), while headings scale from 1.5rem to 3rem. The middle value (0.875rem + 0.5vw) creates the smooth scaling between those bounds.
On small screens, you get the minimum. On large screens, you hit the maximum. Everywhere in between, the size adapts fluidly.
Why It Matters
This eliminates multiple media queries for typography and creates a seamless reading experience across all device sizes. Combined with your type scale custom properties, you can build an entire responsive typography system with just a few fluid values.
Key Takeaway: Use clamp(min, flexible, max) to create typography that scales smoothly with viewport width, staying within readable bounds without breakpoints.