Create consistent spacing systems for UI design.
Generate spacing systems (4, 8, 12, 16px, etc) and export CSS variables.
Results in --space-0, --space-1, ...
: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)',
}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 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.
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 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.
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.
Create consistent spacing systems for UI design.
Free spacing scale generator — create 4px, 8px, or custom-base spacing systems and export them as CSS variables, Tailwind config, or design token JSON. No signup required.
Choose ratio, base unit, or seed colors.
Preview the scale, palette, or contrast preview.
Copy CSS variables, Tailwind config, or HEX list.
Advertisement
Multiples align with common device pixels and component libraries—keeps padding and gaps consistent.
Yes—copy theme.spacing extensions or CSS custom properties for your design tokens file.
Spacing tokens are generated locally; scale values are not sent to a server.
WCAG ratios are indicative—verify with official audits for compliance sign-off.
For design systems and prototyping—not legal accessibility certification.
Part of Design & UI Tools
More free tools for the same workflow.
Advertisement
Reviewed by EverydayTools Editorial Team on 2026-05-19.