Fluid Typography with CSS clamp(): A Readable Type Scale That Adapts

A headline that looks balanced on a large monitor may wrap awkwardly on a narrow phone. Making it smaller at one breakpoint and larger at another works, but a collection of special-case media queries is hard to maintain. Modern CSS gives you a more gradual option: clamp().

Start with a legible minimum, a useful fluid range and an upper bound that prevents oversized headings. You can keep body text stable while letting larger headings respond to the available width.

Think in minimum, preferred and maximum sizes

The clamp() function accepts three values:

/* Minimum, preferred, maximum */
font-size: clamp(2rem, 1rem + 3vw, 4.5rem);

Browsers select the preferred computed value, but prevent it from falling below the minimum or exceeding the maximum. A basic heading example is:

.hero-title {
  font-size: clamp(2rem, 1rem + 3vw, 4.5rem);
}

Here the heading cannot shrink below 2rem, can expand as the viewport widens because of 3vw, and has a 4.5rem cap. The bounds use rem, which follows the root font size. The preferred expression mixes rem and viewport width. That gives user font preferences some influence, but it does not guarantee that the text will enlarge enough when zoomed; test the complete formula.

The browser support for clamp() is now broad. MDN’s CSS clamp() reference explains the calculation and its accessibility considerations.

Start with body copy, not the hero

Most reading comfort comes from ordinary paragraphs. Keep body type stable unless there is a compelling reason to vary it. A good starting point is a normal 1rem body size, a proportional line height, and a line length that does not stretch across the entire screen.

:root {
  font-family: system-ui, sans-serif;
  font-size: 100%;
}

body {
  margin: 0;
  font-size: 1rem;
  line-height: 1.6;
}

.article {
  width: min(calc(100% - 2rem), 68ch);
  margin-inline: auto;
}

.article p {
  margin-block: 0 1.25em;
}

68ch is a rough line-length target, not a guarantee of exactly 68 visible characters. Actual glyph widths vary. A long paragraph should feel easy to track, while short snippets and subheadings should not collide.

To test a layout early, paste realistic paragraph and list content from the Lorem Ipsum Generator. The tool can produce plain text or HTML lists. Placeholder content is suitable for wrapping tests, but replace it with actual language, numbers and links before release.

Build a compact heading scale

A type scale does not need seven dramatic sizes. Three levels are often enough for a practical landing page or blog article.

:root {
  --type-body: 1rem;
  --type-small: 0.875rem;
  --type-h3: clamp(1.25rem, 1rem + 1.2vw, 2.625rem);
  --type-h2: clamp(1.5rem, 1rem + 2vw, 3.25rem);
  --type-h1: clamp(2rem, 1rem + 3vw, 4.5rem);
}

h1, h2, h3 {
  line-height: 1.15;
  overflow-wrap: break-word;
}

h1 { font-size: var(--type-h1); }
h2 { font-size: var(--type-h2); }
h3 { font-size: var(--type-h3); }

p, li { font-size: var(--type-body); }
small { font-size: var(--type-small); }

These are illustrative values, not universal design tokens. They are intentionally moderate at the low end and cap large headings at the high end. For a compact documentation layout, you may want less variation. A campaign hero may call for more, provided the line wraps and zoom behavior remain comfortable.

Each step needs a clear visual purpose. If the h2 and h3 look indistinguishable in a real page, adjust the weight, margin or actual size instead of adding more variables.

Understand when fluid growth stops

A fluid formula describes a line. The minimum and maximum create the floor and ceiling. That means changing the preferred expression shifts the range where growth is visible.

At a viewport width of 400px, 3vw is 12px. With a root size of 16px, the expression 1rem + 3vw is 28px. The example h1 minimum is 2rem or 32px, so the minimum wins. At a viewport width of 1200px, the preferred value is 16px + 36px = 52px, between the 32px minimum and 72px maximum. At a sufficiently wide viewport, growth stops at the cap.

There is nothing wrong with the font staying fixed on a phone. In fact, a stable mobile size may be precisely what the design needs. Fluid typography describes behavior between bounds rather than promising growth at every viewport size.

When you need a specific type size at a specific viewport, calculate the slope from two design targets, then verify the resulting CSS in the browser. Do not assume a value that looks mathematically smooth is visually correct.

Pair typography with readable colors

Type size is only one dimension of accessibility. Pale text on a pale background remains hard to read even with generous font sizes. Build a palette, then test the actual foreground-background pairs, including muted descriptions, links, disabled states and focus indicators.

The Web2Generators Color Studio helps experiment with color relationships and WCAG contrast checks. The site’s guide to designing an accessible color system explains why reusable CSS colors are more dependable than scattering one-off shades through stylesheets.

Aim for a clear hierarchy: readable body copy, distinguishable headings, visible links and adequate spacing. Higher contrast is not a substitute for clear information architecture, but it supports it.

Do not turn a zoom test into a math problem

Accessibility guidance warns against sizing text with viewport units alone. Mixing relative units into the preferred value helps, but a hard upper bound can still limit further growth for some viewport and zoom combinations. MDN recommends particular care with the maximum allowed value, including using a relative length and allowing sufficient room for resizing.

The reliable check is practical. At 200% page zoom, check that the text actually enlarges enough to read, as well as remaining visible: viewport units can offset part of the enlargement. At 400%, check how the layout reflows, whether navigation overflows and whether important controls can still be operated. Narrow the viewport independently and test text-only zoom, browser font preferences and the operating system’s text enlargement settings where available.

If zoom testing reveals a problem, adjust the caps, layout or overflow handling. For critical reading interfaces, a fixed rem heading size with carefully chosen media queries may be more robust than a fluid formula. clamp() is a convenience, not a requirement.

Handle long words, translations and dynamic content

Good typography needs to survive actual content. Try a long URL, a compound word, a heading in another language and a paragraph containing inline code. The right solution depends on the component.

.article-title,
.card-title {
  overflow-wrap: anywhere;
}

.article pre {
  max-width: 100%;
  overflow-x: auto;
}

.article a {
  text-underline-offset: 0.15em;
}

Use overflow-wrap: anywhere selectively: it can split a long word at unusual points, which is better than clipping but not always attractive for ordinary text. Let code blocks scroll horizontally rather than forcing every token to wrap. Avoid fixed-height containers around headings; translated text often takes more lines than the original.

Images and cards also affect text layout

A heading can be perfectly responsive while the image next to it forces a card beyond the screen width. Give the grid column permission to shrink and keep images within its width:

.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
}

.card__image {
  display: block;
  max-width: 100%;
  height: auto;
}

.card__title {
  font-size: var(--type-h3);
}

If your layout depends on images, review responsive images that actually save bandwidth alongside the typography. Text and images share a layout, and an oversized download or unexpected image dimension can undermine the experience.

Verify the finished page, not just the CSS snippet

Create a small test matrix: a narrow phone width, a tablet width, a desktop width, 200% zoom, a very long heading and a page with no custom fonts loaded. Then revisit the work with realistic content.

A lightweight set of design tokens lets you revise a whole website from a few decisions. The most maintainable type scale is the one that makes a page easy to read across devices without forcing authors to manually repair every headline.

References

Premium is coming soon

An optional premium subscription to remove ads is planned. Subscriptions are not available yet.

You can keep using our free tools without an account.