CSS Clamp Calculator
Generate responsive CSS clamp() values for fluid typography and spacing. Preview sizes, choose px or rem, and copy the result in your browser.
- Runs in your browser
- Tool input is not uploaded to ZeroTool servers
- Free · No Sign-Up
Scan with WeChat to share this tool
Examples, details and FAQ Worked examples, how it compares with other tools, and answers to common questions.
Default example
With the defaults—320px to 1440px and 16px to 32px—the result is:
font-size: clamp(1rem, 0.7143rem + 1.4286vw, 2rem);
The preview slider starts halfway, at 880px, where the value is 24px (1.5rem).
What the generated expression means
clamp(minimum, preferred, maximum) asks the browser to use the preferred value while keeping it between the two bounds. The calculator derives the preferred value from the line through your two viewport/value points:
slope = (end value - start value) / (max viewport - min viewport)
intercept = start value - slope × min viewport
preferred = intercept + (slope × 100)vw
Below the minimum viewport, the lower or upper bound holds the value at its endpoint. Between the endpoints, the value changes linearly. Beyond the maximum viewport, the opposite bound takes over.
Fluid typography and spacing
Fluid values are useful when a sudden breakpoint would create a visible jump. Typical targets include headings, section padding, grid gaps, and content widths. They are less useful for values that must align to a strict fixed system, such as one-pixel borders.
For font sizes, rem bounds preserve a relationship with the root font size. Still test the finished layout at 200% browser zoom and with longer translated text. A mathematically valid expression can still overflow a real component.
Reverse and constant ranges
The end value may be smaller than the start value. In that case the preferred expression uses a negative vw term, so the property decreases as the viewport widens. The calculator sorts only the clamp() bounds; it preserves the direction of the line.
If both endpoint values match, no fluid calculation is needed. The output becomes a single fixed length such as 1rem. Negative values are accepted for margin and the custom property, where negative lengths can be meaningful, but rejected for the other presets.
Two more worked examples
Section padding in px. Choose Padding, px output, viewports 375 and 1280, values 16 and 48:
padding: clamp(16px, 2.7403px + 3.5359vw, 48px);
In a Chrome iframe 768px wide this computed to 29.896px; the live preview shows 29.8961px with the slider at 768px, and at 1280px it reaches the 48px cap. The sampled values table lists five evenly spaced widths (375, 601.25, 827.5, 1053.75 and 1280px), so 768px is not one of its rows.
A heading that shrinks on wide screens. Font size, rem output, 320 → 1440, values 40 and 28:
font-size: clamp(1.75rem, 2.7143rem - 1.0714vw, 2.5rem);
The bounds are sorted (1.75rem first), but the slope stays negative: 40px at 320px, 35.2px at 768px, 28px from 1440px on. Because 40 is less than twice 28, the calculator also shows its zoom notice for this range.
Limits and things to check
- Zoom. Zooming the page shrinks the viewport in CSS pixels, so the vw part grows less than the rem part. MDN's clamp() accessibility note advises a maximum that uses a relative length unit such as rem and is at least twice the minimum, so text can still reach 200% (WCAG 1.4.4); with px output the bounds do not follow the user's font size setting. The notice appears for font-size when the maximum is under twice the minimum; with 18px → 22px, for example, it stays on.
- vw includes the scrollbar. On desktop browsers with classic scrollbars, 100vw is the window width including the vertical scrollbar, so at a "768px" breakpoint the content area is narrower than the number the line was built on.
- Viewport units only. The preferred value always uses
vw. For a component that should scale with its container, replacevwwithcqiby hand and addcontainer-type: inline-sizeto the container. - Rounding. Numbers are written with up to four decimals, which is well under a hundredth of a pixel at common widths.
- Inputs are pixels. Endpoint values and viewports are entered in px and converted with the root size you set; the output cannot be em, ch or %.
clamp()works in Chrome 79, Firefox 75 and Safari 13.1 and later (MDN browser compat data).
To turn the output into a token, paste it into the CSS variables generator; to convert single values between px, rem, em and vw, use the CSS unit converter.
Privacy
The calculation runs in your browser tab. ZeroTool does not upload viewport sizes, property values, or generated CSS. The form settings are saved in this browser's local storage and are removed by Reset or by Ctrl/⌘+L inside the tool. The page analytics records only the tool name and the action (copy or reset), not your values.
FAQ
How does the CSS clamp calculator work?
It draws a straight line between the value at your minimum viewport and the value at your maximum viewport. It then converts that line into a preferred vw expression and wraps it with clamp() bounds.
Should I output px or rem?
Use rem for typography and other values that should respect the root font size. Use px when the endpoints need to remain fixed pixel measurements. The vw part stays responsive in either mode. With rem, enter the root font size your project really uses; if a script changes the root size with the screen width, choose px.
Can the value get smaller as the viewport grows?
Yes. Enter a larger value at the minimum viewport and a smaller value at the maximum viewport. The calculator generates a negative vw slope and keeps the bounds in valid ascending order.
Does clamp() automatically make fluid text accessible?
No. Fluid sizing still needs testing at browser zoom, narrow layouts, and user font settings. The calculator shows a notice when a font-size range is narrower than two-to-one, but that notice is guidance rather than a compliance guarantee.
Is any project data uploaded?
No. Calculation, preview, saving and copying happen in your browser tab. Your settings are saved in this browser's local storage and Reset (or Ctrl/⌘+L inside the tool) removes the saved entry. The page analytics records only the tool name and the action (copy or reset), not your values.