New series: what assistive tech really hears on your checkout page. Start with part one →
Shipwright
Home
CSS Sep 6, 2026 2 min read 287 views

Fluid Typography with clamp(): A Formula You Can Reuse

Mara Okafor

Mara Okafor

@maraokafor

Share
Cover illustration for the article Fluid Typography with clamp(): A Formula You Can Reuse

One formula, two breakpoints, and no media queries for your type scale. Most CSS problems we see in reviews are not about a missing property. They are about a layout that was never told what it should do when the content changes size, and that is what this piece sets out to fix.

Start from the constraint

Begin by writing down the smallest and largest sizes the component must survive. Once those two numbers exist, properties such as clamp(), minmax(), and fit-content stop feeling like magic and start reading like a specification.

typography.css
:root {
  --step-0: clamp(1rem, 0.93rem + 0.33vw, 1.19rem);
  --step-1: clamp(1.2rem, 1.09rem + 0.54vw, 1.5rem);
  --step-2: clamp(1.44rem, 1.27rem + 0.85vw, 1.95rem);
}

h1 { font-size: var(--step-2); }
h2 { font-size: var(--step-1); }
body { font-size: var(--step-0); }

Where the layout bends

The tricky part is always the middle: the tablet widths nobody designs for, the translated label that is forty percent longer, the avatar that failed to load. Test those states on purpose by resizing the container rather than the whole window.

  • Set explicit minimum and maximum sizes first.
  • Prefer intrinsic sizing keywords over fixed pixel values.
  • Let the container decide, not the viewport.
  • Keep one fallback declaration above the modern one.

Browser support notes

Everything here works in the current versions of Chrome, Firefox, and Safari. Where a feature landed recently we note the version, and the fallback is usually a single line that older engines simply ignore.

We have been running this approach for several months now. The initial setup took about a day, and the ongoing cost is close to zero once the team knows where to look.

None of this is new, and that is the point. The techniques that last are usually the boring ones that are documented well and supported by the platform itself.

As always, the examples are simplified to fit on a page. The production version has more error handling and logging, but the shape of the code is the same.

Before you ship this

Fluid values based on vw ignore the user’s zoom level in some browsers. Always mix in a rem term so text still scales when readers zoom.

Premature optimization is the root of all evil.

Donald Knuth, Structured Programming with go to Statements, 1974

Wrapping up

Questions, corrections, and war stories are welcome in the comments. Several of our best follow-up posts started as a reader pointing out something we had missed.

Mara Okafor

Mara Okafor

Author

Staff frontend engineer focused on CSS architecture and accessibility. Mara has audited more design systems than she can count and still gets excited about a good focus ring.

Related Posts

Comments 9

Sam Whitfield Member

Tried it on a side project over the weekend and it worked first time, which never happens.

Mara Okafor Author

Same experience here, the tooling is much better now.

Sam Whitfield Member

The renaming spree is a rite of passage.

Mara Okafor Author

We have a follow-up on CI in the drafts, stay tuned.

Sam Whitfield Member

Any thoughts on how this interacts with server-side rendering?

Mara Okafor Author

Thanks for catching that, it is fixed now.

Ben Carter

Counterpoint: for small teams the simpler approach in the first section is usually enough.

Hannah Becker

Great post. Did you measure the impact before and after, or is this mostly from experience?

Sam Whitfield Member

The quote in the middle is doing a lot of work here, and it earns it.

Leave a comment

Your email will not be published. Sign in for a faster experience.

Supports **bold**, *italic*, and `code`.