To source

Design Tokens

Understanding the design token architecture used in Atrium components.

Components come with a default design-system based on design tokens. This guide explains the token architecture and how to customise it for your projects.

What Are Design Tokens?

Design tokens are the atomic values that define your visual design language. They create a single source of truth that keeps your UI consistent and makes theming straightforward.

/* Tokens are defined as CSS custom properties */
:root {
  --color-primary: #3b82f6;
  --spacing-md: 16px;
  --font-size-base: 1rem;
}

Token Categories

Primitives vs Semantic Tokens

Primitives are raw values without context:

:root {
  --blue-500: #3b82f6;
  --blue-600: #2563eb;
  --gray-100: #f3f4f6;
  --gray-900: #111827;
}

Semantic tokens reference primitives and provide meaning:

:root {
  --color-primary: var(--blue-500);
  --color-primary-hover: var(--blue-600);
  --color-background: var(--gray-100);
  --color-text: var(--gray-900);
}

This separation allows you to change your entire colour palette by updating primitives, while semantic tokens maintain their purpose.

Spacing

Spacing tokens follow a consistent scale based on a 4px base unit:

TokenValueUse Case
--spacing-xs4pxTight spacing, icon gaps
--spacing-sm8pxCompact elements, small gaps
--spacing-md16pxDefault spacing, padding
--spacing-lg24pxSection spacing
--spacing-xl32pxLarge gaps
--spacing-2xl48pxMajor section breaks
--spacing-3xl64pxPage-level spacing
--spacing-4xl96pxHero sections

Usage in Components

.card {
  padding: var(--spacing-md);
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-lg);
}

Colours

Semantic Colour Tokens

TokenPurpose
--color-primaryBrand colour, primary actions
--color-secondarySecondary actions, accents
--color-backgroundPage background
--color-surfaceCard and component backgrounds
--color-textPrimary text
--color-text-mutedSecondary/helper text
--color-borderBorders and dividers
--color-errorError states
--color-successSuccess states
--color-warningWarning states

Defining a Colour Palette

:root {
  /* Primitives */
  --brand-50: #eff6ff;
  --brand-100: #dbeafe;
  --brand-500: #3b82f6;
  --brand-600: #2563eb;
  --brand-700: #1d4ed8;

  /* Semantic */
  --color-primary: var(--brand-500);
  --color-primary-hover: var(--brand-600);
  --color-primary-active: var(--brand-700);
}

Theming with Modes

Support dark mode and other themes using CSS custom properties:

:root {
  --color-background: #ffffff;
  --color-surface: #f9fafb;
  --color-text: #111827;
  --color-text-muted: #6b7280;
}

[data-theme="dark"],
.dark {
  --color-background: #111827;
  --color-surface: #1f2937;
  --color-text: #f9fafb;
  --color-text-muted: #9ca3af;
}

/* Or use media query for system preference */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-background: #111827;
    --color-surface: #1f2937;
    --color-text: #f9fafb;
    --color-text-muted: #9ca3af;
  }
}

Grid and Breakpoints

Grid System

The layout uses a flexible grid based on CSS Grid:

Grid

.grid-container {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: var(--spacing-md);
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--spacing-md);
}

Breakpoints

BreakpointWidthDescription
sm640pxSmall devices, large phones
md768pxTablets
lg1024pxSmall laptops
xl1280pxDesktops
2xl1536pxLarge screens

Usage with TailwindCSS:

<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
  <!-- Responsive grid -->
</div>

Typography

Font Scale

TokenSizeLine HeightUse Case
--font-size-xs0.75rem (12px)1remCaptions, labels
--font-size-sm0.875rem (14px)1.25remSmall text, metadata
--font-size-base1rem (16px)1.5remBody text
--font-size-lg1.125rem (18px)1.75remLead paragraphs
--font-size-xl1.25rem (20px)1.75remSmall headings
--font-size-2xl1.5rem (24px)2remSection headings
--font-size-3xl1.875rem (30px)2.25remPage headings
--font-size-4xl2.25rem (36px)2.5remHero headings

Font Families

:root {
  --font-sans: ui-sans-serif, system-ui, sans-serif;
  --font-serif: ui-serif, Georgia, serif;
  --font-mono: ui-monospace, monospace;
}

Typography Classes

.typo-title-1 {
  font-size: var(--font-size-4xl);
  font-weight: 700;
  line-height: 1.2;
}

.typo-title-2 {
  font-size: var(--font-size-3xl);
  font-weight: 600;
  line-height: 1.3;
}

.typo-headline {
  font-size: var(--font-size-xl);
  font-weight: 600;
  line-height: 1.4;
}

.typo-body {
  font-size: var(--font-size-base);
  line-height: 1.5;
}

Using Tokens in Elements

Elements accept CSS custom properties for customisation:

/* Customise the calendar element */
a-calendar {
  --calendar-hover-bg: rgba(0, 0, 0, 0.1);
  --calendar-selected-bg: var(--color-primary);
  --calendar-selected-color: white;
}

/* Customise the range slider */
a-range {
  --range-handle-background: var(--color-primary);
  --range-progress-background: var(--color-primary);
  --range-track-background: var(--color-border);
}

Each element's documentation lists its available CSS custom properties.

Tailwind

When using TailwindCSS, create a theme with your tokens, css variables will be created automatically:

@theme custom {
  --color-primary: #3b82f6;
  --color-secondary: #2563eb;
  --color-surface: #f9fafb;

  ...
}

Then use in your components:

<button class="bg-primary text-white">
  Click me
</button>

References