Say what size you want at a narrow viewport and at a wide one, and get a clamp() that interpolates smoothly between them and stops at both ends. The output uses rem for the bounds and keeps a rem term in the middle rather than reducing to a bare vw value, and that is not a stylistic preference: a size built only from viewport units ignores the reader's own font setting entirely, so someone who has increased their default text size sees no difference at all. That fails WCAG 1.4.4. Drag the preview slider to see the size at any viewport width, including outside the range where the clamp holds it steady — which is the whole reason to use clamp() rather than a raw vw value that keeps growing forever on a large monitor.
| Approach | Scales with viewport | Respects user font size |
|---|---|---|
| font-size: 20px | No | No |
| font-size: 2vw | Yes, without limit | No |
| clamp() with vw only | Yes, bounded | No |
| clamp() with rem + vw | Yes, bounded | Yes |
It takes three values: a minimum, a preferred value and a maximum. The browser uses the preferred value unless it falls outside the bounds, in which case it uses the nearer bound. With a viewport-relative preferred value, that gives you a size that scales smoothly and then stops.
Because rem respects the reader's font settings and px does not. Someone who has set a larger default text size in their browser gets nothing from a px-based fluid size. This is an accessibility requirement — WCAG 1.4.4 asks that text survive being resized to 200% — not a preference.
Two reasons. A bare vw value keeps growing indefinitely, so a heading that looks right at 1280px is absurd on an ultrawide monitor. And vw is completely independent of the user's font size setting, so zooming text does nothing. Keeping a rem term and clamping both ends fixes both problems.
320px and 1280px are sensible defaults — roughly the narrowest phone and a common desktop width. Going wider than about 1600px at the top makes the size change very slowly across most real screens, which defeats the point.
Yes, and it is occasionally what you want — an oversized display heading that calms down on larger screens. The bounds are ordered correctly for you, since clamp() expects its smaller value first and would otherwise pin the result at one end.
Yes. clamp() has been supported in every major browser since 2020. If you need to support older ones, a font-size fallback declared before the clamp will be used by browsers that cannot parse it.
The preferred term is a straight line through two points: the size you want at a narrow viewport and the size you want at a wide one. The slope is the change in size divided by the change in viewport width, expressed in vw by multiplying by 100; the intercept is what is left when that line is extended back to a viewport of zero. The detail that matters for accessibility is that the intercept is written in rem rather than px, and it is never dropped in favour of a bare vw value. A size built only from viewport units ignores the reader's own font setting completely — someone who has raised their default text size sees no change at all, because vw knows nothing about it. That fails WCAG 1.4.4, which requires text to remain usable when resized to 200%. Keeping a rem component means the root size still moves the result. The bounds are emitted smallest-first because clamp() takes its lower limit as the first argument, and a value that shrinks as the viewport grows — unusual but legal, and sometimes what you want for a hero heading — would otherwise be pinned at one end rather than interpolating. An equal or inverted viewport range is refused with an explanation rather than dividing by zero and emitting a clamp containing Infinity, which is valid syntax that silently does nothing.