Home/Tools/Layout/Spacing Generator
Layout · Generator

Spacing Generator

Create consistent spacing scales for margin and padding.

Scale Preset

Unit

Spacing Scale

0
0.000rem
0.5
0.125rem
1
0.250rem
1.5
0.375rem
2
0.500rem
2.5
0.625rem
3
0.750rem
3.5
0.875rem
4
1.000rem
5
1.250rem
6
1.500rem
8
2.000rem
10
2.500rem
12
3.000rem
16
4.000rem
20
5.000rem
24
6.000rem

Usage Example

Example card with padding: 0.500rem

Generated CSS
:root {
  --spacing-0: 0rem;
  --spacing-0.5: 0.125rem;
  --spacing-1: 0.25rem;
  --spacing-1.5: 0.375rem;
  --spacing-2: 0.5rem;
  --spacing-2.5: 0.625rem;
  --spacing-3: 0.75rem;
  --spacing-3.5: 0.875rem;
  --spacing-4: 1rem;
  --spacing-5: 1.25rem;
  --spacing-6: 1.5rem;
  --spacing-8: 2rem;
  --spacing-10: 2.5rem;
  --spacing-12: 3rem;
  --spacing-16: 4rem;
  --spacing-20: 5rem;
  --spacing-24: 6rem;
}

/* Usage */
.element {
  padding: var(--spacing-4);
  margin-bottom: var(--spacing-2);
  gap: var(--spacing-3);
}
100%
Free, no
sign-up needed
0
Code written
by hand
85+
CSS tools
in one place
<1s
Copy-ready
CSS instantly
What is this

What is the CSS Spacing Generator?

Generate consistent margin and padding scales based on a base unit. Export as CSS custom properties or Tailwind-compatible values.

Everything runs locally in your browser. Adjust the controls above, preview instantly, and copy clean, production-ready CSS — no account, no upload.

How to use

Using the CSS Spacing Generator

Everything lives in the panel at the top of this page. There is nothing to install — it all runs right here in your browser.

1

Set your base unit

Enter a base spacing value in px or rem. 4px (0.25rem) is the standard choice, matching Tailwind and Material Design.

2

Choose your scale type

Linear (multiples of base), modular (ratio-based), or custom. Linear 4px scales are most common for UI spacing.

3

Export the scale

Copy as CSS custom properties for native CSS, or as a JavaScript object for design token workflows.

The output

What the generated code looks like

Clean, production-ready CSS — no vendor bloat, no unnecessary declarations.

tokens.css
:root {
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;  /* base */
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;
  --space-24: 96px;
}

Reference spacing with var(--space-4) throughout your components. Changing the base unit updates every value at once.

Pro tips

Pro tips for better results

A 4px base unit matches most design systems

Tailwind, Material Design, and Ant Design all use 4px as their base unit. Sticking to multiples of 4 makes designs feel consistent and simplifies collaboration with designers.

Limit your scale to 8-10 values

More spacing tokens than you need creates decision fatigue. Cover the range from 4px to 96px with 8-10 named stops. Use the closest token rather than adding new ones.

Use rem for spacing when fonts are user-resizable

rem-based spacing scales with user font size preferences, improving accessibility. 1rem = 16px by default. 0.25rem = 4px, 1rem = 16px, 1.5rem = 24px.

FAQ

Frequently asked questions

Both work. px gives precise, fixed spacing that does not change with user font size preferences. rem scales with the root font size, which can aid accessibility for users who set larger text. For layout spacing, px is more predictable. For text-adjacent spacing (like line height), rem is often better.
No. Everything runs in your browser. Nothing is sent to a server.

From the blog

Read more