Naar hoofdinhoud
← 🎨 CSS as a design systemΒ·Module B5 Β· Les 4
OpdrachtDefine 10 design tokens on :root. Use them: body bg var(--bg), color var(--text). .card has background var(--surface), border 1px solid var(--border), border-radius var(--radius), padding var(--space-md). .btn-primary has background var(--primary), color var(--primary-fg), padding var(--space-sm) var(--space-md), border-radius var(--radius), border none.

Ontwerptokens: --primary, --bg, --text, --border

75 XP6 min
Theorie

A small token set covers 80% of UI

:root {
  /* Semantic tokens β€” what they're used FOR, not what they ARE */
  --bg: white;
  --surface: oklch(0.98 0 0);            /* card / panel background */
  --text: oklch(0.20 0 0);
  --text-muted: oklch(0.50 0 0);
  --border: oklch(0.90 0 0);
  --primary: oklch(0.66 0.18 252);
  --primary-fg: white;                    /* text color ON primary background */
  --danger: oklch(0.62 0.20 27);
  --success: oklch(0.66 0.16 145);
  --warning: oklch(0.78 0.14 75);
  --radius: 8px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
}

Semantic > literal

Compare:

/* DON'T β€” name colors by what they are */
:root { --blue-500: oklch(0.66 0.18 252); }
.btn { background: var(--blue-500); }

/* DO β€” name colors by what they're FOR */
:root { --primary: oklch(0.66 0.18 252); }
.btn { background: var(--primary); }

When you rebrand from blue to green, "blue-500" becomes a misnomer. "primary" still makes sense β€” it just maps to a different OKLCH value.

You can have BOTH layers: literal scale (--blue-50 to --blue-900) PLUS semantic tokens (--primary maps to --blue-500). Tailwind's color system works this way.

Why these 10 tokens are enough

  • bg + surface β€” page and panel backgrounds.
  • text + text-muted + primary-fg β€” three text colors covers everything.
  • border β€” separators, inputs, panels.
  • primary + danger + success + warning β€” every UI state.
  • radius + space-sm/md/lg β€” geometry.

Anything more is usually scope creep. Start here, add more only when you need them.

πŸ”’

Registreer om te beginnen met coderen

Theorie is voor iedereen. De editor, live preview en check ontgrendelen met een 7-daagse gratis proefperiode β€” kaart vereist, opzegbaar.

Registreren β€” gratis proef β†’

De eerste 10 lessen in elke track zijn gratis. Geen kaart nodig.

← VorigeVolgende les β†’

EΓ©n Python- of web-tip per dag β€” per e-mail

Kort, met de hand geschreven, geen spam. Met één klik afmelden.