# CSS clamp() Calculator

> Set a smallest and largest size and two viewport widths, see the result at any width, and copy clamp() as CSS or Tailwind.

- Page: https://codethatmoves.com/tools/motion/clamp-calculator/
- Site: Code That Moves
- Category: Motion and CSS
- Free, runs in the browser, nothing is uploaded
- Last checked: 2026-11-03

## What it does

- clamp() from min and max size and min and max viewport, in rem or px
- Grows with the viewport (vw) or with its container (cqi), for font-size, padding, margin, gap, width or height
- Live preview with a width slider and a graph of size against width
- A fluid type scale with named ratios, steps below and above the base, and a 200% zoom check per step
- A Utopia-style fluid space scale with one-up pairs such as s-m and s-l
- Export the scales as CSS variables, a Tailwind v4 @theme block, a SCSS map or JSON
- Everything, including the scale settings, is in the share link

## How to use it

1. Enter the smallest and largest font size and the viewport widths where they apply, or start from a preset.
2. Move the viewport slider to see the size at any width, and read the table for common ones.
3. Copy the CSS, the clamp() value or the Tailwind class. Use the type and space scale sections for a whole set of sizes, and pick the export format you need.

## What it checks and why

clamp(min, preferred, max) keeps a value between two limits and lets it grow in between. For fluid type the preferred value is a straight line: a rem part plus a vw part, so the size rises from the smallest at one viewport width to the largest at another and holds there.

The calculator solves the line for you. The slope is the size range divided by the viewport range, and the intercept is what the line gives at a zero-width screen. Writing the rem part in rem, not px, keeps the browser's font size setting working.

Fluid type has an accessibility catch. The vw part does not grow when a visitor zooms the page, so text that grows a lot between the limits can stay too small at 200% zoom. The tool warns when the largest size is more than about 2.5 times the smallest, and checks every step of the type scale the same way.

Switch the unit to cqi and the value follows the width of the nearest container instead of the screen, which suits components that sit in columns of different widths. The space scale uses the same base: 3xs is a quarter of it and 3xl six times, and pairs such as s-l go from one size on small screens to a bigger one on large screens.

## Reference data

| Preset | Smallest | Largest | clamp() for 320px to 1440px, 16px root |
| --- | --- | --- | --- |
| Body text | 16px | 20px | `clamp(1rem, 0.9286rem + 0.3571vw, 1.25rem)` |
| Lead paragraph | 18px | 24px | `clamp(1.125rem, 1.0179rem + 0.5357vw, 1.5rem)` |
| Heading 3 | 20px | 28px | `clamp(1.25rem, 1.1071rem + 0.7143vw, 1.75rem)` |
| Heading 2 | 24px | 40px | `clamp(1.5rem, 1.2143rem + 1.4286vw, 2.5rem)` |
| Heading 1 | 32px | 64px | `clamp(2rem, 1.4286rem + 2.8571vw, 4rem)` |
| Display | 40px | 96px | `clamp(2.5rem, 1.5rem + 5vw, 6rem)` |

## Specs and sources

- [MDN: clamp()](https://developer.mozilla.org/en-US/docs/Web/CSS/clamp)
- [W3C: CSS Values and Units, min(), max() and clamp()](https://www.w3.org/TR/css-values-4/#comp-func)
- [WCAG 2.2: Understanding 1.4.4 Resize Text](https://www.w3.org/WAI/WCAG22/Understanding/resize-text.html)
- [Utopia: fluid type and space](https://utopia.fyi/)

## Limits

- Sizes are interpolated in a straight line between the two widths.
- cqi needs an ancestor with container-type: inline-size; without one it falls back to the small viewport width. The preview slider stands for the container width in that mode.
- The vw unit includes the width of a vertical scrollbar, so values differ by a few pixels from a layout that excludes it.
- The 2.5 times limit is a rule of thumb, not a WCAG number. Test with browser zoom at 200%.

## Questions

### How does clamp() work for font size?

clamp(1rem, 0.857rem + 0.714vw, 1.5rem) means the size is at least 1rem, at most 1.5rem, and in between it follows 0.857rem plus 0.714% of the viewport width.

### Should I use rem or px in clamp()?

Use rem. Pixel values ignore the font size a visitor sets in their browser. The calculator converts from px using your root font size, 16px by default.

### Is fluid type accessible?

It can be, if the largest size is not much bigger than the smallest and the text still scales when a visitor zooms in. The warning in the tool flags the risky setups; test at 200% zoom.

### What is a fluid type scale?

A set of sizes (small print, body, headings) where each step is a clamp() value. A ratio such as 1.2 or 1.25 sets the gap between steps, and it can be different on small and large screens.

### Can I use clamp() for padding and spacing?

Yes. clamp() works for any length, so pick padding, margin, gap, width or height in the Property menu. The fluid space scale gives a whole set of spacing values that grow with the type.

### How do I use clamp() with container query units?

Switch the unit to cqi. 1cqi is 1% of the inline size of the nearest container, so set container-type: inline-size on the parent. The two widths then mean container widths, not screen widths.

### Why does my fluid text not grow when I zoom in?

Zoom makes the viewport narrower in CSS pixels, so the vw part shrinks while the rem part grows. Keep the largest size within about 2.5 times the smallest, so more of the value is rem, and test at 200% zoom.
