---
title: "How do I make font sizes responsive with clamp()?"
description: "Use clamp() with a rem minimum, a viewport-based preferred value and a rem maximum to make text scale smoothly between screen sizes without media queries."
url: https://www.danny.engineering/answer/css/how-do-i-make-font-sizes-responsive-with-clamp
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T18:58:00.000Z
tags: ["CSS"]
---

# How do I make font sizes responsive with clamp()?

## The short answer


`clamp()` takes three values: a minimum, a preferred value and a maximum. Give it a `rem` minimum and maximum, and a preferred value that mixes `rem` with a viewport unit such as `vw`. The text then grows smoothly with the screen width but never goes below or above your limits.


```css
h1 {
  font-size: clamp(2rem, 1.5rem + 2.5vw, 3.5rem);
}
```


## Why it happens


Without `clamp()`, responsive type usually means a list of media queries that jump the font size at each breakpoint. That works, but the size changes in steps, and text that suits a 768px screen can look cramped at 760px.


Viewport units fix the steps: `font-size: 5vw` scales continuously. On their own, though, they have two problems. On a phone the text gets too small, and on a wide monitor it gets huge. Worse for accessibility, a size in pure `vw` does not respond to the user's browser font size setting, and it barely grows with page zoom, because zooming in makes the viewport narrower in CSS pixels, so the `vw` value shrinks while the zoom enlarges it.


`clamp(min, preferred, max)` solves both. The browser works out the preferred value and then limits it to the range. It is the same as `max(min, min(preferred, max))`. Adding a `rem` part to the preferred value, as in `1.5rem + 2.5vw`, keeps the user's font size setting in the result and makes zoom work properly.


## How to fix it


### Work out the preferred value from two sizes


Pick the size you want at a small viewport and at a large one. For example, 2rem (32px) at 400px wide and 3.5rem (56px) at 1360px wide.

1. Slope: the size change divided by the width change. (56 - 32) / (1360 - 400) = 0.025, so 2.5vw.
2. Intercept: the small size minus slope times small width. 32 - 0.025 x 400 = 22px, or 1.375rem.

```css
h1 {
  /* 32px at 400px wide, 56px at 1360px wide */
  font-size: clamp(2rem, 1.375rem + 2.5vw, 3.5rem);
}
```


You do not need to be exact. Many teams use an online fluid type calculator, or round the numbers until it looks right.


### Build a fluid type scale with custom properties


Define each step once and use it everywhere.


```css
:root {
  --step-0: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --step-1: clamp(1.25rem, 1.1rem + 0.6vw, 1.5rem);
  --step-2: clamp(1.5rem, 1.25rem + 1.2vw, 2.25rem);
  --step-3: clamp(2rem, 1.375rem + 2.5vw, 3.5rem);
}

body { font-size: var(--step-0); }
h2   { font-size: var(--step-2); }
h1   { font-size: var(--step-3); }
```


### Scale with the container instead of the viewport


If a component can appear in a narrow sidebar or a wide main column, size its text from the container. Container query units such as `cqi` (1% of the container's inline size) work inside `clamp()` once the parent is a container.


```css
.card-wrapper {
  container-type: inline-size;
}

.card h3 {
  font-size: clamp(1.125rem, 0.9rem + 3cqi, 1.75rem);
}
```


### Use it for spacing too


`clamp()` works on any length, so padding, gaps and margins can scale in the same way as the text.


```css
.section {
  padding-block: clamp(2rem, 1rem + 5vw, 6rem);
}
```


## Common pitfalls

- Using only `vw` in the preferred value. Text in pure viewport units ignores the user's font size preference. Always add a `rem` term.
- Putting the maximum smaller than the minimum. If the minimum is larger, it wins and the text never changes size.
- Writing `1.5rem+2.5vw` with no spaces. Inside `calc()` and `clamp()`, the plus and minus signs need a space on each side or the declaration is invalid.
- Making body text too fluid. Large headings benefit from a wide range; body text should only change a little, if at all.
- Choosing a very wide range. WCAG asks for text to resize to 200%. A useful rule of thumb is to keep the maximum no more than about 2.5 times the minimum, then check with browser zoom that the text still gets bigger at large widths.

## Related reading

- [MDN: clamp()](https://developer.mozilla.org/en-US/docs/Web/CSS/clamp)
- [MDN: Container query length units](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_containment/Container_size_and_style_queries#container_query_length_units)
