惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
博客园 - Franky
V
V2EX
Y
Y Combinator Blog
Google DeepMind News
Google DeepMind News
J
Java Code Geeks
T
The Blog of Author Tim Ferriss
罗磊的独立博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Jina AI
Jina AI
博客园 - 叶小钗
F
Fortinet All Blogs
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
A
About on SuperTechFans
M
MIT News - Artificial intelligence
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
D
Docker
博客园 - 【当耐特】
阮一峰的网络日志
阮一峰的网络日志

Matthias Ott

Hello Again, World This, Still Not for Everyone The Shape of Friction WeissKlang L1 – Punching Above Its Weight Continvoucly Morged Value Webspace Invaders To Affinity and Beyond The Mystery of Storytelling Amateurs! Echoes of Connection Linear() Is Not (That) Linear View Transitions: The Smooth Parts Adding AVIF and WebP Support to My Craft CMS Site Challenge Acoustic Room Treatment and Building Sound Panels, Part 1: Planning Play On Overshoot The HTML Output Element Listening Closely Compressed Fluid Typography The Lifeblood of the Web What Could Go Wrong? That’s My Rank Making Space CSS :is() :where() the Magic Happens Visual Regression Testing for External URLs With Playwright Jane Goodall’s Famous Last Words European Tech Alternatives 🇪🇺 Independent Type Foundry Advent Calendar – Day 24: NaN Independent Type Foundry Advent Calendar – Day 23: Typotheque
World Wide Gamut Web
Matthias Ott · 2020-06-03 · via Matthias Ott

Color on the Web has seen many iterations. When I started to fall in love with the Web in the late nineties, every self-respecting web designer was using web-safe colors. Although it can be argued that they never really worked, because colors still looked different on different screens, web-safe colors were at least the attempt to achieve consistency in a time where it was worth mentioning in ads that a monitor was able to display “millions of colors“.

Today, we are using not only the hex notation and rgb() in CSS but also rgba() to control transparency. Our displays have grown to be much more accurate in how they display color. And in recent years, so-called wide gamut displays have become increasingly popular. While the old lowest common denominator was the tiny sRGB color space, many modern displays are able to reproduce a much larger color gamut, resulting in more vivid, vibrant colors. Once primarily used in prepress workflows to reproduce the full range of printable colors, wide gamut displays can now be found in both pro and consumer monitors, laptops, and even tablets and smartphones. The DCI-P3 color space, originally designed as a standard for digital movie projection for the film industry, made its debut in a consumer computer in September 2015 in Apple’s iMac. A year later, both Apple and Samsung released their first flagship phones with P3 wide gamut display.

Now, support for these wider color spaces is finally coming to the Web. In case you want to dig deeper, Lea Verou has written a brilliant article on the upcoming changes. The CSS 4 Color specification includes, among other things, lab() and lch(). LCH is a color space designed to cover the entire spectrum of human vision, so it is even larger than P3. Safari already supports it, Chrome is going to support it soon, and Firefox is considering implementation. With the lch() color function and support for the P3 color space in our devices, we will therefore soon have access to about 50% more colors than with sRGB. Another advantage is that LCH, which stands for “Lightness, Chroma, Hue”, is perceptually uniform. So when you define two colors that share the same lightness, the two colors will indeed be perceived as being equally bright by the human eye, which can also be useful if you want to create an accessible color palette.

Here is how you write a color with the new lch() function, in the new commaless syntax:

/* CSS / Sass */
lch(50% 73 327)

The first value stands for the lightness of the color and is written as a percentage ranging from 0 to 100. The second value, chroma, is a number that describes how vibrant and saturated the color is. It starts at 0 but is theoretically unbound, so how high it can be set depends on the color gamut of the monitor. Usually, it doesn’t exceed 230, though. The third value ranging from 0 to 360.

If you want to also use an optional alpha channel, you can do so with the new notation that uses a slash:

/* CSS / Sass */
lch(50% 73 327 / 75%)

Lea Verou also made a neat LCH Color Picker. Have a look at it and play around with the values a bit. For best results, use Safari on a machine with a wide gamut display.

Screenshot of LCH Color Picker

CSS 4 Color also adds a new color() function, which can be used to specify a color in a certain color space, like P3, for example:

/* CSS / Sass */
color(display-p3 1 0 0.331)

Here, the color function is used to first define the color space and then set the color with three values ranging from 0 to 1 which represent the red, green, and blue channels. Ollie Williams nicely explains the new color() function as well as LCH in his post over at CSS-Tricks.

As you can see, a lot is going on at the moment in terms of how we can write colors in CSS. And while a few of those features might not yet be ready for prime time in all browsers, we can already make use of them in supporting browsers using progressive enhancement. We can, for example, use the new color-gamut media query to write specific CSS only for devices that support a certain color space.

/* CSS / Sass */
@media (color-gamut: p3) {
  .main {
    background-color: color(display-p3 1 0 0.331);
  }
}

Another option would be to check for support using @supports:

/* CSS / Sass */
/* sRGB color. */
:root {
    --bright-green: rgb(0, 255, 0);
}

/* Display-P3 color, when supported. */
@supports (color: color(display-p3 1 1 1)) {
    :root {
        --bright-green: color(display-p3 0 1 0);
    }
}

header {
    color: var(--bright-green);
}

So while Safari is currently the only browser with full support for lch() and color() there really is no need to wait until the other vendors have added support. I for one will look into how I can update the colors of my site a bit over the next days to make my site ready for this next, exciting era of color on the World Wide (Gamut) Web.

-

This is the seventh post of my 100 days of writing series. You can find a list of all posts here.

~

2 Webmentions

1 Like

ⓘ Webmentions are a way to notify other websites when you link to them, and to receive notifications when others link to you. Learn more about Webmentions.