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.
Related tools
The golden ratio calculator gives proportions for layouts and the screen size calculator relates a display’s diagonal, width and height.