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.
: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.
Tried it on a side project over the weekend and it worked first time, which never happens.
Same experience here, the tooling is much better now.
The renaming spree is a rite of passage.
We have a follow-up on CI in the drafts, stay tuned.
Any thoughts on how this interacts with server-side rendering?
Thanks for catching that, it is fixed now.
Counterpoint: for small teams the simpler approach in the first section is usually enough.
Great post. Did you measure the impact before and after, or is this mostly from experience?
The quote in the middle is doing a lot of work here, and it earns it.