Theming

How a brand palette becomes CSS variables every component reads.

BrandTheme writes each token of the palette to a CSS variable on its own element. Components read only these variables, so you can nest themes, show two brands side by side, or switch at runtime.

Tokens

TokenCSS variableUsed for
surface--bs-surfacePage background
elevated--bs-elevatedCards, fields, popups
ink--bs-inkText
muted--bs-mutedSecondary text, field borders
accent--bs-accentPrimary actions, focus rings, highlights
onAccent--bs-on-accentText on the accent
line--bs-lineDividers and outlines
font--bs-fontBody and UI type
radius--bs-radiusCorner radius
voiceFont--bs-voice-fontOptional second family for promise lines

Two more are derived: --bs-accent-soft and --bs-line-soft, light tints for highlights and dividers.

Motion

Components time their movement with a few shared variables. Override any of them on a BrandTheme or a parent element to change the feel of a whole brand.

CSS variableDefaultUsed for
--bs-ease-outcubic-bezier(.2,.7,.2,1)Things arriving: panels, slides, list items
--bs-ease-in-outcubic-bezier(.41,.19,.13,.95)Things moving from one place to another
--bs-ease-springcubic-bezier(.34,1.56,.64,1)Things that answer a tap: menus, tabs, switches, cards
--bs-duration-fast150msFades on small popups
--bs-duration420msMost movement
--bs-duration-slow700msList entrances
--bs-stagger60msGap between list items entering one after another

--bs-ease still works and points at --bs-ease-out. When the reader asks for reduced motion, every component shows at rest.

Modes

mode="light" and mode="dark" pin a mode. mode="system" follows the reader's setting through prefers-color-scheme.

Contrast

The Brand Studio contract check fails a palette when ink, muted text or text on the accent falls under 4.5:1 against its background. Run it before you ship a palette:

npm run check:brand

Your own components

Read the same variables in your CSS and your components follow the brand too:

.promo {
  background: var(--bs-elevated);
  border: 1px solid var(--bs-line);
  border-radius: var(--bs-radius);
  color: var(--bs-ink);
}

Still, Deskhand and Hollis are fictional brands. The coffee photographs are original generated artwork. @brand-studio/ui is MIT licensed.