Skip to main content
v0.1 dev

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 gap for 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, and large.
  • 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, or 27px.
  • 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 scalesemantic layout rolecomponent tokencomponent 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.

4. Specifications & Anatomy

Spacing Scale

TokenWebFlutterPrimary use
space-none00 dpIntentional removal of spacing
space-3xs0.25rem / 4px4 dpOptical adjustment and compact icon relationships
space-2xs0.5rem / 8px8 dpClosely related inline content
space-xs0.75rem / 12px12 dpCompact control padding and small gaps
space-sm1rem / 16px16 dpDefault internal padding and text grouping
space-md1.5rem / 24px24 dpCards, grouped controls, and content blocks
space-lg2rem / 32px32 dpLarge component padding and group separation
space-xl3rem / 48px48 dpSection separation
space-2xl4rem / 64px64 dpDefault page-section rhythm
space-3xl5rem / 80px80 dpLarge layout separation
space-4xl6rem / 96px96 dpHigh-emphasis layout separation

Inner Padding

ContextCompactDefaultSpacious
Icon and labelspace-2xsspace-xsspace-sm
Button horizontal paddingspace-xsspace-smspace-md
Form control paddingspace-xsspace-smspace-md
Card paddingspace-smspace-mdspace-lg
Dialog or drawer paddingspace-mdspace-lgspace-xl
Page container paddingspace-smspace-lgspace-xl

Outer Margins

RelationshipTokenRule
Text inside one content groupspace-2xs–space-smPreserve a visible relationship
Components inside one workflowspace-sm–space-mdUse parent-controlled spacing
Independent component groupsspace-lgEstablish clear separation
Sections within a pagespace-xl–space-2xlScale down at compact breakpoints
Major page regionsspace-2xl–space-4xlUse only where hierarchy requires it

Margins primarily control separation from external content. Components must not impose unpredictable outer margins.

Gap

Layout typeRecommended token
Icon and textspace-2xs
Closely related controlsspace-xs
Form fieldsspace-sm
Card groupsspace-md
Responsive grid columnsspace-md–space-lg
Independent layout regionsspace-xl
Major vertical sectionsspace-2xl

Sizing

TokenWebFlutterUse
size-control-compact2rem / 32px32 dpDense visual control inside a larger hit target
size-control-small2.5rem / 40px40 dpCompact visual control inside a larger hit target
size-control-medium2.75rem / 44px48 dpDefault interactive control
size-control-large3rem / 48px56 dpProminent or touch-oriented control
size-control-extra-large3.5rem / 56px64 dpHigh-emphasis control
size-target-minimum2.75rem / 44px48 dpMinimum interactive hit area

Compact controls use pseudo-elements, wrappers, padding, or layout containment to preserve the minimum hit area.

Icon Sizing

TokenWebFlutterUse
size-icon-xs0.75rem / 12px12 dpCompact supplementary icon
size-icon-sm1rem / 16px16 dpSmall control or metadata
size-icon-md1.25rem / 20px20 dpDefault control icon
size-icon-lg1.5rem / 24px24 dpProminent control or navigation
size-icon-xl2rem / 32px32 dpDisplay or empty-state icon

Icon size and hit-target size are separate contracts.

Border Width

TokenWebFlutterUse
border-none00 dpIntentional removal
border-default0.0625rem / 1px1 dpStandard containment and dividers
border-strong0.125rem / 2px2 dpSelected or emphasized boundaries
border-focus0.1875rem / 3px3 dpVisible keyboard focus indicator

Hairline borders must not be represented as fractional physical pixels in Flutter.

Corner Radius

TokenWebFlutterUse
radius-none00 dpJoined cells, edge-to-edge regions, and strict geometry
radius-sm0.25rem / 4px4 dpDense controls and compact surfaces
radius-md0.5rem / 8px8 dpDefault controls and containers
radius-lg0.75rem / 12px12 dpCards, menus, and prominent surfaces
radius-xl1rem / 16px16 dpLarge overlays and spacious containers
radius-full9999px9999 dp or StadiumBorderAvatars, 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 pixels on the web.
  • A minimum target area of 48 × 48 dp in Flutter.
  • At least space-2xs between 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-focus for the standard keyboard focus indicator.
  • Maintain at least 3:1 contrast between the focus indicator and adjacent colors.
  • Place the focus ring outside the component border whenever possible.
  • Use a minimum 2px focus 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.