Design tokens

From oborchers/fractional-cto · View interactive version

Design tokens is an AI agent skill from the GitHub repository oborchers/fractional-cto. This skill should be used when the user is building or reviewing theming systems, design tokens, dark mode implementation, CSS custom properties, color naming conventions, or theme switching architecture. Covers the three-tier token model (primitive/semantic/component), purpose-based naming, and the

How to use this skill

Skill file

Design Tokens Make Theming a Non-Event

The industry has converged on a three-tier token architecture. Adopting it correctly means theme switching requires only toggling a class — no component re-renders, no complex logic.

Three-Tier Token Architecture

Tier 1: Primitive Tokens

Raw values. The palette.

Examples: #3B82F6, 16px, 600

Tier 2: Semantic Tokens

Purpose-driven aliases. The meaning layer.

Examples: --color-text-primary, --color-bg-surface, --spacing-md

Tier 3: Component Tokens

Scoped references. The component layer.

Examples: --button-bg, --card-border-radius, --input-border-color

The Critical Naming Rule

Name tokens by purpose, not appearance.

| Bad (appearance) | Good (purpose) |

|-----------------|----------------|

| --color-white | --color-bg-surface |

| --color-blue-500 | --color-action-primary |

| --font-large | --font-heading |

| --color-gray-200 | --color-border-default |

--color-bg-surface works in both light and dark mode. --color-white becomes meaningless the moment themes change.

Theme Switching Architecture

Use CSS custom properties with a class toggle on the root element. CSS variables cascade down, automatically updating every component without re-rendering the component tree.

Implementation pattern:

  1. Define semantic tokens as CSS custom properties
  2. Override values in a .dark (or [data-theme="dark"]) selector
  3. Toggle the class/attribute on <html> to switch themes
  4. No JavaScript re-renders needed

Dark Mode Implementation

Use the hybrid approach:

  1. Detect system preference with prefers-color-scheme
  2. Allow manual override via a toggle
  3. Store the preference in localStorage
  4. Apply via a data-theme attribute on <html>

Consider Twitter's three-option model for apps where users spend long sessions:

W3C Design Tokens Community Group

The DTCG released the first stable specification (2025.10), backed by Adobe, Amazon, Google, Figma, Shopify, and others. Adopting the DTCG JSON format future-proofs token architecture for cross-platform tooling and design-to-code pipelines.

Examples

Working implementations in examples/:

Review Checklist

When reviewing or building a token/theming system:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.