Responsive Font Sizing in CSS With clamp()
Fluid type with clamp() worked out in full: exact values for 16 to 20px body text and a 32 to 56px heading, the vw zoom trap, and how to test it.

Responsive font sizing used to mean three or four media queries that bumped the font size at each breakpoint. Today one line of CSS does it smoothly: font-size: clamp(min, preferred, max), with a preferred value that mixes rem and vw. This guide works the formula out in full, gives you exact values you can paste, and shows with real browser measurements the one mistake that turns fluid type into an accessibility failure.
If you are still deciding between units, start with the sibling guide on px vs rem vs em in CSS. Everything below assumes rem for the parts that should respect the reader.
Step one: rem already makes text responsive to the reader
The most important kind of responsiveness has nothing to do with screen width. It is responding to the person reading. Text sized in rem follows the browser's default font size, which readers change in their settings, and it scales with page zoom. That alone satisfies most of WCAG 1.4.4, Resize Text.
So a perfectly good responsive type setup is:
body { font-size: 1rem; } /* 16px by default */
h1 { font-size: 2.25rem; } /* 36px by default */
@media (min-width: 64em) { /* 1024px at default settings */
body { font-size: 1.125rem; }
h1 { font-size: 3rem; }
}Two sizes, one breakpoint in em so it also follows the reader's setting. If your design only needs two steps, stop here; it is simple, predictable and accessible. Fluid type earns its place when the gap between the smallest and largest size is big, as with display headings, and a single jump at a breakpoint looks abrupt.
Step two: clamp() with a viewport-based middle value
clamp() takes three values: a minimum, a preferred value and a maximum. The browser uses the preferred value, but never lets it go below the minimum or above the maximum.
h1 { font-size: clamp(2rem, 1.413rem + 2.6087vw, 3.5rem); }The middle value is a straight line. The vw part makes it grow with the viewport width; the rem part sets where the line starts and keeps a share of the size tied to the reader's setting. The minimum and maximum flatten the line outside the range you designed for.
Every modern browser supports clamp(), so there is no fallback to write for current traffic.
The formula, worked through
You want a size that is minSize at viewport minVw and maxSize at viewport maxVw, growing in a straight line between them. All values in pixels to start.
- Slope = (maxSize minus minSize) divided by (maxVw minus minVw).
- The vw coefficient = slope times 100 (because 1vw is 1% of the viewport).
- Intercept = minSize minus (slope times minVw). This is the size the line would have at a zero-width viewport.
- Convert to rem by dividing the intercept, minSize and maxSize by 16 (the default root). The PX to REM Converter does this step if you would rather not divide by hand.
- Write it as
clamp(minRem, interceptRem + coefficient vw, maxRem).
Body text: 16px to 20px between 360px and 1280px
- Slope = (20 minus 16) / (1280 minus 360) = 4 / 920 = 0.0043478
- Coefficient = 0.4348vw
- Intercept = 16 minus (0.0043478 times 360) = 16 minus 1.5652 = 14.4348px = 0.9022rem
- Minimum 16px = 1rem, maximum 20px = 1.25rem
body { font-size: clamp(1rem, 0.9022rem + 0.4348vw, 1.25rem); }Heading: 32px to 56px between 360px and 1280px
- Slope = (56 minus 32) / 920 = 24 / 920 = 0.0260870
- Coefficient = 2.6087vw
- Intercept = 32 minus (0.026087 times 360) = 32 minus 9.3913 = 22.6087px = 1.4130rem
- Minimum 32px = 2rem, maximum 56px = 3.5rem
h1 { font-size: clamp(2rem, 1.413rem + 2.6087vw, 3.5rem); }We did not trust the arithmetic alone. We loaded both rules in Chromium and read the computed font size at every 20px of viewport width from 320 to 1440:
The lines are flat below 360px, straight between 360 and 1280, and flat above. At 820px, the midpoint, the heading measures 44px and the body 18px, exactly halfway. Here is what that looks like at true scale on three common widths:
Filling in the rest of the scale
For an H2 and H3, either repeat the formula with your own pairs (say 24 to 36px and 20 to 26px), or pick a ratio for small screens and a larger one for wide screens and derive every step from them. Keep body text close to fixed, and let the bigger sizes do the stretching: a body that swings from 14 to 22px reads as a different site on each device.
The accessibility bug of pure vw
It is tempting to skip the rem part and write font-size: 4vw. It looks perfect while you drag the window around. It is also broken for anyone who needs larger text.
The reason: browser zoom makes CSS pixels larger, which makes the viewport narrower in CSS pixels. A 1280px window at 200 percent zoom is a 640px viewport. 4vw of 640 is 25.6 CSS pixels, drawn at 2x, which is 51.2 screen pixels. At 100 percent zoom it was 4vw of 1280, also 51.2 screen pixels. The zoom cancels out. We measured it:
| Page zoom | 1.5rem (screen px) | 4vw (screen px) | Fluid H1 (screen px) |
|---|---|---|---|
| 100% | 24 | 51 | 56 |
| 150% | 36 | 51 | 67 |
| 200% | 48 | 51 | 79 |
| 300% | 72 | 51 | 101 |
| 400% | 96 | 51 | 128 |
| 500% | 120 | 51 | 160 |
The 4vw heading does not grow at any zoom level. It also ignores the browser font size setting, because no part of it refers to the root. A page set entirely in vw fails 1.4.4 outright.
Look at the fluid heading's column too, because it carries a subtler point. With a vw share in the preferred value, the text grows less than the zoom: 1.4 times at 200 percent zoom, reaching double its size somewhere between 300 and 400 percent. We saw the same with the browser font size setting doubled to 32px: on a 360px phone both rules doubled exactly (the minimum is pure rem), but at 1280px the body went from 20 to 34.4px, not 40.
Readers can still reach double size, so this is not the outright failure that pure vw is, but it is worth knowing before an audit asks. Three ways to keep fluid type comfortably accessible:
- Keep the vw share small. The steeper the slope, the more of the size ignores zoom. A body rule that moves 4px across 920px of viewport is mild; a heading that moves 60px is not.
- Keep the maximum at no more than about two and a half times the minimum, so the clamp range never fights zoom by much. Our heading's range is 1.75 times.
- Keep body text in plain rem with an em breakpoint, as in step one, and save
clamp()for headings. Body copy is where readers most need their setting respected, and a 2 to 4px fluid gain there is barely visible anyway.
Then test it: zoom to 200 percent and set the browser font size to Very large, separately, and check both.
font-size-adjust: consistent size across fallback fonts
Two fonts at the same font-size can look very different in size, because the visible height of lowercase letters (the x-height) varies from typeface to typeface. When a web font is slow to load and the browser shows a fallback first, the text can jump in apparent size and reflow the page.
font-size-adjust scales the fallback so its x-height matches. It has been supported in every major browser since July 2024.
body {
font-family: "Barlow", Arial, sans-serif;
font-size-adjust: from-font; /* use the primary font's own x-height ratio */
}from-font reads the ratio from the first available font, or you can give a number such as font-size-adjust: 0.5. It only adjusts fonts whose x-height differs from the target, so it stacks safely with everything above.
Container query units: sizing to the component, not the screen
Viewport units answer "how wide is the window?" A card in a three-column grid on a wide screen is narrower than the same card alone on a tablet, so window width is the wrong question for component text. Container query units answer "how wide is my container?"
.card { container-type: inline-size; }
.card h3 {
font-size: clamp(1.125rem, 0.9rem + 2cqi, 1.5rem);
}cqi is 1% of the container's inline size (its width in a horizontal language). The same formula from above applies, with container widths in place of viewport widths. The same caution applies too: keep a rem part in the middle value and a rem minimum and maximum, because when a container is as wide as the viewport, cqi cancels out zoom exactly as vw does. Container units have been supported in all major browsers since 2023.
What to avoid
- A bare vw or cqi font size. Always wrap it in
clamp()with rem bounds and a rem share in the middle value. - A px minimum or maximum, such as
clamp(16px, 4vw, 24px). The px bounds ignore the browser font size setting, so a reader who asked for larger text is capped at your 24px. - Fluid body text with a steep slope. Body text should barely move.
- Fluid line-height in px. Use a unitless
line-height: 1.5so the spacing follows whatever size the text ends up at. - Copying a generator's output without checking its range. Confirm it in the browser at your smallest and largest designed widths, as we did above.
- Forgetting contrast at the new sizes. Large, light display type is a common contrast failure; check it with the Color Contrast Checker, especially over a background from the CSS Gradient Generator, where contrast changes along the gradient.
The same thinking applies to fluid images and embeds: size them to the container, and keep their shape stable with aspect-ratio (the Aspect Ratio Calculator gives the ratio and the missing dimension).
The takeaway
- rem first: it is what makes type respond to the reader.
clamp(minRem, interceptRem + Xvw, maxRem)for headings that need to grow smoothly. For 32 to 56px between 360 and 1280:clamp(2rem, 1.413rem + 2.6087vw, 3.5rem). For 16 to 20px body text:clamp(1rem, 0.9022rem + 0.4348vw, 1.25rem).- Never a font size in vw alone; it cannot be zoomed.
- Keep slopes gentle, measure in a real browser, and test at 200 percent zoom and a Very large font setting.
For the arithmetic behind every rem value above, and how a different root size changes it, see how the CSS root font size converts rem to px. And if you are building a product where type, layout and accessibility have to hold up across every screen your customers use, that is part of how we approach web application development.
Tools mentioned in this post
- PX to REM ConverterConvert px to rem and rem to px at any root font size, with full conversion tables for 16px and 10px roots.
- Color Contrast CheckerWCAG contrast ratio between text and background, with live AA/AAA verdicts.
- CSS Gradient GeneratorDesign a linear or radial gradient visually: copy the CSS in one click.
- Aspect Ratio CalculatorFind any image or video’s ratio and scale it to new dimensions without distortion.


