Sari la conținutul principal
← 🎨 CSS as a design system·Modul B5 · Lecția 4
SarcinăDefine 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.

Jetoane de proiectare: --primary, --bg, --text, --border

75 XP6 min
Teorie

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.

🔒

Înregistrează-te pentru a începe să programezi

Teoria e accesibilă tuturor. Editorul, previzualizarea live și verificarea se deblochează cu o probă gratuită de 7 zile — card necesar, anulabilă oricând.

Înregistrare — probă gratuită →

Primele 10 lecții din fiecare traseu sunt gratis. Fără card.

← AnterioarăLecția următoare →

Primește un sfat Python sau web pe zi — prin email

Scurt, scris de mână, fără spam. Dezabonare cu un click.