This entry is almost entirely interactive, and needs JavaScript. There are twenty-three demos and very few paragraphs. Nearly all of the demos share one colour: change it in any of them and the rest follow. Nothing leaves your browser. This is a long-in-waiting follow-up to my “yaflaColor” tool1 that was widely used in the 2000s and 2010s. It was a popular tool for interactively finding colour themes and for converting between the colour spaces.
Spoiler: a colour is three numbers. Every system below is a different choice of which three, and the choice decides what’s easy: building a screen, picking a paint, printing a page, or making six colours look like they belong together.
Light Adds Up
Your eye has three kinds of colour sensor, so three lights are enough to fool it. Start in the dark and add. Drag the lights over one another.
Red and green light make yellow. There is no yellow light there at all, and your eye can’t tell the difference2. All three make white.
RGB
So a screen is told how hard to drive each of the three lamps. One byte each, 0 to 255, and the six-digit hex code is those same three bytes written in base 16.
Each slider’s track shows what moving it would do, given the other two. Notice how hard it is to get anywhere on purpose. “The same, but lighter” means moving all three by different amounts. RGB is how the machine thinks, and nobody else does.
How Many Colours Is Enough
Eight bits a channel, over the three channels, is 16,777,216 colours. Take bits away and see when you notice a difference.
The Numbers Aren’t the Light
One catch that bites everyone eventually: the stored number is not proportional to the light. 128 is not half as bright as 255. It’s about a fifth. Drag along the chart.
The bend is deliberate. Your eye notices a small change in a dark tone far more readily than the same change in a bright one, so levels spent evenly on light are wasted at the top and scarce at the bottom. The curve spends them evenly on what you can tell apart instead. Pull the bits down and the second strip falls apart in the shadows while the first holds3.
Switch the chart to stops, where each step along is double the light, and the same idea keeps going:
- Camera log. A sensor records maybe fourteen stops and a screen’s white is only two and a half above mid grey. A log curve gives every stop about the same share of the numbers, so the highlights survive to be dealt with later. Shown raw it looks flat and grey, which is what the last strip is.
- PQ and HLG, the two HDR curves. Same purpose, for screens that really can go that bright. PQ was built directly from measurements of the smallest step in brightness a person can see4.
The practical consequence for anyone writing code: if you average two colours’ numbers, you don’t get the average of their light.
Red to green is the famous one: the naive blend goes through a muddy brown that is darker than either end.
A Fourth Lamp
If three lamps are good, are four better? Around 2010 Sharp sold televisions with a yellow sub-pixel beside the red, green and blue, and plenty of OLED televisions today have a white one.
Here is every colour a person can see, laid flat. The curved edge is the pure wavelengths. Mixing two lights gives you the colours on the straight line between them, so three lamps can reach exactly the triangle between them and nothing outside it. A fourth lamp makes the triangle a quadrilateral. It does not add a dimension: your eye still has three kinds of sensor.
Try yellow, then cyan. Yellow buys about 3% more colours on an sRGB screen, because the red-to-green edge of the triangle already runs close to the curve there. Cyan buys about 31%. The room was always on the other side.
So why yellow? Brightness. A yellow sub-pixel lets through far more light than a red and a green one side by side, which is the same reason for the white one in an OLED panel. And there is a catch that no fourth lamp gets around: the picture still arrives as three numbers. Nobody ever broadcast a yellow channel, so the set has to invent the fourth value from the other three, and it cannot put back colours the signal never carried5.
Brighter Than White
Everything so far has had a ceiling. 255 is white, and white is as bright as the screen is prepared to go. High dynamic range, HDR, takes the ceiling off. It is not a brighter picture: a white page stays about where it always was. The new room is above it, for the things that really are brighter than a page, like the sun, a flame, or a glint off chrome. Brightness is measured in nits. Drag along the chart.
So is HDR just more bits? It needs more, but that isn’t what it is. Range is how far apart the two ends are, and bits are how fine the steps between them are. Stretch eight bits over a range this long and the steps show, so HDR video uses ten or twelve. It also swaps the old curve for PQ, which spends them better: far more in the shadows, where the old curve all but runs out, and fewer at the top.
Then the catch. A PQ number means a particular brightness, not a share of whatever the screen has, and almost no screen has all of it. A film can ask for 1,000 nits from a laptop that stops at 400, and the laptop has to decide what to do about it. This is tone mapping, and it’s why the same film looks different on every HDR television.
For a colour theme, none of this changes anything, and that’s on purpose. An interface stays in the ordinary range, because a button brighter than the page’s white is a button nobody wants to look at6.
The Same Colours, Rearranged
RGB is a cube: three axes at right angles. Every other system on this page that describes a screen is that same cube, bent into a more convenient shape. Each dot keeps its colour throughout. Only its address changes.
Stand the cube on its black corner and look down from white. The six vivid corners make a hexagon, and the angle round it is what we call hue. That one move is the whole idea behind HSV and HSL.
HSV and HSL
Both keep hue as an angle, and both add “how colourful” and “how bright”. They differ only in where white goes.
- HSV (or HSB): value is the brightest of the three channels. Full value and full saturation is the pure colour. White is full value with no saturation. This is the square in nearly every colour picker.
- HSL: lightness runs from black through the pure colour at 50% to white at 100%. This is the one CSS speaks.
The same colour has the same hue in both, and usually a different saturation. “50% saturated” means nothing until you say which system.
The Lie in “Lightness”
Both are just arithmetic on RGB, and they know nothing about eyes. HSL insists that pure yellow and pure blue have the same lightness: 50%. Take the colour out and see.
OKLCH
The fix is a space built from measurements of what people actually see. CIE Lab was the 1976 attempt, and OKLab (2020) is the one that finally got into CSS7. Its polar form, OKLCH, has the same three ideas as HSL: lightness, chroma (colourfulness), hue. The difference is that the lightness is honest: change the hue and it keeps looking as light as it did.
The price is that the space is not a tidy box. You can ask for colours no screen can show, and the tracks above flatten out where sRGB runs out of room. This is the space the theme generator at the end works in.
Ink Subtracts
Paper starts white and ink takes light away. Cyan ink absorbs red, magenta absorbs green, yellow absorbs blue. They are the exact opposites of the three lights, which is not a coincidence.
CMYK
In theory cyan, magenta and yellow together make black. Real inks make a wet, expensive brown. So printers add a fourth, black, the K8, and hand it whatever grey the other three have in common.
Pull the last slider down: the colour doesn’t change, but the ink bill does. Many different CMYK recipes give the same colour, which is one reason CMYK numbers mean nothing without knowing the press, ink and paper they were made for9.
Dots
A press can’t print 40% cyan. It can print cyan or not. So it prints dots of different sizes and lets your eye average them, each ink’s grid turned to its own angle so the four don’t beat against each other.
One Colour, Ten Spellings
Type into any of these.
Colours That Go Together
Colour theory is mostly geometry on a wheel: pick a hue, then pick others by their angle from it.
Which wheel, though? Opposite red on a screen’s wheel is cyan. Opposite red on the painter’s wheel you learned at school is green. Neither is wrong. They’re spaced differently, and the traditional harmonies were worked out on the painter’s.
Drag any dot. The usual advice for using a scheme is the 60-30-10 rule: one colour gets most of the room, a second supports it, and the loudest gets a tenth. The little poster does that.
Tints, Shades and Tones
One hue goes a long way. Add white for a tint, black for a shade, grey for a tone.
Company Matters
No colour is ever seen alone, and the neighbours change it.
Colours for Everyone
Two checks before any palette ships.
Contrast. Text needs enough difference in luminance from its background. Hue doesn’t count. The usual bar is 4.5 to 1 for body text10.
Colour vision. About one man in twelve, and one woman in two hundred, has some form of colour vision deficiency, most often trouble telling red from green. If two colours in your palette differ only by hue, some people will see one colour.
A Theme From One Colour
Everything above, put to work. Pick one colour and a harmony, and get:
- Scales: eleven steps of each hue, built in OKLCH so that step 600 of one is as light as step 600 of any other.
- Roles: which step is the page, the card, the text, the button, in light and in dark, chosen so the contrast holds.
- Something to paste: CSS variables, Tailwind, Sass or JSON.
A few things it’s doing that are worth stealing even if you never use it:
- Your colour is kept exactly, at whichever step it’s nearest. The rest of that scale is built round it.
- Supporting hues are found by turning the OKLCH hue, so a triad looks evenly spaced instead of merely being evenly spaced.
- Buttons get white labels if that passes, dark ones if it doesn’t, and if neither is readable on your colour the button moves a step along the scale until one is. It’s decided by measuring.
- Dark mode is not the light theme inverted. It’s the same scales, read from the other end.
- The neutrals carry a little of the brand hue. Pull that slider to zero and watch the whole thing go slightly dead.
Footnotes
-
I Americanized the spelling of that original tool as it was hosted on a .com domain. Now that this is on a .ca domain, it’s back to Canadian spelling. ↩
-
Two different mixes of light that look identical are called metamers, and every colour screen ever made depends on them. It’s also why a shirt can match your trousers in the shop and not in daylight. ↩
-
The usual story is that the curve exists to cancel out the response of cathode-ray tubes, and that is where the number 2.2 came from. It’s a lucky accident that a tube’s response is close to the inverse of the eye’s, and it’s why the curve outlived the tube. ↩
-
PQ, the “perceptual quantizer”, is absolute: a given number means a given brightness, up to 10,000 nits, whatever the screen. HLG is relative, like sRGB, and was designed so that an ordinary television showing it still looks about right. ↩
-
What does get past it is a better signal. Display P3 and Rec. 2020 are still three numbers, with the three lamps moved further apart, and the picture has to be made for them in the first place. The buttons above the diagram show how much each one reaches. ↩
-
CSS has a property for exactly this,
dynamic-range-limit, which lets a page hold somebody else’s HDR photo down to its own white. ↩ -
Björn Ottosson’s original write-up is short and very readable.
oklch()has worked in every current browser since 2023. ↩ -
K for “key”, the plate the others were lined up against. Also, usefully, not B, which was taken by blue. ↩
-
The CMYK here is the textbook formula, which is honest about the idea and useless for an actual print job. Real conversion goes through an ICC profile that describes one particular press, ink and paper. ↩
-
These are the WCAG 2 thresholds: 4.5 to 1 for body text and 3 to 1 for large text at level AA, 7 and 4.5 at AAA. The formula has known blind spots, especially for light text on dark backgrounds, and its eventual successor works differently. For now it’s the one the rules are written in. ↩
See Also
- Main Blog Updates FYI
New posts published