# Tailwind with the tokens Tailwind is fine as long as the tokens stay the single source of truth. Never use Tailwind's stock palette (`bg-blue-600`, `text-gray-500`) in components. Map the tokens into the theme and use only those names. ## Tailwind v4 (CSS-first config) ```css /* src/styles/app.css */ @import "tailwindcss"; @import "./tokens.css"; /* the file from assets/tokens.css */ /* Explicit toggle. System dark mode needs no variant: the tokens already switch. */ @custom-variant dark (&:where([data-theme="dark"], [data-theme="dark"] *)); @theme inline { --color-*: initial; /* drop the stock palette */ --color-bg: var(--bg); --color-surface: var(--surface); --color-surface-2: var(--surface-2); --color-border: var(--border); --color-border-strong: var(--border-strong); --color-fg: var(--fg); --color-fg-muted: var(--fg-muted); --color-fg-subtle: var(--fg-subtle); --color-accent: var(--accent); --color-accent-hover: var(--accent-hover); --color-accent-fg: var(--accent-fg); --color-accent-soft: var(--accent-soft); --color-accent-text: var(--accent-text); --color-ring: var(--ring); --color-ok: var(--ok); --color-ok-soft: var(--ok-soft); --color-warn: var(--warn); --color-warn-soft: var(--warn-soft); --color-danger: var(--danger); --color-danger-soft: var(--danger-soft); --color-info: var(--info); --color-info-soft: var(--info-soft); --color-transparent: transparent; --color-current: currentColor; /* Names must differ from the token they read, or the variable refers to itself and becomes invalid. */ --font-heading: var(--font-display); /* class: font-heading */ --font-sans: var(--font-body); --shadow-card: var(--shadow-raised); /* class: shadow-card */ --shadow-menu: var(--shadow-popover); --shadow-dialog: var(--shadow-modal); /* --radius-sm/md/lg, --font-mono and --ease-out need no mapping: tokens.css declares them with Tailwind's own names, unlayered, so they override Tailwind's defaults. */ } ``` Because the colors resolve through CSS variables that already switch with the theme, components rarely need `dark:` variants at all: `bg-surface text-fg border-border` is correct in both themes. Usage examples: ```html