Skip to content

CSS Clamp Generator

Generate fluid typography and spacing with clamp() and viewport units.

Updated · Examples checked by automated tests

LOCAL WORKSPACENO UPLOAD REQUIRED
CSS
font-size: clamp(1rem, 0.8333rem + 0.8333vw, 1.5rem);

Live preview

The quick brown fox jumps over the lazy dog

Resize this window to watch the size scale between 16px and 24px.

Viewport widthComputed size
320px16.0px
480px17.3px
768px19.7px
1024px21.9px
1280px24.0px
1536px24.0px
1920px24.0px

About CSS Clamp Generator

Fluid typography scales text smoothly with the viewport instead of stepping between media queries, and clamp() expresses it in a single line of CSS.

Give this generator your minimum and maximum sizes and the viewport widths they apply at, and it solves the linear equation for you and emits a clamp() expression with rem and vw units. Verify resizing in your actual layout.

How CSS Clamp Generator works in your browser

Given a minimum and maximum size and the viewport widths where each should apply, the generator solves the straight line between those two points and expresses it as a preferred value combining rem and vw. That value is wrapped in clamp(min, preferred, max) so it never goes outside your bounds.

Worked example: 16px at 320px and 24px at 1280px produces clamp(1rem, 0.8333rem + 0.8333vw, 1.5rem), assuming a 16px root font size. At 800px the unrounded interpolation is 20px. Below and above the bounds it stops at the minimum and maximum. Test browser zoom, larger default fonts and real content: mixing rem and vw does not guarantee accessible text resizing.

When to use it

  • Making headings scale smoothly between mobile and desktop without media queries.
  • Creating fluid spacing tokens for a design system.
  • Replacing a stack of breakpoint font sizes with one declaration.

Worked examples

Body text from 16 to 24 px

Settings: Minimum 16 px at 320 px wide, maximum 24 px at 1280 px wide

Input

16 → 24 px, 320 → 1280 px

Expected output

font-size: clamp(1rem, 0.8333rem + 0.8333vw, 1.5rem);

The size grows linearly between the two viewport widths and is fixed outside them. Limits are written in rem, assuming a 16 px root size, so they follow the reader’s browser font-size setting.

A large heading

Settings: Minimum 32 px at 375 px wide, maximum 56 px at 1440 px wide

Input

32 → 56 px, 375 → 1440 px

Expected output

font-size: clamp(2rem, 1.4718rem + 2.2535vw, 3.5rem);

Headings usually change more between phone and desktop than body text, so the slope is steeper.

Limits and checks before you use the result

  • The minimum viewport must be smaller than the maximum and both must be positive; otherwise no formula is produced.
  • clamp() needs browsers from 2020 onward.
  • Check that text still reflows when zoomed to 200%, as WCAG requires; vw-based sizes can resist zoom on their own.

Frequently asked questions

How does clamp work?

It takes a minimum, a preferred value and a maximum, and returns the preferred value clamped between the other two.

Why is the preferred value a formula?

The linear formula makes the size scale smoothly with the viewport between your two breakpoints instead of jumping at each one.

Is it accessible?

Not automatically. The rem conversion assumes a 16px root font size. Test zoom and user font-size changes; a rem plus vw expression alone does not guarantee accessible resizing.

Related tools