CSS Clamp Calculator
Generate fluid, responsive clamp() values for any CSS property
This CSS Clamp Calculator is a precision tool for generating fluid, responsive clamp() values, no guesswork required.
Last updated: September 23, 2026
Paste the output directly into your stylesheet. It handles the math: slope, intercept, viewport scaling. You define the boundaries; it builds the expression.
What it does:
-
Generates
clamp(min, preferred, max)with full syntax highlighting -
Outputs an equivalent
max()/min()expression, useful for Safari 11.1 to 13.0, which supported min() and max() before clamp() -
Converts between
pxandremautomatically, respecting your root font size -
Shows exact values at every major breakpoint (320px → 1920px)
-
Renders a live value-curve graph so you can see the fluid transition visually
-
Includes 8 presets (Body, H1–H3, Caption, Gap S/M/L) for instant starting points
Why it matters:
Fluid typography and spacing done manually is error-prone. One formula, locked in. The calculator validates your inputs, warns on inverted ranges, and lets you copy either the property declaration or the raw value with a single click.
Works entirely in the browser. No build step, no accounts.
What Is CSS Clamp?
CSS clamp is a native CSS math function that constrains a value between a set minimum and maximum, with a fluid middle value that scales with the viewport.
It takes three arguments: clamp(MIN, PREFERRED, MAX).
The browser picks the preferred value until it hits either boundary. Below the minimum, the minimum wins. Above the maximum, the maximum takes over.
No media queries needed. One line of CSS handles the full range.
How Does the CSS Clamp Calculator Work?
Enter your min value, max value, and viewport breakpoints. The calculator outputs a ready-to-copy clamp() declaration instantly.
Most people skip doing this by hand. The math involves linear interpolation and vw slope calculations, and it's tricky to get right without a tool.
Inputs the Calculator Needs
-
Minimum value: the smallest the property should ever be (px or rem)
-
Maximum value: the upper cap
-
Minimum viewport width: where scaling starts
-
Maximum viewport width: where scaling stops
What the Calculator Outputs
A complete clamp() declaration with the correct vw-based middle argument.
It also shows the calculated slope and the rem-converted intercept, useful if you're building a design system and need to trace where each value comes from.
The Math Behind the Output
The calculator uses a linear interpolation formula to find two things: the slope (in vw) and the intercept (in rem).
Slope = (maxValue − minValue) / (maxViewport − minViewport)
That slope becomes the vw portion of the preferred argument. The intercept shifts the line so it passes through your min and max points at the right viewport widths.
With the defaults (16px to 24px between 320px and 1440px viewports), the slope is 8 ÷ 1120 = 0.00714, or 0.7143vw, and the intercept is 16 − 0.00714 × 320 = 13.71px (0.8571rem). The output reads clamp(1rem, 0.7143vw + 0.8571rem, 1.5rem).
What Is a CSS Clamp Calculator?
A CSS clamp calculator is a browser-based utility that turns a minimum size, a maximum size, and two viewport widths into a single ready-to-paste clamp() declaration.
It exists to remove the manual math behind fluid sizing in CSS, the language that controls how text and spacing render across devices.
The tool itself is not part of any browser or specification. It sits on top of a native function that already ships in every modern rendering engine.
Two separate things:
- The calculator: a page with input fields and a generated output string
- The clamp() function: the actual CSS syntax the calculator writes for you
Tools like Utopia.fyi took this further and generate a full fluid type scale instead of one isolated value.
Type a font size range into one of these tools and working CSS comes back in seconds, no slope math required by hand.
CSS Clamp Function Syntax and Required Parameters
The clamp() function takes exactly three comma-separated arguments, in a fixed order: minimum, preferred, maximum.
- Minimum value: the floor, used whenever the preferred value would drop below it
- Preferred value: the value the browser tries to use, usually a viewport-based expression
- Maximum value: the ceiling, used whenever the preferred value would climb above it
Each argument can be a length, a percentage, or another math function such as calc(), min(), or max().
Setting the minimum higher than the maximum is a common authoring mistake. Per the specification, the minimum wins and the maximum is ignored, which looks like a broken function when the real problem is argument order.
Once generated, the string drops straight into a property value the same way any other size would, for example font-size: clamp(1rem, 2.5vw, 2rem);
How the Clamp Formula Calculates the Preferred Value
The preferred value inside clamp() is almost always a small linear interpolation problem, two points connected by a straight line.
A calculator runs this automatically using the two viewport widths supplied, so nobody has to work out the slope by hand every time a design changes.
Calculating the Slope Between Minimum and Maximum
The slope is the rate of change between the smallest size at the smallest viewport width and the largest size at the largest viewport width.
The inputs needed:
- Minimum font size, at the minimum viewport width
- Maximum font size, at the maximum viewport width
- Minimum viewport width
- Maximum viewport width
Subtract the two sizes, subtract the two widths, then divide the first result by the second. That number becomes the multiplier attached to the viewport unit in the final declaration.
Converting the Slope Into a calc() Expression
The slope value never stands alone. It gets multiplied by a viewport unit and added to a fixed rem offset.
That fixed offset is the y-intercept, the value the line would hit at zero viewport width, even though no real browser renders at that width.
A typical result reads calc(1rem + 1.5vw), the fluid half of the clamp() declaration.
Browsers resolve that expression on every reflow rather than once at page load, which is why the text keeps scaling as the window resizes.
Units a CSS Clamp Calculator Supports: px, rem, em and vw
Most calculators accept px as an input and quietly convert it to rem before running the formula, since rem is what actually respects a user's browser settings.
Firefox has supported clamp() since version 75, shipped in April 2020 (MDN), and every major engine now treats these four units the same way inside the function.
Why rem Is the Recommended Unit for Font Size
rem is relative to the root font-size, the base size set on the html element, usually 16px by default.
Change that root size through a browser setting and every rem-based clamp value scales with it automatically.
What px does differently:
- px stays fixed no matter what the user changes
- em compounds against a parent's font-size, which gets messy inside nested components
The difference between pixel and rem sizing matters most in this exact spot, since a clamp() built on px silently opts a page out of that scaling behavior.
What vw Contributes to the Fluid Part of the Formula
Quick reference:
- 1vw equals 1% of viewport width
- 100vw equals the full width of the browser viewport
vw ties a value to that viewport width, which is what gives clamp() its smooth, non-stepped scaling.
Without it, the preferred value would just be another fixed number, and the fluid part of the formula disappears entirely.
Calculators built around CSS's viewport-based units handle this conversion so nobody has to remember the percentage math by hand.
Clamp() Compared to calc(), min() and max()
clamp() is not really a fourth function so much as shorthand for the other three working together.
MDN documents the relationship directly: clamp(MIN, VAL, MAX) resolves to max(MIN, min(VAL, MAX)), so the browser runs a small nested comparison whenever the value is computed.
| Function | Arguments | Bound Behavior | Typical Use |
|---|---|---|---|
| calc() | One expression | No bound, pure arithmetic | Combining mixed units |
| min() | Two or more | Caps at the smallest | Setting a maximum only |
| max() | Two or more | Floors at the largest | Setting a minimum only |
| clamp() | Exactly three | Bounded both sides | Fluid typography and spacing |
Reach for calc() alone when nothing needs capping. Adding a bound where none is needed just adds complexity for nothing.
Reach for min() or max() when only one side of the range matters, a maximum width on an image, for instance, with no floor required.
When to Use Clamp() Instead of Media Queries
A handful of fixed breakpoints stop covering real device widths fast. Phones alone now ship in dozens of different viewport sizes.
Every time a new width falls between two breakpoints, someone has to add another media query and test it, which is exactly the maintenance cost clamp() removes.
When each approach wins:
- Clamp() wins for scaling a single value smoothly: font size, padding, a max-width
- Media queries still win for restructuring layout: switching a grid from one column to three, hiding a sidebar
- Combining both is normal in production: clamp() for scaling, media queries for structural shifts
Andy Bell's fluid type tutorial on Piccalil.li builds an entire type system from clamp() and CSS custom properties, skipping breakpoint-based font sizing altogether.
The two approaches are not mutually exclusive inside the same stylesheet. Most production sites still lean on responsive design patterns with breakpoints for layout shifts, while letting clamp() handle whatever scales continuously in between.
rem or px: Choosing Units for Accessible Clamp Values
rem is the safer default for clamp() values tied to text, because it responds to a user's browser font-size setting and px does not.
Web Content Accessibility Guidelines, Success Criterion 1.4.4, requires that text stay readable and functional at 200% zoom without loss of content (W3C, WCAG 2.1).
MDN's own clamp() documentation reflects that requirement directly, recommending the maximum bound be at least twice the minimum whenever clamp() controls font size.
In WebAIM's 2018 Survey of Users with Low Vision, 44.0% of respondents reported using browser zoom controls and 36.7% used browser text-sizing settings specifically, two mechanisms that behave differently depending on the unit chosen.
Choosing between the two units is also a matter of web accessibility compliance, not just visual preference.
rem: Pros and Cons for Clamp Values
Pros:
- Scales with the user's browser text-size setting
- Matches WCAG's resize-text expectations out of the box
- Keeps a consistent ratio to the root font-size across the page
Cons:
- Requires checking that the root font-size has not been reset by a CSS reset
- Slightly less intuitive for designers used to thinking in pixels
Most guidance on accessible typography settles on rem as the default unit for exactly this reason.
px: Pros and Cons for Clamp Values
Pros:
- Predictable, pixel-for-pixel output across every browser
- Easier to match a design file that specifies exact pixel values
Cons:
- Ignores a user's browser text-size setting entirely
- Can fail WCAG's 200% resize requirement on its own
- Offers no real advantage over rem once the root font-size is left at its default
Reserve px-based clamp() values for non-text properties, a border width or a fixed icon size, where accessibility scaling was never the goal.
Browser Support for the Clamp Function
clamp() runs in every browser still receiving updates, and has for years.
Can I Use puts global browser support at 96.25% as of August 2026, combining desktop and mobile usage share from StatCounter GlobalStats.
Key figures:
- Global support: 96.25% of tracked browser usage (Can I Use, StatCounter GlobalStats, August 2026)
- Baseline status: available across browsers since July 2020, Widely Available since January 2023 (web-features project, cited via MDN)
- Chrome: supported from version 79, released December 2019 (Can I Use)
- Safari: supported from version 13.1, released March 2020 (Can I Use)
Edge picked up support a month later with version 79 in January 2020, its first release on the same Blink engine as Chrome.
The remaining gap sits almost entirely with old Android WebView installs and a shrinking pool of enterprise browsers still locked to pre-2020 builds.
That gap is exactly what cross-browser compatibility planning needs to account for on any project still supporting those environments.
Calculating a Fluid Clamp Value Step by Step
A calculator automates this, but running it manually once makes the output easier to trust and debug later.
- Pick the minimum font size and the viewport width it applies at
- Pick the maximum font size and the viewport width it applies at
- Subtract the two sizes, subtract the two widths, then divide the first result by the second to get the slope
- Multiply the slope by 100 to convert it into a vw coefficient
- Solve for the y-intercept: minimum size minus slope times minimum width
- Assemble the three arguments into
clamp(min, coefficient vw + intercept, max)
Check the result at both ends of the range before shipping it. The value should land exactly on the minimum at the smallest width and exactly on the maximum at the largest.
A common mistake here is writing the coefficient as a percentage. It needs the vw unit, as in 0.7143vw, since a percentage inside font-size resolves against the parent font size, not the viewport.
Tools That Generate Clamp Values Automatically
A calculator saves the arithmetic. What separates one tool from another is what happens after the CSS is generated.
| Tool | Output Format | Scale Generation | Build Step Needed |
|---|---|---|---|
| Basic clamp calculator | Single clamp() value | No | No |
| Fluid Type Scale Calculator | CSS variables, rem or px | Yes, full type scale | No |
| postcss-clamp | min()/max() fallback | No | Yes, PostCSS |
| Sass fluid mixins | Precompiled clamp() rules | Optional | Yes, Sass |
Aleksandr Hovhannisyan's open-source Fluid Type Scale Calculator generates an entire set of named font-size variables instead of one isolated value, ready to drop into an existing design system.
Teams still supporting older browser builds sometimes add postcss-clamp, a PostCSS plugin that rewrites clamp() into a min()/max() combination at build time rather than at runtime. That only helps browsers that shipped min() and max() before clamp(), mainly Safari 11.1 to 13.0.
Sass never had native fluid math, so any equivalent there was always a hand-written mixin doing the same slope calculation the calculator does automatically.
When Clamp() Does Not Work or Should Be Avoided
clamp() is not always the right tool. A few situations call for something else entirely.
Where it falls short:
- Legacy projects still supporting Internet Explorer, which never received clamp() at any version (Can I Use)
- Layouts that need a hard jump at a specific breakpoint rather than a smooth scale, a sidebar that should disappear entirely below 768px, for instance
- Values where the minimum and maximum sit close enough together that a fixed size would look identical, adding clamp() there is complexity without a visible payoff
- Properties where a design file specifies exact pixel values with no tolerance for scaling, like a fixed-size logo mark
Reversing the argument order is the most common authoring mistake, setting the maximum where the minimum belongs.
The declaration will not error. It will just silently return the wrong number.
Mixing length units such as px, rem, and vw across the three arguments is fine. Mixing incompatible types, like a length with an angle or a unitless number, makes the whole declaration invalid, and the browser drops it without an error.
Projects that cannot drop legacy support entirely can pair a plain fixed value declared first with the clamp() line after it, so browsers that don't understand clamp() keep the fixed size.
Use Cases Beyond Typography: Spacing, Width and Layout with Clamp()
Font size is the most common use of clamp(), but the same three-argument logic applies to any length-based CSS property.
Fluid Spacing with Clamp()
Padding and margin values scale the exact same way font size does, a minimum on small screens, a maximum on large ones, and a fluid vw-based value in between.
Common candidates:
- Section padding, so content doesn't crowd the edges on small screens or float awkwardly on large ones
- Gap values inside a flex or grid layout
- Margin between stacked headings and paragraphs
The slope calculation is identical to the one used for font size. Only the property name and the min/max numbers change.
Fluid Container Widths with Clamp()
A container's max-width can use clamp() to stop content from stretching too wide on large monitors while still filling smaller screens.
A typical pattern reads width: clamp(320px, 90%, 1200px);, keeping the container fluid between a hard floor and ceiling.
This overlaps directly with how a grid system defines its outer bounds, since both are solving the same problem of keeping content readable at extreme widths.
Fluid design systems such as Utopia ship their spacing and width tokens as clamp() expressions too, not only their font sizes.
FAQ on CSS Clamp Calculator
Is a CSS Clamp Calculator the Same Thing as the Clamp() Function?
No. A CSS clamp calculator is a front-end tool that outputs syntax. clamp() itself is the native CSS function, part of the CSS Values and Units Module, that browsers run. The calculator never ships to production, only the declaration it generates.
Can Clamp() Be Nested Inside calc()?
Yes. clamp() can sit inside a calc() expression, and calc() can sit inside clamp() arguments too. Nesting is common when combining a fluid vw value with a fixed rem offset inside the preferred value argument of the function.
Does Clamp() Work with CSS Custom Properties?
Yes. Any argument in clamp() can reference a CSS custom property instead of a literal value. Design systems often store the minimum, preferred, and maximum values as variables, then apply the same clamp() pattern across multiple components without repeating numbers.
Can Clamp() Produce a Negative Value?
Yes, if all three arguments resolve to negative numbers, clamp() returns a negative result. This shows up in negative margins used for bleed layouts. Mixed positive and negative arguments still resolve normally, following the same minimum, preferred, maximum logic.
Do You Need a Build Tool or Preprocessor to Use Clamp()?
No. clamp() is native CSS and needs no Sass, PostCSS, or bundler step to run in a browser. A preprocessor only becomes useful for generating whole fluid scales, or for a fallback on the small group of old browsers that lack clamp().
How Do You Test a Clamp() Value Across Different Screen Sizes?
Resize the browser window manually, or use browser DevTools' responsive mode to drag the viewport width. Check that the value sits at the minimum below the smallest breakpoint and at the maximum above the largest, with smooth scaling in between.
What Should You Check First When a CSS Clamp Calculator's Output Looks Wrong?
A CSS clamp calculator's output looks wrong for one of three reasons almost every time: reversed argument order, a viewport width outside the tested range, or a leftover px value that never converted to rem.
- Confirm argument order: minimum, preferred, maximum
- Test both viewport extremes, not just the middle
- Check that the min and max use rem, not px, when the value controls font size
Global support for clamp() sits at 96.25% (Can I Use), yet WCAG's 200% resize threshold is a separate bar that near-universal support does not automatically clear.
Accepting clamp() trades precise control at any single breakpoint for scaling that never jumps.
A single fluid value rarely stays isolated. Most projects extend it into a full responsive typography scale with named steps instead of one-off declarations.