CSS Clamp Generator
Enter the smallest size, the largest size and the two viewport widths between which the size should grow, and get a ready-to-paste clamp() value for font-size, padding, margin or any length. A slider previews the size at any viewport width, a table lists it at common widths, and a second box reads an existing clamp() and tells you the size at a width you choose. Everything runs in your browser.
The quick brown fox
| Viewport | Size in px | Size in rem |
|---|---|---|
| 320px | 16 | 1 |
| 375px | 16.23 | 1.014 |
| 480px | 16.67 | 1.042 |
| 768px | 17.87 | 1.117 |
| 1024px | 18.93 | 1.183 |
| 1280px | 20 | 1.25 |
| 1440px | 20 | 1.25 |
| 1920px | 20 | 1.25 |
Read an existing clamp()
A fluid size uses clamp(min, preferred, max): the browser uses the preferred value but never goes below the minimum or above the maximum. The preferred value is a straight line through the two points you give, with a part in rem and a part in vw, so the size is exactly the smallest size at the smallest viewport and the largest size at the largest. Mixing rem into the preferred value keeps the text responsive to the visitor's own font size setting, which a value made of vw alone does not. Rem sizes are converted with the root font size, 16px by default. Everything is worked out in your browser and nothing is uploaded.
Related Tools
[5 suggestions]PX to REM Converter
Convert px to rem, em, pt, pc, vw and percent for CSS, with your own root font size, parent size and viewport width.
Developer & WebCSS Gradient Generator
Design linear, radial and conic CSS gradients with any number of colour stops, preview them live and copy the CSS.
Developer & WebCSS Shadow Generator
Design box-shadow, text-shadow and drop-shadow with several layers, preview them live and copy the CSS.
Developer & WebAspect Ratio Calculator
Find the aspect ratio of any width and height, resize while keeping it, and get the CSS aspect-ratio rule.
Developer & WebCSS Specificity Calculator
Work out the specificity score of any CSS selector, see which part adds what, and find which of several selectors wins.
Developer & WebAbout the CSS Clamp Generator
A fluid size uses clamp(min, preferred, max): the browser follows the preferred value but never goes below the minimum or above the maximum. The preferred value here is a straight line through two points: the smallest size at the smallest viewport width and the largest size at the largest. The slope is the change in size divided by the change in width, which gives the vw part, and the starting point at zero width gives the rem part. For 16px growing to 20px between viewports of 320px and 1280px, that is clamp(1rem, 0.9167rem + 0.4167vw, 1.25rem), and at an 800px viewport the size is exactly 18px. The tool takes sizes in px or rem, converts rem with the root font size (16px by default), rounds to four decimals, and also writes the same value in px for tools that do not take rem. A size that shrinks as the viewport grows is handled too, with the smaller size always written first because clamp() needs its minimum below its maximum. Using rem in the preferred value, and not vw alone, keeps text responsive to the visitor's own font size setting. The reading box accepts values made of px, rem and vw, including calc(). Nothing is uploaded.
How does clamp() work in CSS?▾
clamp(min, preferred, max) returns the preferred value, limited to the range from min to max. With a preferred value that uses vw, the size changes smoothly with the viewport width and stops at the two limits.
How do I make fluid typography?▾
Choose the smallest and largest font sizes and the viewport widths where each should apply, and enter them in the tool. For 16px at 320px and 20px at 1280px it gives clamp(1rem, 0.9167rem + 0.4167vw, 1.25rem). Paste it into font-size.
Why does the preferred value use both rem and vw?▾
The vw part makes the size follow the viewport, and the rem part sets the starting point. Because rem scales with the user's font size setting, the text still grows when a visitor zooms or raises their default size. A value made of vw alone does not.
Can I use it for padding and margins?▾
Yes. A clamp() value is a length, so it works anywhere a length does: padding, margin, gap, width and font-size.
Does the tool send my values anywhere?▾
No. The calculation runs in your browser and nothing you enter is uploaded.