Przejdź do treści głównej
← 🎨 CSS as a design system·Moduł B5 · Lekcja 15
ZadanieBuild a hero. <h1 class='hero'>2026 launch</h1>. Default styles: font-size 32px, color oklch(0.55 0.25 27). Add a @media (color-gamut: p3) override that sets color: color(display-p3 0.96 0.18 0.14).

@media (gama kolorów): progresywne ulepszanie dla żywych ekranów

75 XP7 min
Teoria

Detect the screen, not the browser

Not every "modern" browser is on a wide-gamut screen. Your visitor might use a 2018 budget laptop. So your fallback shouldn't be "always serve P3" — it should be "serve sRGB by default, opt into P3 when the display can show it."

.brand { color: oklch(0.55 0.25 27); }    /* sRGB-safe default */

@media (color-gamut: p3) {
  .brand { color: color(display-p3 0.95 0.20 0.18); }
}

@media (color-gamut: rec2020) {
  .brand { color: color(rec2020 0.95 0.20 0.18); }
}

color-gamut reports what range the display supports, regardless of OS or browser. Values from narrowest to widest:

ValueCoverage
srgbthe 1996 baseline
p3display-p3, ~25% wider than sRGB
rec2020the HDR-cinema gamut, ~75% wider than sRGB

The browser picks the most specific block where the screen meets the requirement.

What this gives you

Designers can publish two color tokens — sRGB-safe and wide-gamut — and the user automatically sees the right one without you sniffing for it.

What to remember

  • Pair this with OKLCH everywhere. OKLCH compresses gracefully when out of gamut, so even the sRGB fallback looks intentional.
  • Don't gate critical contrast on color-gamut — the sRGB version must still pass WCAG. Wide-gamut is a "looks even nicer" upgrade, not a "now legible" one.
🔒

Zarejestruj się, aby zacząć kodować

Teoria jest dostępna dla każdego. Edytor, podgląd na żywo i check odblokowują się z 7-dniowym darmowym okresem próbnym — wymagana karta, anuluj w dowolnym momencie.

Zarejestruj się — darmowy okres próbny →

Pierwsze 10 lekcji w każdej ścieżce jest darmowych. Karta nie jest wymagana.

← PoprzedniaNastępna lekcja →

Codziennie jedna wskazówka Python lub web — na maila

Krótko, ręcznie pisane, bez spamu. Wypisanie w jedno kliknięcie.