Uitly Logo
UITLY
UI Spacing Scale Generator

Free UI Spacing Scale Generator 8px Grid & Design Tokens

Generate a consistent spacing scale from any base unit. Get CSS custom properties, a Tailwind config snippet, and an SCSS map all ready to paste into your design system. Built on the same principles used by Material Design, Ant Design, and Radix UI.

Multiple Algorithms

Linear, Fibonacci, and geometric scales — pick the growth curve that fits your design language

3 Output Formats

CSS variables, Tailwind config, and SCSS maps — copy and paste directly into your project

Live Preview

See your scale as visual blocks, padding previews, and gap demonstrations before you ship it

Build Your Spacing System

Set your base unit, choose a scale algorithm, and adjust the number of steps. The tool generates your full spacing scale with CSS variables, Tailwind config, and SCSS map — ready to copy.

UI Spacing Scale Generator

1–32px

410

Generated Scale

StepTokenpxremTailwindVisual
1--space-180.5p-2
2--space-2161p-4
3--space-3241.5p-6
4--space-4322p-8
5--space-5483p-12
6--space-6644p-16
7--space-7966p-24
8--space-81288p-32
9--space-919212p-48

Live Preview

8px
16px
24px
32px
48px
64px
96px
128px
192px

CSS Custom Properties

:root {
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --space-5: 48px;
  --space-6: 64px;
  --space-7: 96px;
  --space-8: 128px;
  --space-9: 192px;
}

Tailwind Config (tailwind.config.js)

// tailwind.config.js
module.exports = {
  theme: {
    extend: {
      spacing: {
        "2": "8px", // 0.5rem
        "4": "16px", // 1rem
        "6": "24px", // 1.5rem
        "8": "32px", // 2rem
        "12": "48px", // 3rem
        "16": "64px", // 4rem
        "24": "96px", // 6rem
        "32": "128px", // 8rem
        "48": "192px", // 12rem
      },
    },
  },
}

SCSS Map

$spacing: (
  "space-1": 8px,
  "space-2": 16px,
  "space-3": 24px,
  "space-4": 32px,
  "space-5": 48px,
  "space-6": 64px,
  "space-7": 96px,
  "space-8": 128px,
  "space-9": 192px
);

// Usage: padding: map-get($spacing, "space-3");

What This Generator Produces

CSS Custom Properties

  • :root variables for every step
  • Works in vanilla CSS, PostCSS, Astro
  • Overridable per component or theme

Tailwind Config

  • theme.extend.spacing block
  • Compatible with Tailwind v3 and v4
  • Keeps default utilities intact

SCSS Map

  • Sass map for loop-based generation
  • map-get() usage example included
  • Works with Angular, Vue CLI, Rails

No account required — 100% free

The Complete Guide to UI Spacing Systems

Inconsistent spacing is the most common reason production UIs feel off even when the typography and color palette are solid. When every engineer picks their own margin values — 13px here, 22px there — the result is a layout that nobody can explain and nobody can maintain. A spacing scale solves this by giving your entire team a shared vocabulary: instead of debating pixel values, you debate step numbers. This tool generates that vocabulary in under thirty seconds.

What Is a Spacing Scale?

A spacing scale is a predefined set of size values that you use exclusively for all layout decisions margins, paddings, gaps, widths, and offsets. Instead of choosing from an infinite range of pixel values, you constrain every spacing decision to a fixed set: for example, 4, 8, 12, 16, 24, 32, 48, 64px. Every component in your UI uses only values from this list.

The result is visual harmony. Because every spacing value shares a mathematical relationship, elements naturally align across components and pages even when different engineers build them. Spacing scales are the foundation of every mature design system, from Google's Material Design (8px base) to Apple's Human Interface Guidelines (4pt base) to Radix UI's primitives.

Why the 8px Grid System Works

The 8px grid became the dominant standard for one practical reason: most screen sizes are divisible by 8. At 1x density, 8px aligns to whole pixels. At 2x (Retina), 8px maps to exactly 16 physical pixels. At 3x, it maps to 24. This means your layouts stay pixel-perfect across every display density without fractional rounding errors.

4px base

Used by: Tailwind CSS (default), iOS HIG, Ant Design

4, 8, 12, 16, 24, 32, 48, 64

High-density UIs, data tables, form-heavy apps, admin dashboards. Gives fine-grained control for tight layouts.

8px base

Used by: Material Design, GitHub, Stripe, Linear

8, 16, 24, 32, 48, 64, 96, 128

Consumer apps, marketing sites, SaaS products. The most common choice — generous spacing without going too large.

10px base

Used by: Bootstrap (rem-friendly), custom design systems

10, 20, 30, 40, 60, 80, 120, 160

Teams that prefer decimal rem values. 10px base means 1rem = 10px, making rem calculations trivial to do in your head.

How This Spacing Scale Generator Works

The tool takes your base unit and applies a multiplier sequence to generate each step in the scale. You choose from three algorithms:

  • 1Linear: Multiplies the base by 1, 2, 3, 4, 6, 8, 12, 16, 24. This is the standard approach used by Tailwind and most design systems. The non-linear jumps at the larger values (6× to 8× to 12×) reflect the fact that large spacing differences need to be proportionally bigger to register visually.
  • 2Fibonacci: Uses the Fibonacci sequence as multipliers (1, 2, 3, 5, 8, 13, 21...). This creates a naturally accelerating progression that matches how the human eye perceives size differences. Designers who use type scales based on the golden ratio often prefer Fibonacci spacing to maintain system coherence.
  • 3Geometric: Applies a 1.5× growth ratio at each step. This produces a smooth, consistent exponential curve where each value is 50% larger than the previous one. It creates the most visually proportional scale and pairs well with modular type scales that use the same ratio.

Every generated value rounds to the nearest whole pixel to prevent subpixel rendering artifacts. The tool also outputs the rem equivalent of each value (dividing by 16, the browser default font size) so you can use either unit in your actual CSS.

How to Integrate a Custom Spacing Scale in Tailwind CSS

Tailwind's default spacing scale uses a 4px base with values from 0 to 96 (0 to 384px). You can extend it with your custom scale without replacing the defaults by adding your values to theme.extend.spacing in your config file. Values in extend merge with defaults rather than overriding them:

tailwind.config.js — extending the default scale

module.exports = {
  theme: {
    extend: {
      spacing: {
        "18": "72px",   // 9 × 8
        "22": "88px",   // 11 × 8
        "26": "104px",  // 13 × 8
        "30": "120px",  // 15 × 8
      },
    },
  },
}

If you want to replace Tailwind's default spacing entirely with your custom scale, use theme.spacing (without extend). This is the right choice for mature design systems where you want to prevent engineers from using arbitrary values outside your scale. Use the copied Tailwind config output from this tool and paste it into either location.

In Tailwind v4, the config format changes to a CSS-based theme definition. You define your spacing scale using @theme in your CSS file, which maps directly to the CSS custom properties this tool also generates — making the two outputs complementary.

Real Project Examples: Applying a Spacing Scale

Knowing the theory is one thing. Seeing how a spacing scale applies to real interface decisions is another. Here are the conventions that experienced front-end teams use:

Inline spacing (between elements)

Use steps 2–4 of your scale (e.g., 8–16px) for spacing between related inline elements — icon-to-label gap, tag chips in a row, form field icon padding. Related items should feel grouped.

Example: gap-2 (8px) between icon and label in a button

Component internal padding

Use steps 3–5 (12–24px) for the internal padding of most UI components — cards, buttons, form inputs, list items, and dropdowns. This is your most-used range.

Example: px-4 py-3 (16px / 12px) for standard buttons

Between sibling components

Use steps 5–7 (24–48px) to separate distinct UI sections on the same page — the gap between a heading and a card grid, between form groups, or between a sidebar item.

Example: space-y-6 (24px) between form sections

Section and page layout

Use steps 7–9 (48–96px) for major page sections — the vertical rhythm between hero, features, pricing, and footer sections on a marketing page.

Example: py-16 (64px) section padding on desktop

Frequently Asked Questions

Should I use a 4px or 8px base unit for my design system?+

Both work well — the right choice depends on your UI density. Use a 4px base if you build dense, data-heavy interfaces like dashboards, admin tools, or data tables where fine-grained control matters. Use an 8px base for consumer applications, marketing sites, and content-focused products where more breathing room improves readability. Many teams use a 4px base with a convention that they only use even-numbered steps (4, 8, 16, 24...) in practice — giving them the flexibility of 4px increments with the visual discipline of an 8px grid.

What is the difference between a spacing scale and a spacing token?+

A spacing scale is the mathematical system — the set of values and the rationale behind them. A spacing token is the named variable that references a specific step in that scale in your code. For example, --space-3 is a token. The token's value of 24px comes from the scale. Tokens are what engineers and designers reference in their work; the scale is what ensures those tokens form a coherent, intentional system. This tool generates both: the scale defines the values, and the CSS variables, Tailwind keys, and SCSS map names are the tokens.

How do I prevent engineers from using arbitrary spacing values outside the scale?+

Replace Tailwind's default spacing in tailwind.config.js using theme.spacing (not theme.extend.spacing) so only your scale's values generate utility classes. Enable a linting rule using eslint-plugin-tailwindcss to flag arbitrary values like p-[22px]. For CSS codebases, provide only the CSS custom properties and remove other spacing values — engineers can only use what exists. Document the scale in your design system docs and make it the fastest path to using spacing. Friction reduction is more effective than enforcement.

Can I use this spacing scale with Figma?+

Yes. Figma's spacing system uses numeric values directly, so you add the pixel values from your generated scale as Spacing tokens in Figma's Local Variables panel (Figma Enterprise / Professional) or manually apply them as a reference table in your component documentation. If you use a design token tool like Style Dictionary, Token Studio, or Supernova, you can import the CSS custom properties output from this tool as your source of truth and sync it directly to Figma variables and your codebase simultaneously.

Does a spacing scale apply to font sizes and line heights too?+

Spacing scales apply specifically to layout spacing — margin, padding, gap, and positional offsets. Type scales (font sizes and line heights) use a separate but related mathematical system. Most design systems keep these distinct: a spacing scale based on 8px multiples and a type scale based on a ratio like 1.25 or 1.333. Some designers derive both from a single base unit for maximum coherence, but this constraint can make the type scale feel too rigid. The most practical approach is to build your spacing and type scales independently, then verify they share enough common values to create visual harmony.

Whether you're starting a design system from scratch, migrating a legacy codebase to design tokens, or onboarding a new engineer who keeps using random margin values — a well-defined spacing scale is the single highest-leverage tool in your system. Generate yours above, copy the output, and eliminate spacing debates from your team permanently.

Free forever · No account · CSS, Tailwind & SCSS output

You might also like

4 related tools