CSS variables and design tokens

CSS custom properties let you define a value once and reference it anywhere. Define your brand color as --primary in the root and every component references --primary instead of the raw hex. Change the root, and every usage updates at once. This is the native version of what design systems call tokens.

style.css
css
:root {
  --primary: #10b981;
  --text: #1c1917;
  --bg: #fafaf9;
  --radius: 0.5rem;
  --space: 1rem;
}

.button {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: var(--space);
}

Define tokens at the root, use them throughout the stylesheet.

Dark mode becomes almost free. Define the variables in a media query or on a class, and every component updates at once. No deep rewrites, no chasing every rule that uses a color. Reach for tokens early and reap the benefits on every project.

Quiz: Quiz

Loading practice…

Checkpoint: Native CSS layout checkpoint

Loading practice…