UI Spacing Scale Assistant

Generate spacing systems (4, 8, 12, 16px, etc) and export CSS variables.

Settings

Results in --space-0, --space-1, ...

Scale preview

--space-00px
--space-18px
--space-216px
--space-324px
--space-432px
--space-540px
--space-648px
--space-756px
--space-864px
--space-972px
--space-1080px
--space-1188px
--space-1296px

CSS output

:root {
  --space-0: 0px;
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --space-5: 40px;
  --space-6: 48px;
  --space-7: 56px;
  --space-8: 64px;
  --space-9: 72px;
  --space-10: 80px;
  --space-11: 88px;
  --space-12: 96px;
}

// Tailwind-like spacing (use in config)
space: {
  '0': 'var(--space-0)',
  '1': 'var(--space-1)',
  '2': 'var(--space-2)',
  '3': 'var(--space-3)',
  '4': 'var(--space-4)',
  '5': 'var(--space-5)',
  '6': 'var(--space-6)',
  '7': 'var(--space-7)',
  '8': 'var(--space-8)',
  '9': 'var(--space-9)',
  '10': 'var(--space-10)',
  '11': 'var(--space-11)',
  '12': 'var(--space-12)',
}

What Is a Spacing Scale in UI Design?

A spacing scale is a predefined set of values used consistently for margins, padding, gaps, and other layout dimensions. Instead of arbitrary values like 13px or 27px, you choose from a scale—e.g. 0, 4, 8, 12, 16, 24, 32px. These values act as design tokens: named, reusable units that ensure consistency, predictability, and scalability across your UI. A well-defined spacing system makes design decisions faster and keeps layouts rhythmical.

The 8px Grid System Explained

The 8px grid is widely used in design systems (Material Design, many product UIs) because it aligns with common screen densities, supports accessibility (touch targets, readable line heights), and creates a clear visual rhythm. Each step multiplies by 8: 0, 8, 16, 24, 32, 40px, etc. A 4px base gives finer control and is popular for dense dashboards; half-steps (4, 8, 12, 16) let you interpolate between 8px steps when needed. Use 8px as your primary scale and reach for 4px for tight component spacing.

Choosing the Right Base Unit (4px, 8px, 12px, 16px)

  • 4px — Best for dense dashboards, data-heavy UIs, and interfaces where fine-grained control matters. Steps: 4, 8, 12, 16, 20px.
  • 8px — General-purpose choice for product UIs. Matches Material and many design systems. Steps: 8, 16, 24, 32px.
  • 12px / 16px — Suited to marketing sites, landing pages, and content-first layouts where larger gaps and breathing room are desired.

Tradeoffs: smaller bases (4px) offer more steps but can feel busy; larger bases (16px) create simpler scales but less flexibility for compact UIs.

Component Spacing vs Layout Spacing

Component spacing is the padding inside buttons, cards, and inputs—typically smaller values from your scale (e.g. --space-2, --space-3). Layout spacing is the gap between sections, between grid items, or between major blocks—often larger values (--space-4, --space-6). Mixing arbitrary values causes inconsistency: one developer uses margin: 18px, another uses margin: 20px. Stick to the scale for both.

Using CSS Variables for Spacing

After generating your scale, add the :root block to your CSS. Use the variables in padding, margin, and gap:

/* Assume --space-0 through --space-12 exist (8px base) */

.card {
  padding: var(--space-3);
  margin-bottom: var(--space-4);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

You can map these in Tailwind config for spacing utilities or use them directly in custom components. Consistent variable names make refactoring and theming easier.

Frequently Asked Questions

What is a spacing scale?

A spacing scale is a set of consistent values (e.g. 0, 8, 16, 24px) used for margins, padding, and gaps. Using a base unit (4, 8, 12, or 16) keeps layouts consistent and makes design decisions faster.

Which base unit should I use?

4px gives fine control; 8px is very common (Material, many design systems); 12px and 16px create larger steps. Choose based on how dense your UI is and whether you need half-steps (e.g. 4px base gives 4, 8, 12; 8px gives 8, 16, 24).

How do I use the CSS variables?

Add the generated :root block to your CSS. Then use var(--space-1), var(--space-2), etc. in margin, padding, gap, or anywhere you need spacing. You can also map these in Tailwind config for spacing utilities.

Explore these related free tools to enhance your productivity and workflow.