Naar hoofdinhoud
← 🎨 CSS as a design systemΒ·Module B5 Β· Les 7
OpdrachtVerify a token palette passes AA. :root tokens: --bg #ffffff (rgb 255,255,255), --text oklch(0.20 0 0) (passes AAA against white), --text-muted oklch(0.50 0 0) (passes AA), --primary oklch(0.55 0.18 252) (a darker blue that passes AA against white), --primary-fg white. body uses --bg + --text. .alert uses --primary as background + --primary-fg as color.

Contrast voor toegankelijkheid (WCAG AA-samenvatting)

75 XP6 min
Theorie

The numbers from A5, applied to design tokens

(Quick recap from HTML A5 lesson 4 β€” now we apply it through tokens.)

WCAG AA requires:

  • Body text: 4.5:1 contrast against background.
  • Large text (18pt+ regular or 14pt+ bold): 3:1.
  • UI elements (buttons, focus rings): 3:1.

When you build a token palette, ensure every --text value passes against every --bg value:

:root {
  --bg: white;
  --text: oklch(0.20 0 0);        /* dark gray β€” passes 7:1 against white */
  --text-muted: oklch(0.50 0 0);  /* mid gray β€” passes 4.5:1 (just) */
  --text-disabled: oklch(0.65 0 0); /* light gray β€” FAILS body, passes large only */
}

Be honest about what disabled colors are FOR. --text-disabled is meant for disabled UI controls where 3:1 is the floor.

Tool tips

  • Chrome DevTools color picker β†’ shows the contrast ratio + AA/AAA pass.
  • axe DevTools extension β†’ flags every contrast violation across the page.
  • WebAIM Contrast Checker β†’ compute manually.

Dark mode contrast

In dark mode, contrast is BETWEEN dark and light. Pure black (#000) on near-black surface (#0D1117) fails. Use:

  • Dark mode body bg: oklch(0.18 0 0) (β‰ˆ #1c1c1c)
  • Dark mode body text: oklch(0.95 0 0) (β‰ˆ #f2f2f2)

That pair = 12:1 contrast. Passes AAA.

Brand-color contrast

.btn-primary { background: var(--primary); color: var(--primary-fg); }

Make sure --primary-fg (the text COLOR shown on the primary background) passes 4.5:1 against --primary. White-on-blue (#3B82F6) passes (4.5:1 exactly). White-on-yellow fails β€” needs dark text.

πŸ”’

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.