The 4px Grid System
All spacing follows a 4px base unit, creating visual harmony and consistency. This system ensures elements align properly and creates predictable layouts.
4px base unit repeated across 128px
4px
Base unit
8px
2× base (most common)
16px
4× base (standard)
Micro (0-8px)
Tight spacing for compact elements
00px0pxp-0m-0gap-00.50.125rem2pxp-0.5m-0.5gap-0.510.25rem4pxp-1m-1gap-11.50.375rem6pxp-1.5m-1.5gap-1.520.5rem8pxp-2m-2gap-2Small (12-16px)
Standard component padding and spacing
30.75rem12pxp-3m-3gap-341rem16pxp-4m-4gap-4Medium (20-32px)
Card and section spacing
51.25rem20pxp-5m-5gap-561.5rem24pxp-6m-6gap-671.75rem28pxp-7m-7gap-782rem32pxp-8m-8gap-8Large (40-64px)
Major section gaps
102.5rem40pxp-10m-10gap-10123rem48pxp-12m-12gap-12143.5rem56pxp-14m-14gap-14164rem64pxp-16m-16gap-16Macro (80-128px)
Page-level spacing
205rem80pxp-20m-20gap-20246rem96pxp-24m-24gap-24328rem128pxp-32m-32gap-32Common Spacing Patterns
Card Padding
Use p-6 (24px) for standard card padding
<div className="bg-surface-1 border rounded-xl p-6">
Card content
</div>Button Padding
Horizontal padding larger than vertical for better touch targets
<button className="px-6 py-3 rounded-lg">
Action
</button>Stack Spacing
Use space-y-* for consistent vertical rhythm
<div className="space-y-4">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
</div>Grid Gap
Use gap-* for grid and flex container spacing
<div className="grid grid-cols-3 gap-6">
<div>Card 1</div>
<div>Card 2</div>
<div>Card 3</div>
</div>Section Spacing
Use mb-16 (64px) between major page sections
<section className="mb-16">
Section content
</section>
<section className="mb-16">
Next section
</section>Best Practices
Do This
- ✓Use spacing tokens from the 4px scale
- ✓Maintain consistent spacing across similar components
- ✓Use space-y-* for vertical stacks
- ✓Use gap-* for grid/flex containers
- ✓Increase spacing for better touch targets on mobile
Do not Do This
- ✗Avoid arbitrary spacing like p-[13px]
- ✗Do not use spacing values outside the 4px scale
- ✗Never use inline styles for spacing
- ✗Avoid mixing spacing systems (rem + px)
- ✗Do not use overly tight spacing for touch interfaces