Turn a minimum and maximum size at two viewport widths into a clamp() that scales smoothly between them, plus a whole modular type scale.
Scales from 16px to 24px
Between 320px and 1280px of viewport, growing by about 0.83333px per 100px of width. Outside that range the clamp holds it.
The quick brown fox
The preview resolves the clamp at the width above rather than at the real viewport, so you can read both ends without resizing the window.
.fluid {
font-size: clamp(1rem, 0.83333rem + 0.83333vw, 1.5rem);
}CSS Clamp Generator runs entirely on your device — nothing is uploaded.
You’re on the Free plan. Compare plans
`clamp(min, preferred, max)` replaces a stack of media queries for anything that should scale with the viewport. The trick is the middle term: it is a line through two points — your minimum size at your small viewport and your maximum at your large one — expressed as a rem offset plus a vw slope. Written by hand that algebra is where the mistakes happen, and the result looks plausible while being subtly wrong.
There is an accessibility rule that a lot of fluid type gets wrong. If the preferred term is pure `vw`, the text stops responding to a visitor's browser zoom and text-size setting, which fails WCAG 1.4.4. Keeping a rem component in the expression — which is what a line through two points naturally produces — means the text still scales when someone zooms. The output here always keeps that rem term.
The modular scale is the other half of the same job. One ratio applied repeatedly from a base size gives a set of sizes that relate to each other instead of being picked one at a time, and each step can be fluid in its own right, so a heading scale narrows on a phone without any breakpoints. The classic ratios are offered by name because they are the ones with a reason behind them.
Everything is written as custom properties, so the scale lives in one place and the rest of the stylesheet refers to it. That is also what makes it worth exporting: a size scale as nine `--step-*` variables is a design decision recorded once, rather than nine magic numbers scattered through a codebase.
The middle term is a straight line through your two size-and-viewport pairs, so the value changes continuously with the viewport instead of jumping at breakpoints. The min and max stop it going past either end.
Two reasons. It is what a line through two points mathematically requires, and it is what keeps the text responsive to browser zoom. A preferred value of pure vw ignores a visitor's text-size setting entirely, which fails WCAG 1.4.4.
Yes, and it is arguably better for spacing. Fluid padding and gaps keep a layout's proportions as the viewport changes, where a fixed gap looks cramped on a wide screen and oversized on a narrow one.
A set of sizes generated by applying one ratio repeatedly to a base size, so every step relates to the others. The named ratios offered here — the major third, the perfect fourth, the golden ratio — are the ones with a musical or geometric reason behind them.
A smaller ratio such as 1.125 or 1.2 for dense interface text where the sizes should stay close; a larger one such as 1.333 or 1.618 for editorial layouts that want dramatic headings. Larger ratios need more vertical room to breathe.