Fluid Typography With CSS clamp()
Text that grows smoothly from phone to desktop, without breaking zoom.
Fixed font sizes and a few media-query breakpoints were the standard for years. Text jumps in steps as the screen crosses each breakpoint, and between those steps it stays the same size. Fluid typography replaces those steps with a smooth curve, so text grows gradually from a small phone to a large desktop. This guide explains how to build that curve with CSS clamp(), and how to keep it accessible.
It is one of the most searched responsive design topics right now, and it is simple to get right once you know the three values that clamp() takes. The examples below use real pixel targets, and every number has been checked.
Why breakpoints create jumps
With breakpoints, a heading might be 28px on a phone, then jump to 40px on a tablet, then to 56px on a desktop. Between those points the size does not change at all. On a 600px screen the heading is the same size as on a 480px screen, while the line length, the spacing and the image size are changing. Fluid type keeps the type in step with the layout.
How clamp() works
The clamp() function takes three values: a minimum, a preferred value, and a maximum. The browser uses the preferred value while it sits between the minimum and the maximum, and holds the minimum and maximum outside that range. The preferred value usually combines a fixed size in rem with a viewport width in vw, which gives a sloped line between two sizes.
Written out, the pattern is clamp(minimum, preferred, maximum). The minimum is the smallest size the text will reach, the maximum is the largest, and the preferred value sets how quickly it grows in between.
Worked example: body text from 16px to 20px
Suppose body text should be 16px at a 320px screen and 20px at a 1280px screen. The line between those two points has a slope of 4px over 960px, which is 0.4167vw, and it starts at 14.67px, which is 0.9167rem. That gives this value:
font-size: clamp(1rem, 0.9167rem + 0.4167vw, 1.25rem);
Check it at the edges and the middle. At 320px the result is 16px. At 768px it is about 17.9px. At 1280px it is 20px. The same method works for any pair of sizes, so you can calculate your own values in a few minutes.
A complete type scale
Most sites need more than body text. This example scales three levels, each with the same 320px to 1280px range. The heading sizes grow faster than body text, which keeps the hierarchy clear on large screens:
:root {
--text-body: clamp(1rem, 0.9167rem + 0.4167vw, 1.25rem); /* 16px to 20px */
--text-h3: clamp(1.25rem, 1.1667rem + 0.4167vw, 1.5rem); /* 20px to 24px */
--text-h1: clamp(2rem, 1.5rem + 2.5vw, 3.5rem); /* 32px to 56px */
}
body { font-size: var(--text-body); line-height: 1.6; }
h3 { font-size: var(--text-h3); }
h1 { font-size: var(--text-h1); line-height: 1.1; }
Keep the scale in one place, such as the root element, so that a future change touches a single line.
Keep zoom working
Accessibility is the main risk with fluid type. WCAG success criterion 1.4.4 (Resize Text) requires that text can be enlarged up to 200 percent without loss of content or function. A preferred value written only in vw can stop the browser's zoom from making text larger in a meaningful way, because the size is tied to the viewport rather than to the user's settings.
That is why the preferred value combines a rem term with the vw term. The rem part responds to the user's default font size, and the vw part provides the smooth growth. Always test with the browser zoomed to 200 percent, and with a larger default font size in the browser settings.
Line length and line height
Fluid type does not change the reading rules. Body text is easiest to read at roughly 45 to 75 characters per line, and a line height of 1.5 to 1.7 suits most body copy. On large screens the text can grow while the column stays narrow, so set a maximum width for the article, typically between 60 and 75 characters, and let the text size do the rest.
Test your fluid scale
- Resize the browser slowly from 320px to 1440px, and watch for headings that overlap, wrap awkwardly or push buttons out of view.
- Zoom the page to 200 percent, and check that the layout still works and nothing is cut off.
- Change the browser's default font size, and check that the text scales with it.
- Read the page on a real phone, where the smallest size is most likely to feel cramped.
The Typography QA Lab helps you check how your text reads at different sizes, and the Font Stack Tester shows how a fallback font behaves while a web font loads.
Fluid spacing and images
The same idea works for spacing. Section padding and gaps can use clamp() too, so that a 16px gap on a phone grows to 48px on a large screen. Images benefit from a maximum width of 100 percent, so they scale with their column. Pairing fluid text with fluid spacing keeps the page balanced at every width, rather than making only the text change size.
Where fixed sizes are still the right choice
Not every element should scale. Buttons, form labels and navigation items often work best at a fixed, predictable size, because users learn their positions and tap targets. Small captions and interface text should also stay steady. Use fluid sizes for headings and reading text, where a larger screen genuinely benefits from more presence, and keep interface text fixed.
Common mistakes
- Using a vw-only value, which blocks zoom and ignores the user's font size.
- Setting the maximum too high, so headings become oversized on large monitors.
- Letting body text grow while the line length keeps increasing, which makes reading harder.
- Applying fluid sizes to every element, instead of keeping a short, named scale.
Checklist
- Each text level has a minimum, a preferred value and a maximum.
- The preferred value includes a rem term, so zoom still works.
- Body text stays at or above 16px on phones.
- Article width keeps lines between about 60 and 75 characters.
- The page has been tested at 200 percent zoom and with a larger default font size.
Frequently Asked Questions
What is fluid typography?
Fluid typography is text that changes size smoothly with the width of the screen, instead of jumping at fixed breakpoints. In CSS it is usually built with clamp(), which sets a minimum, a preferred value that scales with the viewport, and a maximum.
Does clamp() work in all browsers?
clamp() is supported in all current major browsers, including Chrome, Edge, Firefox and Safari. For older browsers, you can keep a fixed font size as a fallback before the clamp() declaration, so the page still works.
Does fluid type hurt accessibility?
It can, if the preferred value uses only vw. Include a rem term in the preferred value, and test at 200 percent zoom with a larger default font size. Done this way, fluid type stays compatible with WCAG 1.4.4 Resize Text.
Do I still need media queries?
Often yes, for layout changes such as moving from one column to two. Fluid type handles the size of the text, while media queries handle the structure of the page. Use both together.