Skip to content
Omnikalc

Fluid typography calculator: build a CSS clamp() font size

Enter the smallest and largest font sizes and the viewport widths where they apply to get the slope, the intercept and the rem values for a CSS clamp(), with a test width.

Updated on
Your inputs
px

Value out of range

px

Value out of range

px

Value out of range

px

Value out of range

px

Value out of range

px

Value out of range

Results

Slope of the fluid part

0.8333 vw

Intercept of the fluid part
0.8333 rem
Smallest size in rem
1.0000 rem
Largest size in rem
1.5000 rem
Font size at the tested width
20.00 px

Setting a font size for each breakpoint takes many rules and still jumps when the screen crosses a boundary. This fluid typography calculator takes the smallest and largest sizes and the viewport widths where they apply to give the slope in vw, the intercept in rem, the minimum and maximum in rem for a CSS clamp(), and the size at any width you test.

How the calculation works

  • A fluid size grows in a straight line between two viewport widths. The slope = (largest size − smallest size) ÷ (largest width − smallest width) × 100, in vw units.
  • The intercept = smallest size − slope ÷ 100 × smallest width. Divide it by the root font size to get rem.
  • The CSS is clamp(min, intercept + slope vw, max), with the minimum and maximum in rem. The size never goes below the minimum or above the maximum.
  • The size at a tested width = intercept + slope × width ÷ 100, held between the minimum and the maximum.

Example

You want text to grow from 16 px at 320 px wide to 24 px at 1,280 px. The slope is (24 − 16) ÷ (1,280 − 320) × 100 = 0.8333 vw. The intercept is 16 − 0.008333 × 320 = 13.33 px, or 0.8333 rem. The CSS is clamp(1rem, 0.8333rem + 0.8333vw, 1.5rem). At a width of 800 px, the size is 13.33 + 0.008333 × 800 = 20 px.

Why it matters

Fluid type adapts to phones, tablets and large monitors with one line of CSS. It reduces the code, makes the text feel right at every width and works well with a type scale or a spacing scale.

Good to know

The widths must be different, with the smallest below the largest. Keep the maximum within a sensible multiple of the minimum, since text that more than doubles can break layouts. Always include a rem part in the preferred value. Line length should be checked too, because larger type at a wide viewport can make lines shorter than planned. Test at several widths and at 200% zoom.

The golden ratio calculator gives proportions for layouts and the screen size calculator relates a display’s diagonal, width and height.

Frequently asked questions

What is fluid typography?

Fluid typography makes the font size grow smoothly with the width of the viewport, instead of jumping at breakpoints. With the CSS clamp() function, you set a minimum, a preferred value that depends on the viewport width, and a maximum. The text then scales up and down on every screen size.

How does the clamp() formula work?

The preferred value is a rem part plus a vw part, for example 0.8333rem + 0.8333vw. The vw part grows with the screen and the rem part fixes where the line starts. The slope sets the speed of the growth, and the minimum and maximum stop the size outside the two widths.

Why add a rem part and not only vw?

A size in vw alone ignores the user's font size, so people who enlarge the text in the browser see no change. Adding a rem part keeps some response to the user's setting, and it is recommended for accessibility. Test with the zoom at 200% to check that the text grows.

Which widths and sizes should I choose?

Common choices are 320 px for the smallest phones and 1,200 to 1,440 px for desktops. The sizes depend on the design, for example 16 to 20 px for body text and 28 to 56 px for the main heading. Use a smaller range for body text and a wider one for display text.

Was this calculator helpful?

Thanks for your feedback!

Results are estimates provided for information purposes. They do not replace professional advice.