Design tools

CSS Clamp Generator

CSS Clamp Generator

Fluid clamp() values between two viewports for type and spacing.

About this tool

About CSS Clamp Generator

CSS clamp() lets a size grow smoothly with the screen instead of jumping at breakpoints. You give a minimum, a preferred value that mixes a fixed amount with vw, and a maximum. Working out that preferred value by hand means solving a straight-line equation, which this tool does for you. Enter the viewport widths where scaling should start and stop and the sizes you want at each end, choose the property (font-size, padding, margin, gap, width or border-radius) and pick rem or px output. You get the clamp() value, the CSS declaration and a Tailwind arbitrary class, and a table shows the exact size at common widths from 320 to 1920 px. Drag the preview slider to see the result at any width. Switch to Fluid type scale to generate a whole set of headings from a base size and a ratio at each end, exported as CSS variables, a Tailwind v4 theme block or JSON. It all runs in your browser.

Built and maintained by Abhi JainUpdated

How to Generate a CSS clamp() Value

  1. 1

    Set the viewport range

    Enter the Min viewport and Max viewport widths in pixels.

  2. 2

    Enter the sizes

    Choose a property and enter the size at the minimum and maximum viewport, or switch to Fluid type scale and set a base size and ratio for each end.

  3. 3

    Check and copy

    Drag the preview slider, review the table, and copy the CSS, Tailwind or variables.

CSS Clamp Generator: questions and answers

How is the clamp() value calculated?

slope = (max size − min size) ÷ (max viewport − min viewport); intercept = min size − slope × min viewport. The preferred value is intercept + slope × 100vw, and clamp(min, preferred, max) stops it at both ends.

Why use rem in clamp() instead of px?

A rem-based minimum, maximum and intercept scale with the visitor's browser font setting and zoom. Pure vw values ignore text zoom, which is an accessibility problem (WCAG 1.4.4).

Is clamp() supported in all browsers?

Yes. clamp() works in every current browser and has since 2020.

Can I use clamp() for spacing as well as fonts?

Yes. It works with any length property, such as padding, margin, gap, width and border-radius. Choose the property in Single value mode.

What is a fluid type scale?

A set of font sizes (small, base, large, headings) where both the base size and the ratio between steps change with the viewport, so headings grow faster than body text on large screens.

Ready-made CSS Clamp Generator presets