CSSNew

CSS Clamp Calculator for Fluid Typography

Calculate fluid clamp() values from min and max sizes and viewports, with a fluid type scale mode

100% client-side — your data never leaves your browserNo data stored or uploadedFree for lifetime · No signup
Presets
CSS
font-size: clamp(1rem, 0.6667rem + 1.6667vw, 2rem);
Slope
1.6667vw
Intercept
0.6667rem (10.67px)

slope = (32 − 16) ÷ (1280 − 320); intercept = 16 − slope × 320. The rem lower and upper bounds let user font-size settings scale the result.

Fluid heading

At 800px wide this clamp() resolves to 24px.

What clamp() does and the maths behind it

clamp(MIN, PREFERRED, MAX) returns the preferred value but never lets it go below MIN or above MAX. For fluid typography the preferred value mixes a fixed part and a viewport part, such as 0.6667rem + 1.6667vw, so text grows smoothly as the screen widens and stops growing at the limits, with no media queries and no jumps between breakpoints.

This css clamp calculator works out the preferred value from four numbers: the size you want at the smallest viewport, the size at the largest viewport, and those two viewport widths. It draws a straight line between the two points. The slope is (max size - min size) / (max viewport - min viewport). The intercept is min size - slope × min viewport. Because 1vw is 1% of the viewport width, the slope is multiplied by 100 to express it in vw, and the intercept is divided by the root font size to express it in rem.

Worked example: 16px at a 320px viewport growing to 32px at 1280px. Slope = 16 / 960 = 0.016667, which is 1.6667vw. Intercept = 16 - 0.016667 × 320 = 10.667px, which is 0.6667rem at a 16px root. The result is clamp(1rem, 0.6667rem + 1.6667vw, 2rem). At 800px wide that gives 10.667 + 13.333 = 24px, exactly halfway, which you can confirm with the viewport slider.

The minimum and maximum are written in rem and the intercept includes a rem part, so the size still responds when a user increases their browser's default font size. A value built only from vw would ignore that setting, which is an accessibility problem because WCAG 1.4.4 expects text to scale to 200%. Even with clamp(), a large ratio between max and min can limit how far zoom enlarges text, so keep the range moderate for body copy. If the larger size is the smaller one, for example a heading that should shrink, the calculator writes a negative slope and keeps MIN and MAX in the right order.

Using the preview, units and type scale

Enter sizes in px or rem with the toggle; both are converted using the root font size field, which defaults to 16px. The CSS property field changes only the label in the output, so you can use the same clamp() for margin, padding, gap or width as well as font-size. The presets cover body text, headings, a hero title and fluid section padding.

Drag the simulated viewport slider to see what the value resolves to at any width. The preview box narrows with the slider and shows the computed pixel size, which is the quickest clamp font size check before you put it into a stylesheet.

Fluid type scale mode builds a whole modular scale. Set the base size at each end of the range and choose a ratio for small screens and a usually larger ratio for wide screens, such as Minor third (1.2) and Major third (1.25). Each step n is base × ratio to the power n, calculated separately for the minimum and maximum viewport, and turned into its own clamp(). The output is a set of CSS custom properties from --step-n2 to --step-5, ready to assign to body text, h1 to h6 and small print.

How to use the CSS Clamp Calculator for Fluid Typography tool

  1. 1

    Enter the size range

    Type the size you want at the smallest and largest viewport, in px or rem, or pick a preset.

  2. 2

    Set the viewport range

    Enter the minimum and maximum viewport widths in px, and your root font size if it is not 16px.

  3. 3

    Check it in the preview

    Drag the simulated viewport slider to see the resolved size at any screen width.

  4. 4

    Copy the clamp()

    Copy the single declaration, or switch to Fluid type scale and copy the full set of custom properties.

Frequently asked questions

How do I calculate a clamp() value for font size?

Compute slope = (maxSize - minSize) / (maxViewport - minViewport) and intercept = minSize - slope × minViewport, then write clamp(minSize, intercept + slope × 100vw, maxSize), converting px to rem by dividing by 16. This tool does the arithmetic for you.

Why use rem in clamp() instead of px?

rem values scale with the user’s default font size setting, so people who enlarge text in their browser still get larger text. A clamp() with only px and vw would ignore that preference.

Is CSS clamp() supported in all browsers?

Yes. clamp() is supported in all current versions of Chrome, Edge, Firefox and Safari, and has been for several years.

What viewport widths should I use?

Common choices are a minimum around 320 to 375px for small phones and a maximum around 1200 to 1440px, roughly where your content column stops growing. Outside that range the size stays at the minimum or maximum.

Can I use clamp() for spacing as well as typography?

Yes. clamp() works with any length property, including padding, margin, gap and width. Change the CSS property field and use the same calculation for fluid spacing.

Related on TechLogHub

Get the next tool before you need it

One email a week: new and trending developer tools, fresh comparisons, and what shipped. Unsubscribe in one click.