Spacing
Overview of the space scale and spacing tokens in Apsara.Consistent spacing creates visual rhythm and hierarchy in your interface. Apsara provides a comprehensive spacing scale through CSS custom properties that you can use throughout your application.
Scale
Spacing values are derived from a 17-step scale, which provides fine-grained control over layout spacing. The scale starts at 2px and progressively increases to 120px, allowing for both tight and spacious layouts.
| Token | Value | Use Case |
|---|---|---|
--rs-space-1 | 2px | Minimal spacing, icon gaps |
--rs-space-2 | 4px | Tight spacing, small gaps |
--rs-space-3 | 8px | Compact padding, inline spacing |
--rs-space-4 | 12px | Standard small padding |
--rs-space-5 | 16px | Default padding, common gaps |
--rs-space-6 | 20px | Medium padding |
--rs-space-7 | 24px | Comfortable spacing |
--rs-space-8 | 28px | Generous padding |
--rs-space-9 | 32px | Large spacing |
--rs-space-10 | 40px | Section gaps |
--rs-space-11 | 48px | Large section spacing |
--rs-space-12 | 56px | Extra large spacing |
--rs-space-13 | 64px | Major divisions |
--rs-space-14 | 72px | Layout spacing |
--rs-space-15 | 80px | Page sections |
--rs-space-16 | 96px | Large page sections |
--rs-space-17 | 120px | Maximum spacing |
Tokens
Space scale tokens can be accessed using CSS variables. Use these tokens to style your custom components, ensuring they are consistent with the rest of your theme.
1/* Space scale */2var(--rs-space-1); /* 2px */3var(--rs-space-2); /* 4px */4var(--rs-space-3); /* 8px */5var(--rs-space-4); /* 12px */6var(--rs-space-5); /* 16px */7var(--rs-space-6); /* 20px */8var(--rs-space-7); /* 24px */9var(--rs-space-8); /* 28px */10var(--rs-space-9); /* 32px */11var(--rs-space-10); /* 40px */12var(--rs-space-11); /* 48px */13var(--rs-space-12); /* 56px */14var(--rs-space-13); /* 64px */15var(--rs-space-14); /* 72px */16var(--rs-space-15); /* 80px */17var(--rs-space-16); /* 96px */18var(--rs-space-17); /* 120px */
Semantic Groupings
The spacing scale can be organized into semantic groups for easier selection:
| Group | Tokens | Values | Purpose |
|---|---|---|---|
| Compact | 1-3 | 2px - 8px | Tight UI elements, icon spacing |
| Comfortable | 4-7 | 12px - 24px | Standard component padding |
| Spacious | 8-11 | 28px - 48px | Section spacing, larger gaps |
| Layout | 12-17 | 56px - 120px | Page sections, major divisions |
Best Practices
- Use smaller values (1-5) for internal component spacing like padding and gaps between inline elements
- Use medium values (5-9) for spacing between related components and within sections
- Use larger values (10-17) for spacing between sections and major layout divisions
- Be consistent - use the same spacing token for similar contexts throughout your application
- Avoid mixing pixel values with spacing tokens to maintain consistency