# Design Tokens and Theming

> Encode colours, spacing, typography and radii as named tokens so design and code share one source of truth and themes are easy. Free notes, key concepts,...

Canonical: https://www.internhack.in/roadmaps/tracks/frontend/design-tokens
Last updated: 2026-11-28

Encode colours, spacing, typography and radii as named tokens so design and code share one source of truth and themes are easy.

Intermediate · about 3 hours · difficulty 2/5

Learn first: [Custom Properties and Modern CSS Features](https://www.internhack.in/roadmaps/tracks/frontend/modern-css), [Tailwind CSS](https://www.internhack.in/roadmaps/tracks/frontend/tailwind)

A **design system** is the shared language of a product: tokens, components, patterns and guidelines. Its foundation is **design tokens**, named values for every visual decision, used by designers in Figma and by developers in code.

### Token layers

- **Primitive (base) tokens**: the raw palette and scales, such as `blue-600`, `space-4`, `radius-md`, `font-size-lg`.
- **Semantic tokens**: meaning, not appearance, such as `color-bg-surface`, `color-text-muted`, `color-border-danger`. Components use these.
- **Component tokens** (optional): `button-primary-bg` for fine control.

Themes (light, dark, high contrast, brand variants) simply remap semantic tokens to different primitives. Components never change.

### In code

- Implement tokens as **CSS custom properties** on `:root` and theme selectors (`[data-theme="dark"]`), consumed by plain CSS, CSS Modules or a Tailwind theme.
- Respect `prefers-color-scheme` by default, let users override, persist the choice and set it before first paint to avoid a flash of the wrong theme.
- Tools like **Style Dictionary** or Figma variables exports can generate CSS, TypeScript and mobile formats from a single JSON source.
- Check every theme for **contrast** and visible focus rings.

### Beyond tokens

Consistent spacing rhythm, a type scale, elevation (shadows) and motion durations are tokens too. Document when to use each, not just what exists.

### Pitfalls

Using primitive tokens directly in components (dark mode then needs edits everywhere), inventing one-off values, and themes that were never tested for contrast.

### Good enough to move on

You can define primitive and semantic tokens, build light and dark themes with no flash on load, and explain why components should reference semantic tokens.

## Key concepts

- **What a design system includes**
- **Primitive vs semantic tokens**
- **Tokens as CSS custom properties**
- **Light, dark and high-contrast themes**
- **Avoiding theme flash on load**
- **Style Dictionary and Figma variables**
- **Type scale and spacing rhythm**

## Mini project

Create a token set (primitives plus semantic tokens) for a fictional brand, implement light, dark and high-contrast themes with a persisted toggle and no flash on load, and verify contrast for each.

## Check yourself

Why should a Button use color-bg-accent rather than blue-600 directly?

## Free resources

- [Using CSS custom properties](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_cascading_variables/Using_CSS_custom_properties) (MDN)
- [Style Dictionary](https://styledictionary.com/) (Style Dictionary)
- [Design Tokens Community Group](https://www.designtokens.org/) (W3C Community Group)

Previous: [Real-Time Communication: WebSockets and SSE](https://www.internhack.in/roadmaps/tracks/frontend/realtime) · Next: [Component Libraries: shadcn/ui and Radix](https://www.internhack.in/roadmaps/tracks/frontend/component-libraries)

## More in Design Systems, Motion and Internationalisation

- [Design Tokens and Theming](https://www.internhack.in/roadmaps/tracks/frontend/design-tokens)
- [Component Libraries: shadcn/ui and Radix](https://www.internhack.in/roadmaps/tracks/frontend/component-libraries)
- [Storybook and Component Documentation](https://www.internhack.in/roadmaps/tracks/frontend/storybook)
- [UI Animation with Motion Libraries](https://www.internhack.in/roadmaps/tracks/frontend/motion)
- [Internationalisation and Localisation](https://www.internhack.in/roadmaps/tracks/frontend/i18n)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Frontend Developer Roadmap](https://www.internhack.in/roadmaps/tracks/frontend)
