CSS clamp() Generator

Say what size you want on a narrow screen and on a wide one, such as 16px on phones to 20px on desktops. The page writes the clamp() and checks that zoom still works.

How it works

clamp(min, preferred, max) uses the preferred value but never goes below the minimum or above the maximum. The preferred value here is a straight line: a fixed part in rem plus a part in vw that grows with the screen width.

The slope is the change in size divided by the change in screen width. For 16px at 375px wide to 20px at 1280px wide, that is 4 divided by 905, or 0.442px per 100px of width, which CSS writes as 0.442vw. The rem part is whatever makes the line pass through 16px at 375px.

The page then checks browser zoom. It tries every screen width from 320px to 3840px and finds the zoom level at which the text reaches twice its normal size. Everything runs in your browser.

How to use it

  1. 1 Type the smallest size and the narrow screen width where it applies, such as 16 and 375.
  2. 2 Type the largest size and the wide screen width where it should stop growing, such as 20 and 1280.
  3. 3 Change the root font size only if your CSS sets one on html.
  4. 4 Copy the CSS line, and read the zoom check under it.

Good to know

  • Keep the largest size under about 2.5 times the smallest. Then even a fluid heading can reach double size at 500% zoom.
  • The same clamp works for padding, margin and gap, so spacing can grow with the text it surrounds.
  • Pick screen widths you actually design for. A range from 375 to 1280 covers phones to small laptops.

Browser support

  • Chrome 94 and later
  • Firefox 93 and later
  • Safari 16.4 and later
  • Edge 94 and later

These are the oldest versions with everything the tool uses. They are worked out from the tool itself, so they change when it does.

Version numbers checked on 2026-09-04.

Working out a fluid font size by hand, and why the rem term stays

Say the body text should be 16px on a 375px phone and 20px on a 1280px laptop, and change smoothly in between. That is a straight line through two points, and CSS can draw it with clamp(). The line rises 4px over 905px of screen width, so the slope is 4 divided by 905, about 0.00442. In vw, where 1vw is one hundredth of the width, that is 0.442vw.

Next, find where the line starts. At 375px wide the vw part gives 375 × 0.00442, about 1.66px. The text must be 16px there, so the fixed part is 16 minus 1.66, which is 14.34px, or 0.8964rem at a 16px root. Put together, the preferred value is 0.8964rem + 0.442vw. Wrap it in clamp(1rem, 0.8964rem + 0.442vw, 1.25rem) so it stops at 16px below 375px and at 20px above 1280px. That is exactly what the page writes.

The rem term matters for accessibility, not only for the arithmetic. When a reader zooms the page to 200%, each CSS pixel becomes two screen pixels, and a 1280px window becomes 640 CSS pixels wide. A size of 1.5vw on that window drops from 19.2 CSS pixels to 9.6, which shows on screen at the same 19.2px as before. Zoom did nothing. With a rem part, that part doubles with the zoom while only the vw part stays put, so the text does grow, just not quite twice as fast.

That is why the zoom check reports a level rather than a plain pass. For the 16px to 20px example, text reaches double size by 250% zoom at every screen width. For a heading from 16px to 64px, even 500% zoom is not enough on wide screens, because almost all of its size comes from the vw part. A good rule is to keep the largest size no more than 2.5 times the smallest. At 500% zoom the text is then at least five times the smallest size, which is at least twice the largest.

The generator has limits. It assumes the root font size you type, and does not read your stylesheet. It uses the viewport width, so a component inside a narrow sidebar grows with the window, not with its box; container query units such as cqi would be the tool for that. The zoom check models page zoom in desktop browsers. It does not cover pinch zoom on phones, or a reader who raises only the default font size, which enlarges the rem part and the clamp bounds but not the vw part.

Frequently asked questions

Why does the result have a rem part as well as vw?

Browser zoom makes every CSS pixel larger, but it also makes the viewport fewer CSS pixels wide, so a size in vw alone stays the same size on screen when someone zooms. The rem part does grow with zoom. Without it, text cannot be enlarged to 200%, which WCAG 1.4.4 Resize Text requires at level AA.

What does the zoom check mean?

It is the lowest browser zoom level at which the text appears at twice its unzoomed size on every screen width. Chrome, Edge and Firefox zoom to 500%, and Safari stops at 300%. If the answer is above 300%, Safari readers cannot double the text everywhere.

Can the size get smaller on wider screens?

Yes. Type a larger smallest size than largest size and the vw part turns negative. clamp() still needs its lower bound first, and the page writes it that way round.

Do all browsers support clamp()?

Yes. Every current browser has supported clamp() since 2020, including Safari from version 13.1.

Related tools

Your files are processed on your device and are not uploaded. You can verify this in your browser’s developer tools under the Network tab.