Skip to content

Spacing scale

Build spacing on a grid or a ratio, see it in a real layout, and check that small targets get enough room. Everything runs in your browser, and the link keeps your choices.

Runs in your browserGrid or ratioTarget sizes

Choices

Method

Every step is a multiple of it.

Steps
Labels
Unit

Grow each step between two screen widths with clamp().

Such as a 16 px icon in a button. Used by the target checks.

Scale

Each step of the scale, smallest first, with its size.
StepSizeCopy
10.25rem4 px
20.5rem8 px
30.75rem12 px
41rem16 px
61.5rem24 px
82rem32 px
123rem48 px
164rem64 px
246rem96 px
328rem128 px

Checks

  • Every step is differentNo two neighbouring steps share a size.Pass
  • Steps riseEach step is larger than the one before.Pass
  • Every step is a whole pixelEdges stay sharp at 100% zoom.Pass
  • 1 pads the 16 px target to 24 px16 + 2 × 4 = 24 px, enough for 2.5.8. 4 (16 px) reaches 44 px for 2.5.5 (AAA).Pass
  • 2 keeps small targets apartTwo unpadded 16 px targets need a gap of 8 px so their 24 px circles don't overlap. 2 is 8 px.Pass
  • Tailwind gets one --spacing valueTailwind multiplies it, so p-4 is 4 units. No names to clash.Pass

These check the numbers. Target size depends on the real component, so they can't tell you a page conforms to WCAG. Test it in a browser too.

Preview

Ladder

  • 14 px
  • 28 px
  • 312 px
  • 416 px
  • 624 px
  • 832 px
  • 1248 px
  • 1664 px
  • 2496 px
  • 32128 px

Sample layout

Applies the WCAG 1.4.12 overrides a reader might use: line height 1.5, paragraph spacing 2×, letter spacing 0.12× and word spacing 0.16× the font size.

Weekly report

Sent every Monday to the design team, with new components and open reviews.

  • Button sizes agreed
  • Icon set updated
  • Two reviews waiting
Card padding: 6 (24 px)Gap between items: 2 (8 px)Space between sections: 8 (32 px)Icon button padding (16 px icons): 1 (4 px)

Export

spacing-scale-theme.css
/* Spacing scale: 4px grid. */
/* Tailwind multiplies --spacing by any number. This scale uses 1, 2, 3, 4, 6, 8, 12, 16, 24, 32. */
@theme {
  --spacing: 0.25rem;
}

How it works

Grid or ratio

A grid scale multiplies one unit, usually 4 px, by a set of numbers, so every step lines up. A ratio scale multiplies a base by the same ratio for each step, like a type scale, which spreads large steps further apart. Ratio steps are then snapped to the nearest multiple of the snap value, and never below one snap unit, so they stay on a grid. Snapping can join two small steps, and the checks name them.

Pixels are kept to 2 decimals and rem values to 4, with 1 rem as 16 px. Rem values come from the snapped pixels. With Sizes labels, md is the base of a ratio scale, or the grid step nearest 16 px.

Target sizes

WCAG 2.5.8 asks for targets of at least 24 × 24 CSS px, and padding counts toward that. So the padding check looks for the smallest step where the content plus padding on both sides reaches 24 px, and the step for the 44 px of 2.5.5 (AAA). A smaller target can still pass if it has room around it: a 24 px circle centred on it mustn't touch another target or its circle. For two unpadded targets side by side, that means the content plus the gap must reach 24 px, which the gap check works out.

Both checks assume a square target centred in its box. A real component can differ, and some targets are exempt, so test the page itself.

Text spacing

WCAG 1.4.12 is about what happens when a reader overrides your text spacing, not about the values you choose. The preview's “Force text spacing” applies those overrides to the sample, so you can see whether padding and gaps still hold the text without clipping or overlap.

Fluid sizes

A fluid step grows between two screen widths using clamp(), with a rem part beside the vw part. A grid scale grows its unit, and a ratio scale moves to the large base and ratio. Space that grows on wide screens can help, but zooming makes the viewport narrower, so fluid space shrinks back as a page zooms in.

The exports

Tailwind CSS v4 multiplies one variable for every numeric spacing class: p-4 is calc(var(--spacing) * 4). So a grid scale with Numbers labels exports a single --spacing line, which also works as a clamp(). Other scales export named --spacing-<name> values, which give classes such as p-step-1 and gap-step-1.

Two things we found by compiling with Tailwind. Names such as --spacing-md are also container sizes, so they change max-w-md as well; the checks flag them. And --spacing-*: initial also clears --spacing, so every numeric class disappears. The export never writes it.

The DTCG export uses the 2025.10 format with dimension tokens. Token names can't hold a dot, so 0.5 becomes 0-5. A dimension can't hold clamp(), so a fluid scale exports its small and large sizes as two groups.

Not covered yet

  • Layout grids, columns, breakpoints and container widths.
  • Negative spacing and corner radius.
  • Role names such as card padding. Those belong to a design system, not a scale.