CSS Clamp Calculator
Turn a minimum and maximum size plus two viewport widths into a fluid CSS clamp() value, with the slope, intercept and computed size at seven screen widths.
Fluid size
Generated CSS
font-size: clamp(1rem, 0.8333rem + 0.8333vw, 1.5rem);
Computed size at common viewport widths
| Viewport | Linear value | Rendered size | Branch |
|---|---|---|---|
| 320px | 16.00px | 16.00px | held at minimum |
| 480px | 17.33px | 17.33px | scaling |
| 768px | 19.73px | 19.73px | scaling |
| 1024px | 21.87px | 21.87px | scaling |
| 1280px | 24.00px | 24.00px | held at maximum |
| 1440px | 25.33px | 24.00px | held at maximum |
| 1920px | 29.33px | 24.00px | held at maximum |
Preview at a 1024px viewport
The quick brown fox jumps over the lazy dog
Rendered at 21.87px — the value your clamp() resolves to on a 1024px-wide screen.
What is the CSS Clamp Calculator?
The clamp() function lets one declaration cover every screen size: a floor, a value that scales with the viewport, and a ceiling.
- Exact slope and intercept, both shown alongside the result
- rem or px output with a configurable root font size
- Table of computed sizes at 320 to 1920 pixels
- Marks whether each width is scaling or held at a limit
- Works for padding, gap, width and other properties, not just font-size
- Guards against identical viewport widths instead of dividing by zero
How to use the CSS Clamp Calculator
- 1
Enter the minimum size and the viewport width where it should apply.
- 2
Enter the maximum size and the viewport width where it should stop growing.
- 3
Set the root font size, and choose rem or px for the output.
- 4
Pick the CSS property you are generating the value for.
- 5
Check the table of computed sizes, then copy the declaration.
About the CSS Clamp Calculator
The clamp() function lets one declaration cover every screen size: a floor, a value that scales with the viewport, and a ceiling. The hard part is the middle term, which has to be a straight line passing through both of your chosen points. This calculator works it out and shows you the arithmetic.
The slope is the change in size divided by the change in viewport width, and the intercept is what that line would be at a viewport of zero. Multiplying the slope by 100 turns it into a vw unit. With a 16px minimum at 320px and a 24px maximum at 1280px you get clamp(1rem, 0.8333rem + 0.8333vw, 1.5rem), which lands exactly on 16 and 24 at the endpoints.
A table shows what the value resolves to at seven common widths and whether it is scaling or being held at a limit. Everything is calculated in your browser and nothing is uploaded.
Frequently asked questions
How does CSS clamp work?
clamp() takes three values: a minimum, a preferred value, and a maximum. The browser uses the preferred value unless it falls outside the other two, in which case it uses whichever bound it crossed. Making the preferred value depend on vw is what produces fluid scaling.
How do you calculate the vw value for clamp?
Divide the difference in sizes by the difference in viewport widths to get the slope, then multiply by 100 for the vw coefficient. The rem part is the minimum size minus the slope times the minimum viewport width. This tool shows both numbers so you can check the working.
Why should the clamp value include a rem term?
Because a preferred value made only of vw units ignores the user's browser font size setting, which fails WCAG success criterion 1.4.4 on resizing text. Including a rem component means the text still responds to zoom and to a larger default size.
Can I use clamp for padding and margins too?
Yes, and it is one of the best uses for it. Fluid spacing keeps the proportions of a layout consistent as the screen grows, rather than jumping at breakpoints. The property dropdown here covers padding, margin, gap, width, height, border-radius and letter-spacing.
What viewport widths should I use as the endpoints?
320px is a sensible floor since it covers the smallest phones still in use, and somewhere between 1280 and 1440 is a common ceiling. Setting the maximum too high means most desktop users never see your maximum size, because the value is still climbing at their screen width.
Related tools
Type Scale Generator
Build a modular type scale from a base size and ratio, with line heights snapped to a baseline grid, exported as CSS variables, Sass, Tailwind config or JSON.
Cubic Bezier Generator
Drag two control points to build a cubic-bezier() easing curve, preview it on a moving dot, and copy the CSS timing function straight into your stylesheet.
Gradient Text Generator
Create gradient text in CSS with background-clip, an animated shimmer option, a solid-colour fallback and a live contrast check on light or dark backgrounds.
CSS Grid Generator
Design CSS grid layouts visually with column and row counts, gap control and a live grid preview. Copy clean grid-template CSS ready for your stylesheet.
CSS Flexbox Generator
Build flexbox layouts visually with controls for direction, justify-content, align-items, wrap and gap. Live preview of the boxes and copy-ready CSS.