Прескочи на главни садржај
← 🎨 CSS as a design system·Модул B5 · Лекција 3
ЗадатакBuild a button with hover/pressed states using color-mix. :root --primary oklch(0.66 0.18 252). .btn background var(--primary), color white. .btn:hover background color-mix(in oklch, var(--primary), white 15%). .btn:active background color-mix(in oklch, var(--primary), black 15%).

цолор-мик(): изводи нијансе из једног извора

100 XP7 min
Теорија

One color, infinite tints

:root { --brand: oklch(0.66 0.18 252); }

.hover    { background: color-mix(in oklch, var(--brand), white 20%); }   /* 20% lighter */
.pressed  { background: color-mix(in oklch, var(--brand), black 20%); }   /* 20% darker */
.bg-tint  { background: color-mix(in oklch, var(--brand), transparent 90%); } /* 10% opacity */

color-mix(in COLORSPACE, COLOR-A, COLOR-B PERCENT) blends A and B at the given percentage in the specified color space.

Why mix in OKLCH

color-mix(in srgb, blue, white 30%);     /* sRGB mix — can look washed out */
color-mix(in oklch, blue, white 30%);    /* OKLCH mix — perceptually correct */

OKLCH interpolation keeps perceived brightness on the path. Use it for any "lighten/darken" mix.

Common patterns

:root { --primary: oklch(0.66 0.18 252); }

.button { background: var(--primary); }
.button:hover { background: color-mix(in oklch, var(--primary), white 15%); }
.button:active { background: color-mix(in oklch, var(--primary), black 15%); }

ONE source color, derived states. Redesign? Change --primary once, all states update.

Browser support (2026)

Chrome / Edge / Safari / Firefox all shipped. Treat as fully available. Older Safari (<16.4) needs the @supports (color: color-mix(...)) fallback for production sites with long-tail support.

🔒

Региструј се да почнеш са кодом

Теорија је отворена за све. Едитор, преглед уживо и провера се откључавају са 7-дневним бесплатним пробним периодом — потребна картица.

Регистрација — бесплатан пробни период →

Првих 10 лекција у сваком путу су бесплатне. Без картице.

← ПретходнаСледећа лекција →

Један савет за Python или веб дневно — на имејл

Кратко, ручно писано, без спама. Одјава у једном клику.