Web Design for Developers / Module 05

Module 5: How Color Works on a Screen

How a screen turns numbers into color, why HSL lightness misleads, and how to pick colors by lightness, chroma and hue in OKLCH.

This is the snapshot table on the settings page of Stashling, the course’s sample site, at 1280 pixels wide. Module 4 set its text, but its colors are still the ones picked when each rule was written.

Figure 1: the status labels as Module 4 left them. The CSS gives all three colors the same HSL lightness.

A reader would say two things. The Running label is hard to read, and the one Failed label looks heavier than everything around it. But the comment above the three colors in the CSS says they share saturation and lightness “so the three colors match”.

This module explains how a screen turns three numbers into a color, and why HSL’s lightness misled that comment. Then it chooses colors in OKLCH, a way of writing color by the lightness the eye sees. It ends with three status labels that match.

After this module, you can:

  • say what the three numbers of a hex color mean, and why #808080 sends out about a fifth of white’s light
  • predict which of two colors looks lighter, and check it with OKLCH in place of HSL
  • write colors in oklch() that share one lightness and one strength of color, and keep them inside what the screen can show
  • pick an opposite or a neighboring color by rule, and say why two tools give two different answers
  • remove color from a page to check it, in a way that measures lightness, and say why filter: grayscale() doesn’t

To follow along, start from the module-04 folder of the course repository, github.com/vespaiach/web-design-course, and open settings.html in a browser.

Three labels that were meant to match

Here are the rules behind the labels, from settings.css:

/* excerpt */
/* same saturation and lightness so the three colors match */
.status {
  color: #fff;
  padding: 2px 6px;
  font-size: var(--step--1);
}

.status-ok {
  background: hsl(120, 100%, 35%);
}

.status-running {
  background: hsl(60, 100%, 35%);
}

.status-failed {
  background: hsl(0, 100%, 35%);
}

HSL names its three numbers hue, saturation and lightness. All three labels have 100% and 35%, so only the first number differs.

Pause and predict: rank the three backgrounds from the lightest to the darkest, as your eye sees them. Which one gives the white text the least contrast?

You can measure instead of guessing. Open the settings page and paste this into the DevTools console:

const probe = document.createElement("span");
document.body.append(probe);
for (const name of ["ok", "running", "failed"]) {
  const label = document.querySelector(`.status-${name}`);
  const bg = getComputedStyle(label).backgroundColor;
  probe.style.color = `oklch(from ${bg} l c h)`;
  console.log(name, bg, getComputedStyle(probe).color);
}
probe.remove();

The code asks the browser to rewrite each label’s background in OKLCH, which the sections below explain. For now, read only the first number after oklch(.

Answer

In one run in Chrome 157 on macOS, it printed this:

ok rgb(0, 179, 0) oklch(0.664343 0.226033 142.489)
running rgb(179, 179, 0) oklch(0.742206 0.161783 109.756)
failed rgb(179, 0, 0) oklch(0.481496 0.197596 29.2346)

The first number in OKLCH is the lightness, from 0 for black to 1 for white. The yellow is the lightest at 0.74, then the green at 0.66, and the red is the darkest at 0.48. Your eye ranks them the same way in Figure 1.

White text on the yellow has a contrast ratio of 2.24:1, and on the green 2.82:1. On the red it’s 7.20:1. WCAG 2.2 asks for at least 4.5:1 for text this small; Module 6 teaches the formula and the rule. These ratios come from the course’s color script, color-calc/m5/m5.mjs, section A of its output.

So “35%” didn’t mean the same lightness three times. The code uses relative color syntax (oklch(from …)), which is Baseline newly available since 2024-09-16: Chrome 125, Firefox 128 and Safari 18. In an older browser, the last column prints the page’s text color instead.

The next sections explain why the three numbers misled, starting from what a color’s numbers mean.

Hex numbers are codes, not amounts of light

#3ea6ff is three pairs of hex digits, for red, green and blue. Each pair runs from 00 to ff, which is 0 to 255. That range exists because graphics systems long stored each number in one byte (CSS Color 4, §5).

A color space is a fixed rule that says which color each set of numbers means: which red, green and blue the screen mixes, and which white they make together. Hex, rgb(), hsl() and named colors in CSS all use one color space, sRGB. CSS makes it the default and defines its three primaries and its white (CSS Color 4, §10.2).

The numbers don’t count light. Gamma encoding stores each number on a curve instead of in proportion to the light it stands for. CSS Color 4 gives the curve for decoding a number back to light, and the code below uses it.

Pause and predict: #808080 is halfway between black and white in hex. What share of white’s light does it send out?

const toLight = (n) => {
  const c = n / 255;
  return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
};
const luminance = (r, g, b) =>
  0.2126 * toLight(r) + 0.7152 * toLight(g) + 0.0722 * toLight(b);
console.log(toLight(128), toLight(188));
console.log(luminance(255, 255, 0), luminance(0, 0, 255));

It prints this, in any browser console or in Node.js:

0.21586050011389926 0.5028864580325687
0.9278 0.0722

So #808080 (code 128) sends out 21.6% of white’s light, not 50%. The gray with half of white’s light is code 188, #bcbcbc. The usual reason for the curve is that the eye tells dark tones apart more easily than light ones, so the encoding spends more of its 256 codes on them. The standard that defines sRGB isn’t free to read, so we haven’t checked that reason in it.

Luminance is the amount of light a color sends out, with each primary weighted by how strongly the eye responds to it. The second function computes it the way WCAG 2.2 defines it for sRGB.

Green carries 0.7152 of the weight and blue only 0.0722. So pure yellow (#ffff00) has a luminance of 0.9278, and pure blue only 0.0722. The contrast ratio in the answer above compares two luminances.

Lightness is how light a color looks compared with white. It’s a perception, so a model can only predict it, and it doesn’t follow light in a straight line. Figure 2 shows eleven grays, built three ways.

Figure 2: equal steps of the hex number (top), of light (middle) and of OKLCH lightness (bottom). The middle row spends one step on all the dark tones.

The middle row shows why the encoding exists. Equal steps of light leave the dark grays with a single step.

The bottom row uses the lightness that the section on OKLCH explains. In it, the middle gray, at lightness 0.5, is #636363, and #808080 sits higher, at 0.600. The numbers come from section D of the script’s output.

This matters every time a browser mixes two colors. Suppose you write color-mix(in srgb, white, black). The browser averages the codes and gives #808080. CSS Color 5 notes that a mix in sRGB comes out a bit too light, which matches the 0.600.

Rule: Treat hex numbers as codes. To compare amounts of light, decode them first. To compare how light two colors look, use a lightness model.

Why HSL lightness is not what the eye sees

HSL rearranges the same sRGB codes. Its lightness is the average of the largest and the smallest of the three codes, in the sample code of CSS Color 4 (§7). It never decodes them, and it gives red, green and blue the same weight.

Hue is the family a color belongs to, such as red, yellow, green or blue, written as an angle around a circle of colors.

CSS Color 4 makes this point with two colors. hsl(60deg 100% 50%) is yellow and hsl(240deg 100% 50%) is blue, and both have an HSL lightness of 50%. But the specification says that the yellow clearly looks much lighter than the blue.

The table shows six colors with the same HSL lightness. The numbers come from color-calc/calc.mjs, section 1:

Color Hex OKLCH lightness Luminance White text on it
hsl(0 100% 50%) #ff0000 0.628 0.2126 4.00:1
hsl(60 100% 50%) #ffff00 0.968 0.9278 1.07:1
hsl(120 100% 50%) #00ff00 0.866 0.7152 1.37:1
hsl(180 100% 50%) #00ffff 0.905 0.7874 1.25:1
hsl(240 100% 50%) #0000ff 0.452 0.0722 8.59:1
hsl(300 100% 50%) #ff00ff 0.702 0.2848 3.14:1

One HSL lightness gives OKLCH lightness from 0.452 to 0.968. White text on these colors ranges from 1.07:1 to 8.59:1. Figure 3 puts the gray of each color’s lightness under it, and then does the same for six colors at one OKLCH lightness.

Figure 3: six hues at one HSL lightness (top) and at one OKLCH lightness (bottom). Only the bottom row’s grays match.

HSL’s hue is uneven too. CSS Color 4 compares two steps of 30° in HSL hue, and finds them very different. Between 220° and 250°, the hue the eye sees moves about 6° in OKLCH, and between 50° and 80° about 36°. So HSL bunches some colors together on its circle and spreads others apart.

HSL has a real advantage. You can guess a color in it and then adjust it, which is harder with three RGB numbers. It’s been Baseline widely available since 2022-07-15. But its cost appears when you build a set of colors by changing one number, because the lightness of the set is then out of your control.

Rule: Never make colors match by giving them the same HSL lightness. Compare their lightness in OKLCH.

Lightness, chroma and hue in OKLCH

OKLCH writes a color as three numbers, lightness (L), chroma (C) and hue (H). It’s built on Oklab, a color space that Björn Ottosson published in 2020 to predict how people see color (A perceptual color space for image processing). Chroma is how far a color is from the gray of the same lightness, and 0 is gray.

How Oklab turns light into lightness

Oklab was fitted by numerical optimization to a large data set of colors that look alike (CSS Color 4, §9.2). Converting an sRGB color takes four steps:

  1. Decode each sRGB number to light, as toLight does above.
  2. Mix the three lights with a matrix into three responses, roughly like the three kinds of cone in the eye.
  3. Take the cube root of each response.
  4. Mix again with a second matrix into L, a and b. The a axis runs from green to red, the b axis from blue to yellow.

C and H are a and b as a distance and an angle: C = √(a² + b²), H = atan2(b, a). This is the function from color-calc/calc.mjs, which the script checks against the colorjs.io library before it prints anything:

// excerpt from color-calc/calc.mjs; hex2rgb turns "#3ea6ff" into [62, 166, 255]
const oklch = h => {
  const [r, g, b] = hex2rgb(h).map(v => lin(v / 255));
  const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
  const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
  const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
  const L = 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s;
  const A = 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s;
  const B = 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s;
  let H = (Math.atan2(B, A) * 180) / Math.PI; if (H < 0) H += 360;
  return [L, Math.hypot(A, B), H];
};

Notice the cube root. For a gray, a and b are 0 and L is the cube root of the luminance: #777777 has a luminance of 0.1845 and an L of 0.569. The cube root spreads the dark tones apart, as the eye does. That’s why the bottom row of Figure 2 looks evenly spaced.

Ottosson compared it with older models. He found that CIELAB predicts hue badly, blue hues most of all, and that the more complete CAM16 model behaves badly in numerical work. HSV is on his list only because it’s widely used.

The three numbers in CSS

You write oklch(0.75 0.14 145). The rules, from CSS Color 4, §9.4:

  • L runs from 0 to 1, or 0% to 100%. At 0 or 1 the screen shows black or white, whatever C and H say.
  • C starts at 0 and has no fixed top. In practice it stays under 0.5, and 100% means 0.4.
  • H is an angle. 0° points to a purplish red, 90° to mustard yellow, 180° to a greenish cyan and 270° to sky blue.

The hue numbers don’t match HSL’s. sRGB red is hue 29.2 in OKLCH, yellow 109.8, green 142.5 and blue 264.1. So you can’t copy a hue from hsl() into oklch(); the bottom row of Figure 3 shows oklch(0.7 0.12 0) as pink.

oklch() and oklab() are Baseline widely available since 2025-11-09: Chrome 111, Firefox 113 and Safari 15.4. A browser older than those drops the declaration.

Chroma has a ceiling that moves

Chroma has no fixed maximum, because the screen can’t show every combination. The most chroma that sRGB can show depends on both the lightness and the hue. Figure 4 cuts OKLCH at the three hues that the lab gives the status labels.

Figure 4: what sRGB can show at three hues. At lightness 0.75, all three reach past chroma 0.14.

The table reads the same edges as numbers. For each lightness, it gives the largest chroma inside sRGB at each hue, and the contrast of white and black text on a gray of that lightness. It comes from section B of the script’s output:

Lightness Hue 30 (red) Hue 85 (yellow) Hue 145 (green) Smallest White text Black text
0.50 0.201 0.102 0.157 0.102 6.01:1 3.50:1
0.55 0.221 0.113 0.173 0.113 4.88:1 4.30:1
0.60 0.241 0.123 0.189 0.123 3.95:1 5.32:1
0.65 0.236 0.133 0.204 0.133 3.23:1 6.49:1
0.70 0.192 0.143 0.220 0.143 2.68:1 7.84:1
0.75 0.151 0.154 0.236 0.151 2.22:1 9.47:1
0.80 0.115 0.164 0.252 0.115 1.86:1 11.30:1
0.85 0.082 0.166 0.267 0.082 1.57:1 13.34:1

Red holds the most chroma near lightness 0.6 and loses it quickly above 0.75. But yellow holds little chroma at low lightness and the most near 0.85. So a yellow at lightness 0.5 can have a chroma of only 0.102, so it looks olive or brown, not yellow. The three hues share the most chroma at lightness 0.75, where the smallest ceiling is 0.151.

A color past the ceiling is a valid color that the screen can’t show, so the browser has to change it. The section on wide screens below shows how.

Mixing and gradients follow the color space

A gradient and color-mix() blend two colors in a color space, and the result depends on which one. Colors written the old way blend in gamma-encoded sRGB, for compatibility with old pages (CSS Color 4, §13.3). But you can name a different space.

Pause and predict: blue and yellow sit on opposite sides of the color wheel. What color is halfway between them in sRGB?

Figure 5 blends blue into yellow in three spaces.

Figure 5: blue to yellow, blended in srgb (top), oklab (middle) and oklch (bottom), in Chrome 157.

The midpoints, from section I of the script’s output and from the pixels of the screenshot:

  • In sRGB, the midpoint is the gray #808080, at lightness 0.598. The codes average to the same number on all three channels.
  • In Oklab, it’s #6cabc7, a light blue-gray with lightness 0.710. Lightness moves evenly, so there’s no dark dip.
  • In OKLCH, it’s oklch(0.710 0.262 186.9). The hue turns from blue to yellow through cyan and green, and the chroma stays high. That midpoint is outside sRGB. Chrome drew #00cfbd, and the sharp band in the bar is where it cut off chroma it couldn’t show.

CSS Color 4 warns that a blend in OKLCH can leave the screen’s range even when both ends are inside it. That’s why Oklab is the safer default for mixing. OKLCH keeps colors vivid, but it can pass through hues you didn’t pick.

color-mix() is Baseline widely available since 2025-11-09. The in oklab part of a gradient is newly available since 2024-06-11: Chrome 111, Firefox 127 and Safari 16.2. A browser without it drops the declaration, so write a plain gradient on the line before as a fallback.

What Oklab does not do

Oklab predicts lightness for one viewing condition and has no idea of a reference white.

Ottosson wrote in 2021 that a color picker with a fixed white needs a corrected lightness, and he added one for his pickers (Two new color spaces for color picking). CSS Color 4 now lists a color difference that uses it. CSS treats a difference of 0.02 in Oklab as one just-noticeable step. These are small corrections, but they show that L is a prediction for typical viewers, not a measurement of every eye.

Rule: Choose the lightness first, then a chroma that fits every hue at that lightness, then the hues.

Screens that show more than sRGB

Modern screens can show colors that sRGB can’t describe. CSS Color 4 says modern displays show all, or nearly all, of a larger color space called display-p3 (§10.4). But it gives no data on how many screens that is.

A gamut is the range of colors that a color space or a screen can produce. Figure 6 draws the gamuts of sRGB, display-p3 and the larger Rec. 2020 as triangles. Each corner is the color of one primary on the CIE 1931 chromaticity chart, a map of color without lightness.

Figure 6: the sRGB, display-p3 and Rec. 2020 gamuts on the chromaticity chart. P3 reaches further toward green and red, and shares sRGB’s blue.

The three spaces use the same white, and display-p3 uses the same gamma curve as sRGB. So only the primaries differ.

On this chart, the P3 triangle has 1.357 times the area of the sRGB one. On the newer CIE 1976 chart, it has 1.256 times (section G of the script’s output). A guide on Chrome’s developer site says P3 has “50% more colors” (High definition CSS color guide). But neither area counts colors, since both ignore lightness, and neither gives 50%.

In OKLCH terms, P3 adds chroma. sRGB’s red is oklch(0.628 0.258 29.2) and P3’s red is oklch(0.649 0.299 29.0). sRGB’s green has chroma 0.295 and P3’s green 0.369. P3’s yellow, written color(display-p3 1 1 0), would need a blue of -0.3463 in sRGB, which no screen can send. The dashed lines in Figure 4 are the edges of P3.

You write a P3 color with color(display-p3 r g b), or with an oklch() whose chroma is past the sRGB edge. color() is Baseline widely available since 2025-11-09. The media query @media (color-gamut: p3) asks whether the screen covers P3, and it’s widely available since 2025-08-14:

.badge {
  background: oklch(0.7 0.19 145);
}

@media (color-gamut: p3) {
  .badge {
    background: oklch(0.7 0.25 145);
  }
}

At lightness 0.7 and hue 145, sRGB’s ceiling is chroma 0.220. So the first color fits sRGB, and the second fits only P3 (section J of the script’s output).

What the browser does with a color it cannot show

Gamut mapping is how a browser changes a color the screen can’t show into one it can. CSS Color 4 (§14.2) requires it for display. It says how: lower the chroma in OKLCH and keep the lightness and the hue. The specification allows three algorithms that do this.

The simpler method is clipping, which cuts each sRGB number to the range 0 to 1. The specification calls clipping the simplest and least acceptable method, because it changes the hue. Figure 7 shows what Chrome does with a color outside both sRGB and P3.

Figure 7: oklch(0.7 0.3 150) as Chrome 157 draws it on an sRGB screen (left), and the gamut-mapped color that CSS Color 4 asks for (right).

In one test in headless Chrome 157, the left square’s pixels were #00cb00, the clipped color. That moved the hue from 150 to 142.5 and the lightness from 0.70 to 0.73. But gamut mapping gives #00c248, oklch(0.709 0.210 147.1), which keeps the lightness and moves the hue by about 3°. The gradient in Figure 5 was clipped in the same way.

Other browsers may differ. The web-features data (3.46.0, read on 2026-11-18) lists no browser as supporting gamut mapping. Firefox’s bug tracker marks it as fixed for Firefox 153, but the release notes don’t mention it, and Firefox and Safari weren’t tested here.

So keep any color that must look the same everywhere inside sRGB, such as a status color or a brand color. Put extra P3 chroma behind @media (color-gamut: p3). WCAG 2.2 defines luminance for sRGB, so check contrast on the sRGB color.

In Chrome’s DevTools, the color picker draws the edge of sRGB on its color area, and the Rendering tab can emulate a screen’s color-gamut.

The screenshots in this module are sRGB images, so none of them can show a P3 color as P3.

Rule: Keep colors that must match inside sRGB, and add P3 chroma only behind @media (color-gamut: p3).

Color schemes from the wheel are conventions

Design books and tools offer rules for choosing colors that go together. A harmony scheme is a rule that picks hues by their position on a color wheel, a circle of hues. Three schemes cover most uses:

  • Monochromatic: one hue in several lightnesses. Module 6 builds one.
  • Analogous: hues next to each other, about 30° apart.
  • Complementary: two hues opposite each other, 180° apart, usually with one as a small accent.

Others exist: triadic (three hues 120° apart), split-complementary and tetradic.

The schemes are geometry, and the answer depends on the wheel. Painters use a red-yellow-blue wheel, and tools use the HSL wheel or the OKLCH one. Figure 8 shows the complement of Stashling’s brand blue on two of them.

Figure 8: the brand blue (left) and its complement on the HSL wheel (middle) and on the OKLCH wheel (right). The two complements differ by about 10° of hue.

On the HSL wheel, the complement #ff973e is lighter than the blue, at lightness 0.771 against 0.707. On the OKLCH wheel, the complement at the same lightness and chroma is outside sRGB. Gamut mapping gives #e08a00, which keeps the lightness of 0.707 (color-calc/calc.mjs, section 9).

Schloss and Palmer (2011) found that earlier studies of color harmony disagreed with each other. In their own data, people rated pairs as more pleasing and more harmonious as the hues got more similar (Attention, Perception & Psychophysics). Pairs with strongly contrasting hues were rated neither.

Ou and Luo (2006) fitted a model of harmony to ratings of 1,431 color pairs (Color Research & Application). We read only the abstracts, so we can’t say which factors their model weights most.

So treat a scheme as a way to suggest hues, not as a finding. Analogous hues are the safer choice for colors that sit together. A complement suits one small accent. The “60-30-10” proportion rule has no primary source that we could find.

The status labels don’t need any of these schemes, because green, yellow and red for done, in progress and failed are a common convention, chosen by meaning.

Rule: Use a scheme to suggest hues, then set lightness and chroma yourself. The scheme says nothing about either.

Value carries contrast, so test without hue

Value is how light or dark a color is, apart from its hue. It’s the design word for what lightness and luminance measure.

WCAG 2.2 computes contrast from luminance alone, and its Understanding document for 1.4.3 explains why. Many visual impairments reduce contrast sensitivity whatever the hue. For readers with a color vision deficiency, hue has little or no effect on how well they read (Understanding 1.4.3).

A separate rule, 1.4.1 Use of Color, forbids color as the only way to convey information (WCAG 2.2). The status labels pass that rule, because each one carries a word.

The grayscale test is a check you run by looking at a design with its hue removed. If the differences you meant still show, they rest on value. If two things you meant to differ look the same, they differ only in hue. It’s a common design practice, not a standard.

A common way to remove hue is one line of CSS, filter: grayscale(1). Suppose your page has a red error color, #d32f2f, and a green success color, #388e3c.

Pause and predict: with filter: grayscale(1) applied, do the two colors turn into two clearly different grays, or into the same gray?

Figure 9: a red and a green (top), after filter: grayscale(1) (middle) and after removing chroma in OKLCH (bottom). The filter invents a difference in value that isn’t there.

The filter turns them into #525252 and #767676, so the pair seems to pass the test. But their OKLCH grays are #777777 and #797979, almost the same. The contrast ratio between the two colors is only 1.21:1 (calc.mjs, section 10). So they differ in hue alone.

The reason is in the Filter Effects specification. Filter functions must work in sRGB, so grayscale() weights the gamma-encoded codes, not the light (Filter Effects 1). Chrome 157’s pixels match that formula for every color tested. The table compares three ways to remove hue, from color-calc/gray-output.txt:

Color filter: grayscale(1) Gray of the same luminance oklch(from … l 0 h)
#0000ff #121212 #4c4c4c #565656
#ff0000 #363636 #7f7f7f #888888
#d32f2f #525252 #707070 #777777
#388e3c #767676 #7d7d7d #797979
#3ea6ff #969696 #a1a1a1 #a0a0a0

The filter makes reds and blues much too dark. The other two columns stay close, because both decode the light first. The filter itself works everywhere, Baseline widely available since 2019-03-07. It’s fine as an effect and wrong as a measurement.

Two ways measure value:

  • DevTools: in Chrome, open the Rendering tab and set “Emulate vision deficiencies” to “Achromatopsia”. In one test in headless Chrome 157, through the same DevTools setting, its grays equaled the luminance grays of the table for all 13 colors tried.
  • CSS: oklch(from <color> l 0 h) keeps the lightness and sets chroma to 0. It needs relative color syntax, which is newly available. Without it, the declaration is dropped and the previous one applies.

Equal value doesn’t mean equal attention. A label with high chroma can draw the eye more than its gray suggests. That’s an observation; we found no source that measures it.

Rule: Run the grayscale test with DevTools’ Achromatopsia or oklch(from … l 0 h), never with filter: grayscale().

Choices and costs

Decision Choice Cost or limit Choose something else when
Notation Hex and rgb() Codes on a curve; nothing in them tells you lightness You build related colors: use OKLCH
Notation hsl() Lightness and hue steps do not match what the eye sees You tweak one color by eye and check it after
Notation oklch() The chroma ceiling moves with hue and lightness; hue numbers differ from HSL’s You must match a tool that speaks CIELAB: use lch()
Notation lch() (CIE LCH) CSS Color 4 shows blues turning purple as chroma changes You need even hue: use oklch()
Wide gamut display-p3 colors No sRGB meaning; browsers clip or map them differently The color must match everywhere: stay in sRGB
Mixing in oklab Mixes can look less vivid than in OKLCH You want vivid blends and can check the gamut: in oklch
Status labels Lightness 0.75, chroma 0.14, black text Soft colors; Failed draws no more attention than Done One status must stand out: give it its own lightness on purpose
Hue choice A harmony scheme A convention; the result depends on the wheel Colors carry meaning, such as status: choose by meaning
Grayscale test DevTools Achromatopsia Chrome-only, and only on screen You want it in code: oklch(from … l 0 h)

Material Design’s HCT is a fourth option outside CSS. It keeps CIELAB’s lightness as “tone” and takes hue and chroma from the CAM16 model (Material 3). Okhsl and Okhsv, from Ottosson’s 2021 post, give HSL-shaped pickers built on Oklab, for sRGB only. Neither is a CSS color function.

What changed recently in CSS and standards

All Baseline statuses are from the web-features data (version 3.46.0), read on 2026-11-18.

  • oklab(), oklch(), lab(), lch(), color() and color-mix() became Baseline widely available on 2025-11-09.
  • The color-gamut media query became widely available on 2025-08-14.
  • Relative color syntax (oklch(from …)) became newly available on 2024-09-16, and interpolation spaces in gradients on 2024-06-11.
  • CSS Color 4 is a Candidate Recommendation Draft, dated 12 November 2026. Its gamut mapping section requires mapping for display and allows three algorithms.
  • Firefox’s bug tracker marks gamut mapping as fixed for Firefox 153 (July 2026). Chrome 157 clips.
  • WCAG 2.2 is a W3C Recommendation, in its 12 December 2024 edition.

Online tools for this step

All three were free and reachable on 2026-11-18. None replaces checking a color in the browsers your readers use.

  • OKLCH Color Picker & Converter. An open-source picker by Evil Martians, with sliders for L, C and H, a 3D view, conversion from hex, RGB and HSL, and views of the P3 and Rec. 2020 gamuts. For a color outside sRGB, it suggests the closest sRGB color by lowering chroma. Limit: its sRGB fallback is its own calculation, which can differ from Chrome 157’s clipping. DevTools overlap: Chrome’s color picker also edits oklch() and draws the sRGB edge.
  • Color.js apps. Small tools from the team behind the colorjs.io library. Among them are a gamut mapping playground, a test of your own browser called “Gamut mapped, or clipped?”, and step-by-step views of gradients and color-mix(). It’s free and open source. Limit: it’s aimed at people testing the specification, and some apps are marked as work in progress. The clip test paints a canvas, not a CSS background, and DevTools can’t show the difference between clipping and mapping.
  • Ottosson’s color picker comparison. HSV, HSL, Okhsv, Okhsl and two more pickers side by side, by the author of Oklab. It shows HSL’s uneven lightness at a glance, for free, with its source on GitHub. Limit: sRGB only, no export, and little text. DevTools have nothing like it.

For the grayscale test, DevTools’ Achromatopsia emulation needs no outside tool.

Check yourself

Critique: the chart that passed its grayscale test

A monitoring dashboard draws a chart with two lines: errors in #e53935 and successes in #43a047. A legend under the chart shows a colored dot next to the word “Errors” and another next to “Successes”.

Before release, the developer applied filter: grayscale(100%) to the page. The two lines turned into a dark gray and a clearly lighter gray, so they shipped it. Then a reader who can’t tell red from green wrote that they can’t tell which line is which.

Hint 1

Which numbers does filter: grayscale() weight: the codes or the light?

Hint 2

Find the OKLCH lightness of both colors. Change the console code from the start of this module to read them, or use DevTools’ Achromatopsia emulation.

Answer

The filter weights the gamma-encoded codes, so it turned the two colors into #5d5d5d and #868686, two clearly different grays. But measured with decoded light, they’re close: OKLCH lightness 0.608 and 0.629, and grays of the same luminance #7b7b7b and #8d8d8d. The contrast ratio between the two lines is 1.28:1 (section F of the script’s output). So the lines differ in hue alone, and the legend’s dots match lines to words by hue alone, which 1.4.1 Use of Color doesn’t allow.

Fix both parts. Give the error line its own value, for example oklch(0.45 0.18 29), which is #a20906, at 2.47:1 against the green. And stop relying on color alone: label each line at its end, or draw one line dashed.

Then run the grayscale test again, with Achromatopsia this time.

Review questions

  1. What share of white’s light does #808080 send out, and which gray sends out half?
  2. hsl(60 100% 50%) and hsl(240 100% 50%) both have HSL lightness 50%. What are their OKLCH lightnesses, and why does HSL miss the difference?
  3. You write oklch(0.75 0.25 30) for a red label. What does Chrome 157 show on an sRGB screen, and how would you keep the hue?
  4. You need a color opposite Stashling’s blue. Why do the HSL wheel and the OKLCH wheel give different answers, and which one keeps the blue’s lightness?
  5. Why is filter: grayscale(1) a poor grayscale test, and what are two better ones?
Answers
  1. 21.6% of white’s light, because the codes are gamma-encoded. Half the light is code 188, #bcbcbc.
  2. 0.968 for the yellow and 0.452 for the blue. HSL lightness averages the largest and smallest codes, without decoding them and without weighting green, red and blue as the eye does.
  3. At lightness 0.75, red’s ceiling in sRGB is chroma 0.151, so 0.25 is outside sRGB. Chrome 157 clips it, which can shift the hue. Lower the chroma to 0.15 or less yourself, or put the higher chroma behind @media (color-gamut: p3).
  4. A harmony scheme is geometry on a wheel, and the two wheels place hues differently. Adding 180° in HSL gives #ff973e, at lightness 0.771. Adding 180° in OKLCH and mapping into sRGB gives #e08a00, which keeps the blue’s lightness of 0.707.
  5. It weights the gamma-encoded codes, so it makes reds and blues far too dark and can invent a difference in value. Use DevTools’ Achromatopsia emulation, whose grays matched luminance in Chrome 157, or oklch(from <color> l 0 h).

The lab: give the status labels one lightness

In about 15 minutes, you give the three status labels one OKLCH lightness and one chroma, and check the result without hue. Start from the module-04 folder and keep settings.html open. Reload after each step. The finished files are in the module-05 folder of the course repository.

Step 1: look at the labels without hue

Why: the labels’ values were set by accident, and you see that best with hue removed (see “Value carries contrast, so test without hue”).

Open DevTools. Open the Rendering tab from the Command Menu (Cmd+Shift+P on macOS, Ctrl+Shift+P elsewhere, then type “Rendering”). Set “Emulate vision deficiencies” to Achromatopsia. Scroll to the Snapshots table.

Figure 10: the labels with Achromatopsia emulated, before the change. Failed is far darker than Done and Running.

What you should see: Figure 10. Failed is the darkest by far, and Running the lightest. Then run the console code from the start of this module, and you get the three lightnesses 0.66, 0.74 and 0.48. Turn the emulation off afterward.

Step 2: choose one lightness and one chroma

Why: lightness first, then a chroma that fits every hue (see “Chroma has a ceiling that moves”).

Nothing to type in this step. Read the table in that section.

  1. The lightness. At 0.75, the three hues share the most chroma, a ceiling of 0.151. A gray of that lightness gives black text 9.47:1 and white text only 2.22:1, so the labels get black text.
  2. The chroma. Take 0.14, a little under the ceiling of 0.151, so all three stay inside sRGB.
  3. The hues. Keep red near sRGB red, at 30, and green near its old hue, at 145. For yellow, the old hue was 109.8, but at this lightness oklch(0.75 0.14 110) is #b4b53d, an olive. Move it toward orange, to 85, which reads as a gold yellow; that choice is by eye.

You can try the three colors live on oklch.com, or in the DevTools color picker, before you type them.

Step 3: add the status colors to the tokens

Why: each label color has a name, and the three numbers show the rule they follow.

In tokens.css, add an empty line after the --color-muted line, then these lines, before the closing }:

  /* Status labels: one OKLCH lightness and chroma, three hues */
  --color-status-ok: oklch(0.75 0.14 145);      /* #71c575 */
  --color-status-running: oklch(0.75 0.14 85);  /* #d6a62e */
  --color-status-failed: oklch(0.75 0.14 30);   /* #fa8978 */

The hex codes in the comments are what the colors become in sRGB, from section C of the script’s output. All three are inside sRGB, so no browser has to clip them.

What you should see: nothing changes yet, because no rule uses the new properties.

Step 4: use them in the labels

Why: the backgrounds come from the tokens, and black text replaces white, as step 2 decided.

In settings.css, replace the comment and the four status rules at the end of the file with these:

/* same OKLCH lightness, so no label looks heavier; black text on all three */
.status {
  color: #000;
  padding: 2px 6px;
  font-size: var(--step--1);
}

.status-ok {
  background: var(--color-status-ok);
}

.status-running {
  background: var(--color-status-running);
}

.status-failed {
  background: var(--color-status-failed);
}

What you should see: Figure 11, beside Figure 1. Only the label colors and their text changed.

Figure 11: the status labels after the lab, in the same crop as Figure 1. One lightness, one chroma, three hues.

Step 5: check the result

Why: a number on paper is a prediction, and the browser is the test.

  1. Run the console code again. It prints this:

text ok oklch(0.75 0.14 145) oklch(0.75 0.14 145) running oklch(0.75 0.14 85) oklch(0.75 0.14 85) failed oklch(0.75 0.14 30) oklch(0.75 0.14 30)

  1. Emulate Achromatopsia again. The three labels are now close grays, as in Figure 12.
  2. Check the black text. Section C of the script’s output gives 9.95:1 on the green, 9.35:1 on the yellow and 8.91:1 on the red, all over the 4.5:1 that small text needs.

Figure 12: the labels with Achromatopsia emulated, after the lab. All three have nearly the same value.

The grays are close, not identical: #b2b2b2, #adadad and #a9a9a9. Achromatopsia shows luminance, and luminance and OKLCH lightness differ a little for colors with chroma. Their OKLCH grays are all #aeaeae. The contrast ratios differ for the same reason.

What you should see: the page in Figure 11. The brand blue buttons and the red “Delete repository” button didn’t change; Module 6 fixes their contrast.

Optional: apply it to a page of your own

Pick a page of your own that has colored labels, badges or chart lines.

  1. List the colors in its CSS. For each one, read its OKLCH lightness with the console code, changing the selector.
  2. Do colors meant to have the same weight share a lightness? Do colors meant to stand out have a clearly different one?
  3. Run Achromatopsia emulation. Does anything you meant to differ disappear? Does the page rely on hue alone anywhere?

Then rewrite the colors in oklch() with one lightness per level of weight, and check each chroma against the ceiling for its hue on oklch.com.

Module 5 cheat sheet

Hex          codes on a curve: #808080 is 21.6% of white's light
Luminance    0.2126 R + 0.7152 G + 0.0722 B, on decoded numbers
HSL          L ignores hue: yellow 0.968 and blue 0.452 are both "50%"
OKLCH        oklch(L C H): L 0-1, C from 0, H angle (not HSL's angles)
Order        lightness first, then the chroma every hue can reach, then hues
Gamut        keep colors that must match in sRGB; P3 behind color-gamut: p3
Mixing       in oklab for even blends; in srgb dips gray and dark
Schemes      conventions; the complement depends on the wheel
Gray test    DevTools Achromatopsia or oklch(from c l 0 h), not filter

Module 6, Building a Palette and a Dark Theme, starts with the brand blue button whose white text fails contrast.

Sources

Color science:

Color harmony research:

Standards and browsers:

The numbers in this module come from three scripts in the course’s color-calc/ folder, with their output saved beside them: calc.mjs, gray.mjs and m5/m5.mjs. They use the colorjs.io library (version 0.7.1) and check their own WCAG and Oklab formulas against it. Run them with Node.js after npm install in that folder.