Foundations
Spacing, Sizing, Borders & Corner Radius
A governed 4 px baseline system for predictable spacing, interactive sizing, borders, and surface shape.
1. Component Overview
Definition
Spacing, sizing, borders, and corner radii form the geometric foundation of the design system.
- Spacing controls padding, margins, gaps, grouping, and layout rhythm.
- Sizing defines predictable dimensions for controls, icons, targets, and containers.
- Borders separate, contain, emphasize, or indicate interactive state.
- Corner radius defines surface shape without changing component semantics.
All values derive from a 4px baseline grid. The primary rhythm advances in 8px increments, while 4px values support compact alignment and optical adjustment.
Web implementations use rem values based on a user-configurable root size. Flutter implementations use density-independent logical pixels (dp).
Purpose
A governed scale prevents arbitrary geometry from accumulating across interfaces. It improves visual rhythm, responsive behavior, implementation consistency, design-to-development handoff, and automated validation.
The structural model uses one shared spacing scale for components, patterns, typography, and layouts. Smaller values establish relationships within components; larger values separate sections and layout regions. Existing tokens must be combined instead of creating arbitrary values.
2. Usage Guidelines (Dos and Don'ts)
Do
- Use only canonical spacing, sizing, border, and radius tokens.
- Use smaller spacing values between strongly related elements and larger values between independent regions.
- Assign component-internal spacing within the component contract rather than at each implementation site.
- Use
gapfor spacing between flex or grid children when spacing belongs to the parent layout. - Preserve the baseline grid when adapting layouts across breakpoints.
- Use semantic component-size variants such as
compact,small,medium, andlarge. - Apply corner radius consistently across the component boundary, focus indicator, overflow clipping, and interactive state layers.
- Use the smallest border strength that preserves sufficient separation and contrast.
- Document every exception that cannot be expressed using the canonical scale.
Don't
- Do not introduce arbitrary values such as
13px,19px, or27px. - Do not use repeated margins on child elements when the parent can define a consistent gap.
- Do not stack component padding and layout spacing without accounting for their combined distance.
- Do not reduce interactive targets below the platform minimum to create visual density.
- Do not use corner radius as a substitute for hierarchy, grouping, or elevation.
- Do not apply a full radius to multiline controls, large containers, or dense data surfaces.
- Do not use borders as the only indicator of error, selection, focus, or status.
- Do not remove focus-ring space by clipping interactive content with
overflow: hidden. - Do not create platform-specific values unless required by platform ergonomics and documented in the token mapping.
3. Architectural Integration (Web & Flutter)
Token Architecture
The canonical progression is:
primitive scale→semantic layout role→component token→component instance:root {
--ds-space-3xs: 0.25rem;
--ds-space-2xs: 0.5rem;
--ds-space-xs: 0.75rem;
--ds-space-sm: 1rem;
--ds-space-md: 1.5rem;
--ds-space-lg: 2rem;
--ds-space-xl: 3rem;
--ds-space-2xl: 4rem;
--ds-space-3xl: 5rem;
--ds-space-4xl: 6rem;
--ds-size-target-minimum: 2.75rem;
--ds-border-default: 0.0625rem;
--ds-border-strong: 0.125rem;
--ds-border-focus: 0.1875rem;
--ds-radius-sm: 0.25rem;
--ds-radius-md: 0.5rem;
--ds-radius-lg: 0.75rem;
--ds-radius-xl: 1rem;
--ds-radius-full: 9999px;
}The web root font size remains 100%. Do not force 16px on the root element because that can override user font preferences.
abstract final class DsSpace {
static const double threeXs = 4;
static const double twoXs = 8;
static const double xs = 12;
static const double sm = 16;
static const double md = 24;
static const double lg = 32;
static const double xl = 48;
static const double twoXl = 64;
static const double threeXl = 80;
static const double fourXl = 96;
}Component API / Props Architecture
Web components expose semantic variants such as <ds-stack gap="md">, <ds-card padding="lg">, and <ds-button size="medium">. Spacing utility classes may support page composition, prototypes, and migration work, but must not override required component geometry.
Flutter components accept typed values such as DsSpace.md, DsInsets.lg, and DsControlSize.medium. Public APIs prefer semantic enums; raw numeric overrides remain private, deprecated, or explicitly marked as escape hatches.
Visual Examples
These rendered specimens use the same canonical variables exported by the Web package. Dimensions are shown at their actual CSS scale.
Spacing
Baseline scale
space-3xs0.25rem · 4 dpspace-2xs0.5rem · 8 dpspace-xs0.75rem · 12 dpspace-sm1rem · 16 dpspace-md1.5rem · 24 dpspace-lg2rem · 32 dpspace-xl3rem · 48 dpspace-2xl4rem · 64 dpspace-3xl5rem · 80 dpspace-4xl6rem · 96 dpSizing
Control and target scale
Borders
Width hierarchy
Shape
Corner radius
Layout
Parent-controlled gaps
space-2xs8 pxspace-md24 pxspace-xl48 pxAccessibility
Focus geometry
The focus ring follows the component radius, sits outside its border, and remains unclipped.
4. Specifications & Anatomy
Spacing Scale
| Token | Web | Flutter | Primary use |
|---|---|---|---|
space-none | 0 | 0 dp | Intentional removal of spacing |
space-3xs | 0.25rem / 4px | 4 dp | Optical adjustment and compact icon relationships |
space-2xs | 0.5rem / 8px | 8 dp | Closely related inline content |
space-xs | 0.75rem / 12px | 12 dp | Compact control padding and small gaps |
space-sm | 1rem / 16px | 16 dp | Default internal padding and text grouping |
space-md | 1.5rem / 24px | 24 dp | Cards, grouped controls, and content blocks |
space-lg | 2rem / 32px | 32 dp | Large component padding and group separation |
space-xl | 3rem / 48px | 48 dp | Section separation |
space-2xl | 4rem / 64px | 64 dp | Default page-section rhythm |
space-3xl | 5rem / 80px | 80 dp | Large layout separation |
space-4xl | 6rem / 96px | 96 dp | High-emphasis layout separation |
Inner Padding
| Context | Compact | Default | Spacious |
|---|---|---|---|
| Icon and label | space-2xs | space-xs | space-sm |
| Button horizontal padding | space-xs | space-sm | space-md |
| Form control padding | space-xs | space-sm | space-md |
| Card padding | space-sm | space-md | space-lg |
| Dialog or drawer padding | space-md | space-lg | space-xl |
| Page container padding | space-sm | space-lg | space-xl |
Outer Margins
| Relationship | Token | Rule |
|---|---|---|
| Text inside one content group | space-2xs–space-sm | Preserve a visible relationship |
| Components inside one workflow | space-sm–space-md | Use parent-controlled spacing |
| Independent component groups | space-lg | Establish clear separation |
| Sections within a page | space-xl–space-2xl | Scale down at compact breakpoints |
| Major page regions | space-2xl–space-4xl | Use only where hierarchy requires it |
Margins primarily control separation from external content. Components must not impose unpredictable outer margins.
Gap
| Layout type | Recommended token |
|---|---|
| Icon and text | space-2xs |
| Closely related controls | space-xs |
| Form fields | space-sm |
| Card groups | space-md |
| Responsive grid columns | space-md–space-lg |
| Independent layout regions | space-xl |
| Major vertical sections | space-2xl |
Sizing
| Token | Web | Flutter | Use |
|---|---|---|---|
size-control-compact | 2rem / 32px | 32 dp | Dense visual control inside a larger hit target |
size-control-small | 2.5rem / 40px | 40 dp | Compact visual control inside a larger hit target |
size-control-medium | 2.75rem / 44px | 48 dp | Default interactive control |
size-control-large | 3rem / 48px | 56 dp | Prominent or touch-oriented control |
size-control-extra-large | 3.5rem / 56px | 64 dp | High-emphasis control |
size-target-minimum | 2.75rem / 44px | 48 dp | Minimum interactive hit area |
Compact controls use pseudo-elements, wrappers, padding, or layout containment to preserve the minimum hit area.
Icon Sizing
| Token | Web | Flutter | Use |
|---|---|---|---|
size-icon-xs | 0.75rem / 12px | 12 dp | Compact supplementary icon |
size-icon-sm | 1rem / 16px | 16 dp | Small control or metadata |
size-icon-md | 1.25rem / 20px | 20 dp | Default control icon |
size-icon-lg | 1.5rem / 24px | 24 dp | Prominent control or navigation |
size-icon-xl | 2rem / 32px | 32 dp | Display or empty-state icon |
Icon size and hit-target size are separate contracts.
Border Width
| Token | Web | Flutter | Use |
|---|---|---|---|
border-none | 0 | 0 dp | Intentional removal |
border-default | 0.0625rem / 1px | 1 dp | Standard containment and dividers |
border-strong | 0.125rem / 2px | 2 dp | Selected or emphasized boundaries |
border-focus | 0.1875rem / 3px | 3 dp | Visible keyboard focus indicator |
Hairline borders must not be represented as fractional physical pixels in Flutter.
Corner Radius
| Token | Web | Flutter | Use |
|---|---|---|---|
radius-none | 0 | 0 dp | Joined cells, edge-to-edge regions, and strict geometry |
radius-sm | 0.25rem / 4px | 4 dp | Dense controls and compact surfaces |
radius-md | 0.5rem / 8px | 8 dp | Default controls and containers |
radius-lg | 0.75rem / 12px | 12 dp | Cards, menus, and prominent surfaces |
radius-xl | 1rem / 16px | 16 dp | Large overlays and spacious containers |
radius-full | 9999px | 9999 dp or StadiumBorder | Avatars, tags, badges, and pill controls |
Nested surfaces should generally use an inner radius equal to the outer radius minus the intervening padding or border thickness.
5. Accessibility (WCAG 2.2 AA)
Interactive Target Size
- A minimum target area of
44 × 44 CSS pixelson the web. - A minimum target area of
48 × 48 dpin Flutter. - At least
space-2xsbetween adjacent targets where overlapping activation areas could cause errors. - Compact visual controls retain a larger invisible or transparent activation area.
- Standalone icon buttons use the same minimum target as labeled controls.
- Inline text links preserve adequate line height and separation when a larger rectangular target is not practical.
These system requirements intentionally exceed the WCAG 2.2 AA minimum target-size threshold.
Focus Rings, Borders, and Radius
- Use
border-focusfor the standard keyboard focus indicator. - Maintain at least
3:1contrast between the focus indicator and adjacent colors. - Place the focus ring outside the component border whenever possible.
- Use a minimum
2pxfocus offset. - Match the focus-ring shape to the component radius.
- Calculate an external focus radius as the component radius plus the focus offset.
- Do not clip the focus ring with overflow rules.
- Do not replace the focus indicator with a border-color change alone.
- Preserve focus visibility in forced-colors and high-contrast modes.
- Keep error, selected, disabled, and focus states distinguishable when simultaneous.
Borders representing controls or essential boundaries must meet 3:1 non-text contrast against adjacent colors unless another visible cue provides the required distinction.
6. MCP Server Context
Agent Instructions
Use only registered spacing, sizing, border, and radius tokens; never generate arbitrary numeric values when a canonical token can express the relationship. Apply smaller tokens within related component content, larger tokens between independent layout regions, and preserve minimum targets of 44x44 CSS pixels on Web and 48x48 dp in Flutter. Component APIs must receive semantic variants, while focus rings remain visible, contrast-compliant, radius-aligned, and unclipped.