4

Day 98: oklab() and oklch()

 1 year ago
source link: https://www.matuzo.at/blog/2023/100daysof-day98/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Day 98: oklab() and oklch()

posted on February 8., 2023

It’s time to get me up to speed with modern CSS. There’s so much new in CSS that I know too little about. To change that I’ve started #100DaysOfMoreOrLessModernCSS. Why more or less modern CSS? Because some topics will be about cutting-edge features, while other stuff has been around for quite a while already, but I just have little to no experience with it.


oklab() and oklch() are okay versions of lab() and lch() because lab() and lch() are not okay.

I will not pretend that I really understand this whole color on the web thing, how it works or why one color function offers many more options to developers than the other, but I did learn several things during this experiment. I understand why a color function like hsl() offers better DX than rgb(). I’ve learned that rgb(), hsl(), and hwb() use colors from the sRGB color space, and lab() and lch() colors from the CIELAB color space. These color functions are relevant now because they support more colors and modern monitors can display them. It kinda also makes sense to me why some people say that using lch() is more intuitive than lab().

This doesn’t sound too bad, but as soon as I dig deeper into colors, I soon reach a point where I’m out. It’s usually a graph or complicated formula that stops my enthusiasm. Why am I saying this? I don’t know, maybe self-defense, maybe to make you feel better and assure you it’s fine to not understand everything.

Anyway, now I’ve added hsl(), hwb(), lab(), and lch() to my tool belt, and along comes mary oklab() and oklch(). lab and lch are great, but not perfect. The main issue with lab and lch is that there's a bug with blue colors which turns blue purple.

3 shades of blue compared in lch and oklch. oklch colors look blue while lch colors turn purple.

oklab() and oklch() fix that.

Two triangles that are constant-hue slice of LCH and OKLCH spaces with the same hue. The LCH slice, the leftmost triangular shape, is blue on one side and purple on the other. The right shape, OKLCH, keeps a constant hue, as expected.

Source: evilmartians.com

The okay versions of lab and lch come with additional improvements. You can learn more about it Chris Lilley's presentation “Better than Lab? Gamut reduction CIE Lab & OKLab”.

See on CodePen.

Further reading

Want more?

  1. Previous post: Day 97: animating grids

Overview: 100 Days Of More Or Less Modern CSS

My blog doesn't support comments yet, but you can reply via e-mail.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK