About the CSS Clamp Generator
This tool makes a clamp() CSS expression for fluid font sizes or spacing. You give smallest and largest sizes, two viewport widths, and a root font size. The tool computes slope and intercept, shows CSS, an example rule, and the computed size at 375px and 768px. Everything runs in your browser. Nothing is uploaded to a server. Results update as you type, and you can copy the CSS or share a link that reopens with your numbers. Designers and front-end developers use it to replace many breakpoint-only rules with a single fluid value. Compared with complex generators, this tool focuses on clear math, instant results, rem conversion, and privacy. It also shows the exact sizes at chosen viewports so you can test accessibility and zoom behavior.
How to use it
- 1Enter the smallest size in px.
- 2Enter the largest size in px.
- 3Set the from and to screen widths in px and the root font size in px.
- 4Choose output unit (rem or px). Results update instantly; copy or share the generated CSS.
Worked example
Inputs: Smallest size = 16px, Largest size = 24px, From screen width = 320px, To screen width = 1280px, Root font size = 16px. Computation: slope = (24−16)/(1280−320) = 0.0083333333 px per px. intercept = 16 − 0.0083333333×320 = 13.3333333333 px. Preferred = 13.3333333333px/16 + (0.0083333333×100)vw = 0.833333rem + 0.833333vw. CSS rule: font-size: clamp(1rem, 0.833333rem + 0.833333vw, 1.5rem); Size at 375px: 16.458333px (1.028646rem). Size at 768px: 19.733333px (1.233333rem).
How it works
slope = (largest - smallest) / (to width - from width)The preferred value is intercept + slope x 100vw, where intercept = smallest - slope x from widthclamp(smallest, preferred, largest) then grows smoothly between the two screen widths and stays fixed outside themrem values are px divided by the root font sizeResults update instantly as the visitor types; there is no calculate buttonVisitors can copy the result and share a link that reopens with their numbersSource: W3C CSS Values and Units Module Level 4 (clamp)MDN Web Docs: clamp(). Last checked 7 November 2026.
What it is good for
- Produces a single clamp() line you can paste into CSS.
- Shows the math and sizes at example viewports for quick testing.
- Runs client-side only, so nothing is uploaded and results update instantly.
- Does not replace layout changes that need media queries.
- It outputs size values only; it does not export Tailwind tokens or CSV.
Questions people ask
What does clamp() do?
clamp(min, preferred, max) ensures a value never goes below min or above max. The preferred value can use rem and vw so size scales smoothly between two viewports.
Should I use rem or px in the outputs?
Use rem for min and max if you want to respect user font settings. px is okay for fixed decorative sizes, but rem improves accessibility and zoom behavior.
Will this replace media queries?
No. clamp() replaces many size-only breakpoints, but you still need media queries for layout or structural changes. Use clamp() for fluid sizes and media queries for layout shifts.
How do you calculate the preferred term?
The tool computes slope = (largest − smallest) / (to − from). Then intercept = smallest − slope×from. Preferred becomes intercept/root rem + slope×100vw.
Is clamp() supported in browsers?
Modern Chrome, Firefox, Safari, and Edge support clamp(). Check MDN for specific versions and edge cases before relying on it in older browsers.
Will clamp() break text zoom or WCAG Resize Text?
It can if you rely only on viewport units. Use a rem component, test at 200% zoom, and keep max not excessively larger than min to meet Resize Text guidance.
Help keep every tool free
FreeToolr stays free because people help it grow. Share a tool you like, tell us what to build next, or support us on Ko-fi.