vasilenko.info

clamp() generator for fluid typography

/en/tool/clamp-generator/ works calculated in the browser

Set the size for a narrow and a wide screen, specify the widths between which it should grow, and get a clamp() expression instead of three media queries. You can also generate a complete scale: heading font sizes based on a modular ratio or a spacing set from 3xs to 3xl.

promoTwenty years of notes on websitesHow we did it in 2008 and what still works today.Open

clamp() expression calculator

Between two widths, the size changes linearly; outside them, it hits the bounds.

What to calculate

One value — one line. A type scale is a set of variables --step--2 … --step-5 based on a modular ratio.

Type-size pairs from a typical layout — click to fill them in
Layout width and the size at that width, separated by a colon; two pairs separated by a comma. Fills all four fields at once. Three pairs enable the breakpoint.
Lower bound: it will not get smaller than this
Upper bound: it will not get larger than this
Usually the narrowest phone you support
Usually the width of your container, not the monitor
Use this when the size should grow faster from phone to tablet than from tablet to desktop. The output uses min() or max() inside clamp().
The arithmetic based on the property stays the same — only its name in the final string changes
Only needed for conversion to rem
Units in the final string
Scale unit

The sample, the current value, and the chart marker follow the slider: there is no need to drag the browser by its corner.

In your current window

px

The accessibility check is included with the string.

Sample

This sample uses the same value

What to copy
clamp.css ready-to-use CSS

The browser does the calculation. No numbers or final strings are sent anywhere: the file is built right on your device, and the share link is stored in the address bar.

Chart and table

Horizontally, the width ranges from 320 to 2560 px; vertically, the size is shown in pixels. The flat sections on the left and right indicate that the value has reached a limit.

The chart uses the same numbers as the table.

Breakpoint width
promoCalculate ROI at the same timeCampaign payback based on spend and revenue.Open

How to use it

  1. Take two sizes from the design: the phone size and the desktop size. The “Parse” button accepts them in a single string such as 375:20, 1440:48—the four fields will be filled in automatically.

  2. Use the widths where the designs were created. Set the lower width to the narrowest supported screen and the upper width to the container width, not the monitor width.

  3. Need all the typography at once? Switch to “Font size scale”: the base font size, the ratio on narrow and wide screens, and the number of steps up and down. The result is a set of --step--2 … --step-5 variables. “Spacing scale” works the same way and produces --space-3xs … --space-3xl and pairs such as --space-s-m.

  4. Keep rem units: the rem term is required. A string containing only vw does not respond when the font size is increased in the browser settings. The “Accessibility” section shows how many times the text grows when the base font size is doubled and at 200% zoom.

  5. The “Preview width” slider moves the entire view: the sample, the “Current” value, and the marker on the chart. The button next to it restores the actual viewport width.

  6. The tabs below the code provide the same result in six formats: a CSS string, variables in :root, SCSS, PostCSS with separate min and max values, JSON tokens, and a Tailwind config snippet. The “Download file” button saves the selected tab.

  7. The “Copy link” button puts the entire configuration into the URL. You can send the link in a chat, and your colleague will see the same scale.

promoBrowser task listNo account required—everything is stored on your device.Open

The formula and what it includes

clamp(min, slope × 100 vw + offset, max), where slope = (max − min) ÷ (max width − min width)

The middle clamp() argument is an ordinary value, not a separate mode: the browser recalculates it at every width and clips it to the limits. Media queries are not needed. A scale is calculated the same way; the output simply contains one string for each step. Each step has its own min and max values, while the widths are shared.

Example breakdown: from 16 px to 32 px between 400 px and 1200 px

The input data is the same as the default field values: you can calculate it mentally and confirm that the tool is telling the truth.

  1. Slope: (32 − 16) ÷ (1200 − 400) = 16 ÷ 800 = 0.02.

  2. vw coefficient: 0.02 × 100 = 2. That is, 2vw.

  3. Offset: 16 − 0.02 × 400 = 16 − 8 = 8 px. In rem, that is 8 ÷ 16 = 0.5rem.

  4. rem limits: 16 ÷ 16 = 1rem and 32 ÷ 16 = 2rem.

  5. Check at 400 px: 0.5rem is 8 px, 2vw is 8 px, and the sum is 16 px. Check at 1200 px: 8 + 24 = 32 px.

  6. Accessibility at 1280 px. Normally, 8 + 25.6 = 33.6 px there, but the maximum clips it to 32. The reader sets the base font size to 32 px instead of 16, so all rem values double: 16 + 25.6 = 41.6 px, with a maximum of 64. It was 32 and is now 41.6—that is 130%, not 200%, so WCAG 1.4.4 is not met. The tool shows this value immediately: to reach double the size, increase the upper limit or reduce the vw portion.

font-size: clamp(1rem, 0.5rem + 2vw, 2rem);

Frequently asked questions

promoAll toolsForty-four tools, all running in your browser.Open

Related tools

5