Skip to content
FluidClamp
Language: English

Fluid Spacing Calculator for Padding, Margin and Gap

Spacing benefits from fluid sizing just as much as type. Set how much space you want on a phone and on a desktop and get a clamp() value for padding, margin or gap.

Input unit
Output unit

Common presets

Your clamp() value

clamp(1.5rem, 0.6667rem + 4.1667vw, 4rem)

Slope: 4.1667vw ยท Intercept: 0.6667rem

CSS
clamp(1.5rem, 0.6667rem + 4.1667vw, 4rem)
CSS custom property
--fluid-space: clamp(1.5rem, 0.6667rem + 4.1667vw, 4rem);
Tailwind class
p-[clamp(1.5rem,0.6667rem_+_4.1667vw,4rem)]

Max is 2.67ร— the min (above 2.5ร—). Text that scales this much may not reach 200% when users zoom โ€“ see WCAG SC 1.4.4 Resize Text.

Rendered size by viewport
ViewportSize (px)Size (rem)
320px241.5
375px26.291.6432
768px42.672.6667
1024px53.333.3333
1280px644
1440px644
1920px644

Your settings are saved in the URL, so you can bookmark or share this exact result.

Live preview

53.33px at a 1024px viewport

Fluid padding and gap

Why make spacing fluid

Generous whitespace makes a desktop layout feel calm, but the same 96px section padding wastes a third of a phone screen. Fixed breakpoints fix that in steps, often leaving tablets with spacing that is either too tight or too loose. A fluid value grows continuously, so every screen gets space in proportion to its width, and you write one declaration instead of three.

The same math as fluid type

Spacing uses exactly the same linear formula as font sizes: a minimum, a maximum and a straight line between two viewport widths. The difference is in the numbers you choose. Spacing often grows by a larger factor than text โ€“ going from 24px to 64px of section padding is common โ€“ because whitespace does not have to stay readable. The WCAG 2.5ร— zoom note does not apply to spacing, but it still appears as a reminder when you reuse the value for text.

Building a spacing scale

For a consistent system, define a handful of fluid space tokens such as --space-s, --space-m and --space-l, each with its own min and max. Use the small ones for gaps inside components, the middle ones for card padding and the large ones between page sections. Pair them with a fluid type scale using the same viewport range so text and space grow in step.

In Tailwind, apply the result as an arbitrary value such as p-[clamp(โ€ฆ)], gap-[clamp(โ€ฆ)] or my-[clamp(โ€ฆ)]. The calculator outputs a ready-made class with underscores instead of spaces, which is how Tailwind expects spaces inside arbitrary values.

Tips

Keep spacing values in rem so they respect user font settings along with the text. Avoid fluid values for borders and hairlines, where fractional pixels can blur. Check the preview at 320px to make sure padding still leaves room for content.

Frequently asked questions

Can clamp() be used for padding and margin?

Yes. clamp() works for any CSS length, including padding, margin, gap, width, border-radius and inset values.

Should spacing use rem or px?

rem is usually better: spacing then grows when a user increases their default font size, keeping the proportions between text and whitespace.

Does the 2.5ร— WCAG warning matter for spacing?

No. The guideline concerns text resizing. Spacing can safely grow more, as long as content still fits on small screens.

How do I use the value in Tailwind?

Copy the Tailwind class and change the prefix as needed, for example p-, px-, gap- or space-y-. The value inside the brackets stays the same.