brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: color-mix() in css builds hover and tint colors from one variable

Css
~/tips/tip-css-color-mix-from-variable

:root { --accent: #0b6bcb; }

Blends two colors so shades and tints can be derived from a single base color.

I would rather change one brand color than maintain a hand-picked palette of shades.

:root { --accent: #0b6bcb; }
.btn { background: var(--accent); }
.btn:hover { background: color-mix(in oklab, var(--accent), black 15%); }
.note { background: color-mix(in oklab, var(--accent) 12%, white); }

color-mix() blends two colors in a chosen color space. The percentage says how much of that color goes in, and the rest is filled by the other one. Darker hover states and pale backgrounds then follow the variable automatically. oklab mixes in a perceptual color space, which usually looks more even than sRGB. It works in Chrome 111, Safari 16.2, Firefox 113 and newer, so keep a plain color as a fallback line above it if you still need older browsers.

Further reading: MDN: color-mix()

More Css tips CSS Overview in Chrome DevTools audits the colors and fonts of a page .notice:empty { .toast { article { counter-reset: h2; } .toolbar { All Css tips (66) All topics

Link