33
loading...
This website collects cookies to deliver better user experience
00000000 - 00000000 - 00000000
as the code for pure black and 11111111 - 11111111 - 11111111
as the code for pure white – all off, or all on, basically. When we convert from binary to decimal, 1111111
converts to 255
. So, when we’re defining RGB colors, we’re really telling each one of those subpixels in an RGB display what binary value we want it to take...but it’s a lot faster and easier for us to write them in the decimal value shorthand. Kind of cool, right? Like, we abstractly know that it’s all 1s and 0s in the end, but I think it can be a lot of fun to see the curtain pulled back in this way. rgb()
, hsl()
or hex are. There are a few options out there for defining P3 colors, all from the CSS Color Module Level 4. display-p3
but could also be srgb
or rec2020
. Then, the three numbers are kind of an updated version of how we used to define sRGB color: each number still represents red, green, and blue (in that order), but instead of maxing out at 255, it now functions on a scale from 0 to 1, with 1 being equal to 100% (the same way we define opacity). So, if we wanted a color that was 100% pure red, we’d write it like color(display-p3 1 0 0)
. color(display-p3 0.6 0.44 0.89)
how do you make it darker? How do you make it brighter? You’d almost always have to go back to some kind of color selection tool and adjust the color there, then derive a new RBG color value to copy into your code. Kind of a pain. Which brings us to...lab()
syntax is a method of defining colors based on lightness and color channels. In fact, that’s what the L in lab
stands for: Lightness! Lightness, Color Channel A, and Color Channel B. Lightness is defined on a scale from 0-100%, with 0 being completely dark and 100% being the lightest it can go. The color channels work a little bit differently than we might be accustomed to; they define color as a value between two ends of a spectrum, going from -128 to 127 (which, spoiler alert, is a total spectrum of 255 values). Channel A works on a spectrum between red and green, and channel B works on a spectrum between blue and yellow. In both situations, 0 would be the exact middle – grey. Picture an X shape, with green to red being one crossbar and blue to yellow being the other. lab(50% -40 60)
allows us to plot on that graph, but also adds a new value at the very beginning to define lightness on a scale from 1-100%. lch()
syntax is similar, but not quite the same as lab()
– it might even be more easy to use. The L still stands for lightness, and the scale works in exactly the same way: 0-100% to control the lightness of the color. However, the next two values are different; the C stands for chroma, and the H for hue. Chroma is the saturation or intensity of the color, with 0 being grey and 230 (the "max" value) being the highest vividness. Technically, that upper value is limitless, but in practice you'll never (currently) see it go higher than 230. Hue, as you probably guessed, is the color itself. It works on a scale from 0 to 360 (representing the color wheel), with each number representing a hue in the available spectrum. This approach is nice because it’s an incredibly intuitive approach to color. The L and C values correlate really well to the “brightness” and “saturation” controls that we’ve become really accustomed to through things like instagram filters or color picker UI tools. If you want to play around with it a little bit, this LCH Color Picker can really help you visualize how it works. color: lch(66% 132 359 / 65%);
CSS | Safari | Edge | Chrome | FF |
---|---|---|---|---|
color() | Yes, v15+ | No | No | No |
lab() | Yes, v15+ | No | No (In development) | No (In development) |
lch() | Yes, v15+ | No | No (In development) | No (In development) |
color-gamut
media query, you can check the user’s browser AND output device for current color compatibility by passing in srgb
, p3
, or rec2020
and then conditionally rendering your styles based on the status. So if you want to start writing for those future color spectrums, you could set up a little graceful degradation like so:@media (color-gamut: p3) {
body { color: lch(66% 132 359 / 65%) }
}
@media (color-gamut: srgb) {
body { color: rgba(255 110 180 0.6) }
}
@supports
, if you were so inclined.