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: oklch() in CSS gives you color shades that look equally light

Css
~/tips/tip-css-oklch-color-palette

:root {

Changing only the lightness number gives a predictable set of shades for one hue.

In HSL, a yellow and a blue at the same lightness look nothing alike. oklch() is built around how bright colors look to people, which makes palettes much easier to tune by hand.

:root {
  --blue-300: oklch(80% 0.10 255);
  --blue-500: oklch(62% 0.19 255);
  --blue-700: oklch(45% 0.15 255);
  --green-500: oklch(62% 0.19 150);
}

The three numbers are lightness (0% to 100%), chroma (how colorful, starting at 0) and hue as an angle. To make a lighter or darker shade, I’d change the first number. To make a matching color in another hue, keep lightness and chroma and only change the angle, and the green above comes out about as bright as the blue.

The color space can also describe colors outside the classic sRGB range, so on a wide gamut screen a high chroma value can look more vivid than any hex code.

That is also the caveat. Not every combination exists on every screen, and a chroma that is too high for a given lightness gets mapped back into the display’s range, so two of your shades may end up looking the same. Keep chroma moderate for UI colors. Browser support is broad: Chrome 111, Firefox 113 and Safari 15.4.

Further reading: MDN: oklch()

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