Spacing scale generator
Choose a base unit and how many steps you need; the tool builds a consistent spacing scale and gives you CSS variables, a Tailwind theme or plain values.
Adjust the values to build a scale.
| Step | px | rem |
|---|
4px or 8px?
An 8px grid makes the next step obvious: every gap is a multiple of eight, so a 12px value stands out as a mistake. A 4px grid keeps that rhythm but gives you the half steps that small UI needs — 4px between an icon and its label, 8px inside a button, 12px between rows. Start at 4px and use multiples of eight wherever you can; the scale above already contains both.
Linear or geometric
A linear scale adds the same amount at every step: 4, 8, 12, 16, 20. It is predictable, but the jump from 4 to 8 is a 100% change while 36 to 40 is 11%, so small gaps feel tight and large ones feel flat. A geometric scale multiplies instead: 4, 8, 16, 32. The relative jump stays constant, which suits type sizes and page-level spacing. Many design systems mix the two — linear up to 16px, geometric above it.
Why the output uses rem
A spacing scale in rem follows the reader's font size. Someone who sets 20px as their default gets gaps that scale with their text instead of staying fixed. Borders and hairlines are the exception: keep those in px so they stay one physical pixel. The tool also shows px next to every step, because that is the number you usually have in your head while designing.
Questions and answers
Should I use a 4px or an 8px spacing grid?
An 8px grid keeps every gap a multiple of eight and makes mistakes easy to spot. A 4px grid keeps the same rhythm but allows the half steps small UI needs, such as 4px between an icon and its label. Starting at 4px and preferring multiples of eight is a common compromise.
Why does the output use rem instead of px?
Spacing in rem follows the reader's default font size, so gaps grow with their text instead of staying fixed. Keep borders and hairlines in px so they stay one physical pixel. The table shows both units because px is easier to reason about while designing.
When should I use a geometric scale instead of a linear one?
Use linear steps for small, frequent values and a geometric scale where relative jumps matter: type sizes, section padding, page-level layout. A linear scale compresses large gaps and exaggerates small ones, which is why many systems mix the two.
How do I use this scale with Tailwind?
Tailwind v4 reads the --spacing-* variables you see in the output. Paste the @theme block into your CSS entry point to replace the default spacing scale. On Tailwind v3, map the same values under theme.spacing in tailwind.config.js.
Last updated