AyeCalc
All tools
CSS typography

CSS Clamp Generator & Fluid Typography Calculator

Create a fluid CSS value that scales smoothly between two viewport widths without exceeding your chosen minimum or maximum. Use the result for responsive typography, spacing, widths, and other length properties.

Pixel and REM outputCopy-ready CSSNo network calculation
Fluid scale inputs

Generate your clamp()

Runs locally

Generated CSS
clamp(1rem, 0.6667rem + 1.6667vw, 2rem)clamp(16px, 10.6667px + 1.6667vw, 32px)
Core formulapreferred = intercept + slope × 1vw

The generated value uses clamp(minimum, preferred fluid value, maximum).

01
Method

How the css clamp generator works

Calculate the size change per viewport pixel, convert that rate to a vw coefficient, and solve the linear equation for its intercept. The minimum and maximum arguments keep the preferred value inside the intended range.

Formulapreferred = intercept + slope × 1vw

The generated value uses clamp(minimum, preferred fluid value, maximum).

02
Worked example

Scale text from 16px to 32px between 320px and 1280px

The slope is 1.6667vw and the intercept is 10.6667px, producing clamp(16px, 10.6667px + 1.6667vw, 32px). At 320px the result is 16px; at 1280px it is 32px.

03
Implementation

Copyable code examples

Use these examples as a starting point, then match the values and assumptions to the rendered project.

CSS
.heading {
  font-size: clamp(1rem, 0.6667rem + 1.6667vw, 2rem);
}
CSS custom properties
:root {
  --step-fluid: clamp(1rem, 0.6667rem + 1.6667vw, 2rem);
}

h1 { font-size: var(--step-fluid); }
JavaScript
const slope = (maxSize - minSize) / (maxWidth - minWidth);
const vw = slope * 100;
const intercept = minSize - slope * minWidth;
04
Practical guidance

Using the result accurately

Choose viewport bounds that reflect the layout rather than device names. Test the generated value at the minimum, midpoint, maximum, and with browser zoom. For text, keep line height and measure readable as font size changes.

Important limitation

A mathematically fluid font size is not automatically accessible. Very small minimums, extreme scaling, fixed-height containers, and viewport-only sizing can still cause readability or overflow problems.

References: W3C CSS Values and Units Level 4: comparison functions.

Common questions

CSS Clamp Generator FAQ

Answers about the method, assumptions, and practical use.

What does CSS clamp() do?

clamp() accepts a minimum, a preferred value, and a maximum. The browser uses the preferred value while keeping it between the two limits.

Can I use the result for spacing as well as font size?

Yes. A compatible clamp() length can be used for padding, margin, gap, width, and other CSS properties that accept length values.

Why provide a root font size?

The root font size is needed to express the fixed parts of the formula in rem. A common default is 16px, but projects and user settings can differ.

Should fluid text use only viewport units?

No. Combining a relative fixed unit such as rem with a viewport term preserves scaling while avoiding a value controlled only by viewport width.