Menu

HSL lies about lightness. Build color palettes in OKLCH instead
📰

HSL lies about lightness. Build color palettes in OKLCH instead

DEV Community: tailwindcss·AppyGrid·3 days ago
#i50CxsmI
#devtotailwindcss#devto#dev#color#lightness
Long article (868 words) — no AI summary yet.
Reading 0:00
15s threshold

When I rebuilt the color palette generator on my tools site, I had to decide which color space to do the maths in. HSL is the obvious choice. It's also wrong in a way that's easy to see.

Here are two colors with exactly the same HSL lightness:

--yellow : hsl ( 60 100 % 50 % ) ; /* #ffff00 */ --blue : hsl ( 240 100 % 50 % ) ; /* #0000ff */

Enter fullscreen mode

Exit fullscreen mode

Put white text on both. On the blue it's perfectly readable. On the yellow you can barely see it. So whatever "50% lightness" means, it isn't what your eyes see.

How far off it is

HSL lightness is just arithmetic on the red, green and blue values. It knows nothing about how bright each color looks to a person. OKLCH does: its L is designed to match perceived lightness.

I ran six colors through both.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.