Brand colour tokens
When to use brand tokens
Your main brand colour belongs on ThemeProvider as brandColor: it drives buttons, links and focus rings, and its text colours are adjusted for contrast. Brand tokens are for the other colours a brand uses, such as a secondary colour, campaign colours or category colours (for example #8B5E3C for an "oak" brown).
You list hex colours in brand-tokens.css, and the generator writes seven tokens per colour for light and dark mode, with matching Tailwind utilities.
Declare Hex Inputs
Add your brand hex values to the INPUT section of brand-tokens.css.
Auto-Generate Cluster
npm run brand:gen writes the hover, text-on-fill, text and soft-tint tokens for light and dark mode, with text adjusted to WCAG AA contrast. It runs before dev and build.
Use the utilities
Use standard utilities like bg-brand-coral, text-brand-coral-contrast, and border-brand-teal.
Try a colour
Pick a preset or enter any hex to see the seven tokens the generator writes, and the contrast they reach:
--brand-oak--brand-oakBase solid fill--brand-oak-fgText on solid fills--brand-oak-hover±12% hover mix--brand-oak-contrastText on the page--brand-oak-subtle12% translucent bgSet up and generate
Running npx @shavin/cli init automatically creates your brand-tokens.css file, wires build hooks, and on Tailwind 3 adds brand-preset.mjs to your Tailwind config.
Step 1: Declare brand colors in brand-tokens.css
Add extra colours as hex values in the INPUT section. Your main brand colour is not set here: it is --brand, set with ThemeProvider brandColor.
/* brand-tokens.css — INPUT section (user-editable) */
/* ─── INPUT ─── */
--brand-oak: #8B5E3C;
--brand-coral: #FF6B6B;
--brand-teal: #14B8A6;
/* --brand-gold: #F59E0B; */ /* commented lines are skipped */Step 2: Generate derived tokens
Run the generator command (also triggers automatically before npm run dev and npm run build):
npm run brand:gen # computes derived tokens + writes brand-preset.mjs (v3) or brand-theme-v4.css (v4)
npm run brand:check # CI validation — exits 1 if brand tokens are staleStep 3 (Tailwind v3): Connect Tailwind Preset
In your application's tailwind.config.ts, include the generated brandPreset:
// tailwind.config.ts
import type { Config } from "tailwindcss";
import shavinPreset from "@shavin/ui/tailwind-preset";
import brandPreset from "./brand-preset.mjs";
const config: Config = {
presets: [shavinPreset, brandPreset],
content: [
"./src/**/*.{js,ts,jsx,tsx}",
"./node_modules/@shavin/ui/**/*.{js,ts,jsx,tsx}",
],
};
export default config;Step 3 (Tailwind v4): Import the generated theme file
On Tailwind v4 there is no JS config. brand:gen writes brand-theme-v4.css (an @theme inline block) next to brand-tokens.css instead of brand-preset.mjs. npx @shavin/cli init wires these imports for you:
/* globals.css — Tailwind v4 */
@import "tailwindcss";
@import "./brand-tokens.css";
@import "@shavin/ui/tokens.css";
@import "@shavin/ui/base.css" layer(base);
@import "@shavin/ui/theme-v4.css";
@import "./brand-theme-v4.css"; /* brand utilities: bg-brand-coral, … */
@import "tailwindcss";
@source "../../node_modules/@shavin/ui"; /* v4 skips node_modules */
@source not "../../.agents";OKLCH projects (init --oklch) use global-oklch.css, theme-v4-oklch.css and brand-theme-v4-oklch.css, and the generator keeps brand-tokens.css in OKLCH (brand:gen runs with --oklch).
The seven tokens
Every entry in brand-tokens.css generates the following seven semantic utilities in your Tailwind bundle:
| Suffix | Tailwind Classes | CSS Custom Property | Use |
|---|---|---|---|
| (base) | bg-brand-{name} | --brand-{name} | Solid brand fill for primary buttons, logos, and header banners. |
| -fg | text-brand-{name}-fg | --brand-{name}-fg | White text on solid brand fills while it reaches 4.5:1, otherwise near-black, whichever reads better. |
| -hover | hover:bg-brand-{name}-hover | --brand-{name}-hover | Luminance-aware ±12% darkened/lightened hover state fill. |
| -contrast | text-brand-{name}-contrast | --brand-{name}-contrast | Brand-coloured text and icons on the page. Darkened in light mode, or lightened in dark mode, until it reaches 4.6:1 contrast (WCAG AA) on every page surface. |
| -subtle | bg-brand-{name}-subtle | --brand-{name}-subtle | Soft tint for chips, badges and cards: 12% opacity in light mode, 15% in dark. |
| -subtle-hover | hover:bg-brand-{name}-subtle-hover | --brand-{name}-subtle-hover | Soft tint hover state: 18% opacity in light mode, 22% in dark. |
| -text | text-brand-{name}-text | --brand-{name}-text | Same value as -contrast, for readability in class names. |
Examples
Here is how you compose accessible branded cards, badges, and action bars using Tailwind utilities:
// Branded Callout Card Component
export function OakwoodFeatureCard() {
return (
// ds-lint-disable-next-line no-unknown-class — brand token example
<div className="p-5 rounded-[var(--radius-panel)] bg-brand-oak-subtle border border-hairline flex flex-col gap-3">
<div className="flex items-center justify-between">
// ds-lint-disable-next-line no-unknown-class — brand token example
<span className="px-2 py-0.5 rounded-[var(--radius-lg)] text-xs font-semibold bg-brand-oak text-brand-oak-fg">
Artisanal Roast
</span>
// ds-lint-disable-next-line no-unknown-class — brand token example
<span className="text-xs font-mono text-brand-oak-contrast">Single Origin</span>
</div>
// ds-lint-disable-next-line no-unknown-class — brand token example
<h3 className="text-sm font-bold text-brand-oak-contrast">
Oakwood Signature Blend
</h3>
<p className="text-xs text-fg-muted leading-relaxed">
Locally roasted with notes of hazelnut and dark chocolate.
</p>
<div className="flex items-center gap-2 pt-1">
// ds-lint-disable-next-line no-unknown-class — brand token example
<button className="px-3 py-1.5 rounded-[var(--radius-lg)] text-xs font-semibold bg-brand-oak hover:bg-brand-oak-hover text-brand-oak-fg transition-colors">
Order Now
</button>
// ds-lint-disable-next-line no-unknown-class — brand token example
<button className="px-3 py-1.5 rounded-[var(--radius-lg)] text-xs font-semibold border border-hairline text-brand-oak-contrast hover:bg-brand-oak-subtle-hover transition-colors">
View Notes
</button>
</div>
</div>
);
}