Skip to main content

Core Spacing

Core spacing tokens provide a consistent scale for margins, padding, gaps, and other spatial relationships throughout the design system.

Spacing Scale

Our spacing scale follows a harmonious progression based on a 4px base unit:

TokenValueremUsage
00px0remNo spacing
14px0.25remTiny spacing
28px0.5remSmall spacing
312px0.75remCompact spacing
416px1remBase spacing unit
520px1.25remMedium spacing
624px1.5remComfortable spacing
832px2remLarge spacing
1040px2.5remExtra large spacing
1248px3remSpacious
1664px4remVery spacious
2080px5remMaximum spacing

Semantic Spacing Names

For better readability, we also provide semantic names:

Semantic TokenNumeric ValueUsage
xs1 (4px)Minimal spacing
sm2 (8px)Small spacing
md4 (16px)Default spacing
lg6 (24px)Large spacing
xl8 (32px)Extra large spacing
2xl12 (48px)Maximum spacing

Usage Examples

Component Spacing

// Using numeric scale
<Box sx={{
padding: 4, // 16px
margin: 2, // 8px
gap: 3 // 12px
}}>
Content
</Box>

// Using semantic names
<Box sx={{
padding: 'md', // 16px
margin: 'sm', // 8px
gap: 'lg' // 24px
}}>
Content
</Box>

Layout Spacing

// Stack with consistent spacing
<Stack sx={{ gap: 'md' }}>
<Card sx={{ padding: 'lg' }}>Card 1</Card>
<Card sx={{ padding: 'lg' }}>Card 2</Card>
</Stack>

// Responsive spacing
<Box sx={{
padding: ['sm', 'md', 'lg'], // Mobile, tablet, desktop
margin: [2, 4, 6]
}}>
Responsive content
</Box>

Spacing Relationships

Our spacing scale maintains mathematical relationships for visual harmony:

Base unit (md: 16px) serves as the foundation for all spacing calculations.

Implementation

In Theme Configuration

const spacing = {
0: '0px',
1: '0.25rem', // 4px
2: '0.5rem', // 8px
3: '0.75rem', // 12px
4: '1rem', // 16px
5: '1.25rem', // 20px
6: '1.5rem', // 24px
8: '2rem', // 32px
10: '2.5rem', // 40px
12: '3rem', // 48px
16: '4rem', // 64px
20: '5rem', // 80px
};

// Semantic aliases
const semanticSpacing = {
xs: spacing[1], // 4px
sm: spacing[2], // 8px
md: spacing[4], // 16px
lg: spacing[6], // 24px
xl: spacing[8], // 32px
'2xl': spacing[12], // 48px
};

Component Integration

// Theme UI automatically maps spacing values
<Box
sx={{
p: 4, // padding: 1rem (16px)
m: 2, // margin: 0.5rem (8px)
px: 'lg', // padding-left/right: 1.5rem (24px)
py: 'sm', // padding-top/bottom: 0.5rem (8px)
}}
/>

Spacing Guidelines

Content Spacing

  • Text blocks: Use md (16px) for paragraph spacing
  • Headings: Use lg (24px) for section separation
  • Lists: Use sm (8px) between list items

Component Spacing

  • Card padding: Use lg (24px) for comfortable content area
  • Button padding: Use sm to md (8px-16px) for touch targets
  • Form spacing: Use md (16px) between form fields

Layout Spacing

  • Section gaps: Use xl to 2xl (32px-48px) for major sections
  • Grid gaps: Use md to lg (16px-24px) for content grids
  • Container padding: Use lg to xl (24px-32px) for page margins

Responsive Spacing

Spacing can adapt to different screen sizes:

// Responsive spacing array
<Box sx={{
padding: [
'sm', // Mobile: 8px
'md', // Tablet: 16px
'lg' // Desktop: 24px
]
}} />

// Responsive numeric values
<Stack sx={{
gap: [2, 4, 6] // 8px, 16px, 24px
}}>
<Item />
<Item />
</Stack>

Accessibility

Proper spacing improves accessibility by:

  • Touch targets: Minimum 44px (11 units) for interactive elements
  • Reading flow: Adequate spacing between text blocks
  • Visual hierarchy: Clear separation between content sections
  • Focus indicators: Sufficient padding around focusable elements