Hello!
I’m Chris or @svgeesus
Hello!
I’m Chris or @svgeesus
Technical Director at W3C
Strategy lead, Core Web Technologies
W3C liaison to ICC
co-editor, CSS Color 3,4,5
#7D2329
rgb(77.61% 36.34% 2.45%)
hsl(55.257 73.833% 35.465%)
hwb(94.22 22.35% 34.88%)
royalblue
#6AE
rgb(128, 0, 128)
color()
function color(display-p3 0.31 0.56 0.74);
color(display-p3 0.31 0.56 0.74 / 0.6);
Minimum 10 bit precision per component
color(display-p3 0 1 0);
Inside display-p3 gamut, outside sRGB
Will use gamut mapping if not displayable
color(display-p3 -0.34 -0.08 1.387)
color(display-p3 -0.1 1.2 0);
Yes you can do that
color(display-p3 0.31 0.56 0.74);
color(prophoto-rgb 0.393 0.478 0.677);
color(rec2020 0.351 0.508 0.708);
oklch(0.623 0.112 235.8);
/*CIE*/ lch(56.29% 37.11 245.1);
P.S. Handy color space converter
@media (color-gamut: p3) {
// is this a wide-gamut screen?
color: color(display-p3 0.31 0.56 0.74);
}
@supports (background: color(display-p3 1 1 1)) {
// is the syntax supported?
color: color(display-p3 0.31 0.56 0.74);
}
let canvas = document.getElementById("foo");
let context = canvas.getContext("2d", { colorSpace: "display-p3" });
context.fillStyle = `color(display-p3 0.43313 0.50108 0.37950)`;
context.fillRect(10, 10, 50, 50);
context.fillStyle = `color(sRGB 0.41587 0.503670 0.36664)`;
context.fillRect(60, 10, 50, 50);
Two colors can be mixed in any colorspace
color-mix(in oklab, teal 65%, olive);
teal in oklab is color(oklab 0.5431 -0.09 -0.024)
olive in oklab is color(oklab 0.5807 -0.043 0.1191)
mix = color(oklab 0.5563 -0.073 0.0263)
= rgb(27.85% 50.81% 39.12%)
color-mix(in oklab, lime 50%, lch(50% 100 40))
[color1]
in [interpolation_space] is [Color.to(color1, interpolation_space) & ""]
[color2]
in [interpolation_space] is [Color.to(color2, interpolation_space) & ""]
mix =
[Color.to(Color.mix(color1, color2, (100 - percent)/100, space: interpolation_space), interpolation_space) & ""]
[Color.to(Color.mix(color1, color2, (100 - percent)/100, space: interpolation_space), interpolation_space).to('srgb') & ""]
gamma-encoded sRGB is a poor space for mixing
CIE Lab has poor hue linearity for blues
color-interpolation method
linear-gradient(to right, #F01, #081)
linear-gradient(in oklab to right, #F01, #081)
Polar color spaces can also specify the shorter or longer hue direction
linear-gradient(in oklch longer to right, #F01, #081)
font-palette property
@font-palette-values --grey-palette {
font-family: "Nabla";
base-palette: 3;
}
@font-palette-values --pink-palette {
font-family: "Nabla";
base-palette: 1;
}
@keyframes anim {
from { font-palette: --grey-palette; }
to { font-palette: --pink-palette; }
}
.animated-palette {
animation: anim 2s infinite;
}
--mycolor: teal;
background: oklch(from var(--mycolor) l calc(0.8 * c) calc(h -120));
Predefined variables per color space: here l
, c
and h
--mycolor: teal;
color: color(xyz-d65 from var(--mycolor) calc(0.8 * x) y calc(1.2 * z));
color: color(prophoto-rgb from var(--mycolor) calc(0.8 * r) calc(0.7) calc(0.4 * b));
Beware, in RGB spaces, values are gamma-encoded
Colors can be specified out of gamut
or calculations give out of gamut results
Those colors must be modified
(by the browser, not by you)
to look similar but in gamut of display
Change in hue very noticeable
Change in lightness less so
Reduction in chroma is least noticeable
Color space matters (hue uniformity, linearity)
Feature | Chrome 110 | Edge 110 | Firefox 109 | Safari 15.5 |
---|---|---|---|---|
color() |
||||
color(display-p3) |
||||
lab(), lch() |
||||
oklab(), oklch() |
||||
display-p3 canvas |
||||
color-mix() |
||||
*-gradient(in colorspace ) |
||||
Relative Color Syntax |
||||
Consumer WCG, HDR films, series, news, sports (BT.2100 PQ, HLG)
Consumer HDR gaming consoles
Consumer WCG, HDR-ready TVs commonplace
Consumer WCG (P3) laptops, tablets, phones; HDR coming
WCG, HDR still images coming (AVIF)
Brighter displays for brighter environments
Brighter displays for more highlights
srgb-linear
, rec2100-hlg
, rec2100-pq