Spacing Scale Generator
Create consistent layout grids, padding structures, and typographic rhythms using linear or geometric progressions
Spacing Scale Generator
Scale Preview
Scale Values
Predefined Scales:
Generated Code:
CSS Variables
Usage Examples
.element {
padding: var(--space-md);
margin-bottom: var(--space-lg);
}
.container {
gap: var(--space-sm);
padding: var(--space-xl);
}
.button {
padding: var(--space-sm) var(--space-lg);
}Tailwind Config
{
"spacing": {}
}Why Consistent Spacing Scales Matter in Modern UI/UX
In premium interface design, the space between elements is just as critical as the elements themselves. Visual harmony, predictable reading paths, and tactile comfort are governed by a unified spacing system. Designing without a structured spacing scale often leads to ad-hoc, inconsistent padding and margin decisions, giving layouts a disorganized, unpolished feel. By using a mathematical scale, you create a natural visual rhythm that feels cohesive and reduces cognitive fatigue for the end-user.
Mathematical Scale Foundations
Modern design systems employ one of two principal mathematical formulas to construct spacing steps: linear progressions or geometric (exponential) curves.
Linear Progression Formula
Provides predictable, uniform increments (e.g., base 8px yields 8px, 16px, 24px, 32px, 40px). Ideal for grid gutters, systematic forms, and UI grids.
Geometric (Exponential) Formula
Generates a progressive curve where gaps grow faster at higher steps (e.g., base 8px with a 1.5 ratio yields 8px, 12px, 18px, 27px, 40.5px). Excellent for landing page sections, cards, and responsive editorial layout margins.
Selecting the Ideal Spacing System
Different screen densities and user interfaces require different spacing systems. Review this direct comparison of standard base units before deciding on your design tokens:
| Base Unit | Scale Increments | Primary Advantages | Best Suited For |
|---|---|---|---|
| 4px System | 4px, 8px, 12px, 16px... | Extremely granular and flexible | Dense, data-heavy dashboards & mobile apps |
| 8px System | 8px, 16px, 24px, 32px... | Highly divisible, perfect scaling factors | Standard desktop SaaS, general websites, Tailwind defaults |
| 10px System | 10px, 20px, 30px, 40px... | Simplifies decimal arithmetic | Rapid layout prototyping and custom portfolios |
| 1rem (16px) | 0.25rem, 0.5rem, 1rem, 1.5rem... | Built-in accessibility & native browser scaling | Responsive editorial, blogging, accessibility-first sites |
Implementation: CSS Custom Properties
Once you generate your scale, define them as CSS Custom Properties in the root scope. This makes it trivial to change your spacing density globally with minimal refactoring:
:root {
/* Design System Spacing Base */
--space-unit: 8px;
/* Scale Definitions */
--space-xxs: calc(var(--space-unit) * 0.5); /* 4px */
--space-xs: var(--space-unit); /* 8px */
--space-sm: calc(var(--space-unit) * 2); /* 16px */
--space-md: calc(var(--space-unit) * 3); /* 24px */
--space-lg: calc(var(--space-unit) * 4); /* 32px */
--space-xl: calc(var(--space-unit) * 6); /* 48px */
--space-2xl: calc(var(--space-unit) * 8); /* 64px */
}
/* Application in Components */
.card-premium {
padding: var(--space-md);
margin-bottom: var(--space-lg);
border-radius: var(--space-xs);
gap: var(--space-sm);
}Responsive Spacing with Relative Variables
To build truly fluid web designs, adjust the base variable under media queries. Since all spacing steps rely on the base variable, the entire layout responds harmoniously:
:root {
--space-unit: 0.5rem; /* Mobile: 8px base */
}
@media (min-width: 768px) {
:root {
--space-unit: 0.75rem; /* Tablet: 12px base */
}
}
@media (min-width: 1200px) {
:root {
--space-unit: 1rem; /* Desktop: 16px base */
}
}
.section-hero {
padding: calc(var(--space-unit) * 5);
/* Mobile: 40px padding | Tablet: 60px | Desktop: 80px */
}Professional Spacing Guidelines
When applying your spacing tokens, adhere to these standard industry design conventions:
- Touch Target Safety: Ensure that all clickable buttons and interactive items maintain a padding of at least
--space-smto satisfy the WCAG touch target dimension of 44×44px. - Content Hierarchy: Keep spaces between sections (e.g.
--space-xl) significantly larger than spaces within cards (e.g.--space-smor--space-md). - Vertical Rhythm: Standardize paragraph spacing (using
margin-bottom) to match your body text height (typically 1.5× font size, around 24px) for perfect readability.