Перейти до основного вмісту
← 🎨 CSS as a design system·Модуль B5 · Урок 1
ЗавданняStyle three elements: .a with color #3B82F6 (hex), .b with rgb(59 130 246 / 0.7) (modern rgb), .c with oklch(0.66 0.18 252) (OKLCH equivalent of the same blue).

Формати кольорів: hex, rgb, hsl, oklch

75 XP7 min
Теорія

Four ways to write the same color

.a { color: #3B82F6; }                /* hex — short, opaque (or #3B82F6ff for full alpha) */
.b { color: rgb(59 130 246 / 0.8); }  /* modern rgb (no commas, slash for alpha) */
.c { color: hsl(217 91% 60% / 0.8); } /* hue saturation lightness */
.d { color: oklch(0.66 0.18 252 / 0.8); } /* OKLCH — modern, perceptually uniform */

When to use each

  • `#hex` — copy-paste from Figma. Familiar. Fine for static brand colors.
  • `rgb()` — when you need alpha and the color came from a designer as RGB. Use the modern slash syntax: rgb(255 0 0 / 0.5).
  • `hsl()` — when you want to MANIPULATE the color (lighten, darken, shift hue) by tweaking one channel.
  • `oklch()` — when you want perceptual uniformity across hues. Best modern default.

What's wrong with hsl?

HSL was meant to be intuitive: "blue at 50% lightness, green at 50% lightness." But human vision isn't proportional to RGB lightness — at the same HSL lightness, yellow looks WAY brighter than blue. Algorithmic palette generation in HSL produces lumpy results.

What OKLCH fixes

  • L (lightness) — perceptual lightness. 0.5 looks like 0.5 across every hue.
  • C (chroma) — saturation. 0 = grey, ~0.3 = vivid.
  • H (hue) — degree on the color wheel (0-360).

Same L → same perceived brightness across blue, green, red. Critical for design-system palettes.

🔒

Зареєструйся щоб кодувати

Теорія відкрита всім. Інтерактивний редактор, живий перегляд і перевірка відкриваються з 7-денним безкоштовним trial — потрібна картка, скасування у будь-який час.

Реєстрація — безкоштовний trial →

Перші 10 уроків у кожному треку — безкоштовні. Картка не потрібна.

← НазадНаступний урок →

Отримуй одну пораду з Python чи вебу — щодня поштою

Коротко, без води, без спаму. Відписка — в один клік.