Sub topic 8
Colour spaces and gamut: what each device can reproduce
This chapter assumes you know what RGB and CMYK channels are and how 8-bit values and hex codes work. It explains why #ff8800 is not one fixed colour until you say which colour space it is in, and why some colours can appear on one device but not another.
A model is not a space
A colour model describes how a colour is built from channels. RGB uses three channels of light. CMYK uses four channels of ink. A model on its own says nothing about which real colours those numbers mean.
A colour space is a colour model plus the extra definitions that tie the numbers to measurable colours. A space fixes three things:
- Primaries. These are the exact colours of the pure red, green and blue (or the inks) that the channels refer to.
- White point. This is the colour that counts as white, such as D65 (roughly midday daylight) or D50 (a warmer reference used in print).
- Transfer function. This is how channel values map to light intensity. This is the gamma topic covered in the next chapter, so treat it as a given for now.
Two spaces can use the RGB model and still disagree. The triple (0, 255, 0) means "the greenest green sRGB can make" in one space and "the greenest green Display P3 can make" in another. These are different colours.
Gamut: the set of colours a space can reach
The gamut of a space or device is the set of colours it can represent or reproduce. A monitor's gamut is limited by the colours of its red, green and blue emitters. A printer's gamut is limited by its inks, the paper, and the printing process.
Gamut is easiest to picture on a chromaticity diagram. This is a flat map of all colours the human eye can see, ignoring brightness. The visible colours fill a horseshoe-shaped region. Three RGB primaries are three points on the map. Any colour the display can make is mixed from those three, so its gamut is the triangle they form.
A colour outside the triangle is out of gamut for that device. The device cannot show it, however you set the channel values. A CMYK process has no neat triangle. Its gamut is an irregular blob, because ink mixing is not linear, and it shifts with paper.
Common colour spaces
| Colour space | Model | Typical use | Gamut compared with sRGB |
|---|---|---|---|
| sRGB | RGB | Web default, most apps, most images | Baseline |
| Display P3 | RGB | Recent phones, laptops and monitors | Roughly 25% larger in area, mainly greener and redder |
| Adobe RGB (1998) | RGB | Photography and some print workflows | Roughly 35% larger, mainly more cyan-green |
| Rec. 2020 | RGB | HDR and wide-gamut video | Much larger, beyond most displays today |
| FOGRA39 | CMYK | Coated paper printing in Europe | Smaller overall, but reaches some cyans that sRGB cannot |
| SWOP | CMYK | Coated web-offset printing in North America | Smaller overall, with a similar pattern |
The area figures are approximate and depend on which chromaticity diagram you measure on.
Two points matter more than the numbers.
- Bigger is not a superset. CMYK gamuts are smaller than sRGB in most regions, but they are not a subset. Saturated cyans and some deep yellows and greens can be printable yet fall outside sRGB. Gamuts overlap, and neither contains the other.
- The numbers do not change.
(255, 0, 0)in Display P3 is a more saturated red than(255, 0, 0)in sRGB. A wider space does not add more channel values. It stretches the same 0 to 255 range over a larger area of colour.
Seeing the difference in code
CSS lets you name the space explicitly. This stylesheet gives wide-gamut screens a more saturated orange and falls back to sRGB elsewhere.
.badge {
/* Fallback for every browser */
background-color: #ff8800;
}
@media (color-gamut: p3) {
.badge {
/* Display P3 values are written as fractions from 0 to 1 */
background-color: color(display-p3 1 0.55 0);
}
}The color-gamut media query asks whether the display can show at least the Display P3 gamut. On an sRGB-only display, the browser ignores the block and uses the hex fallback. On a P3 display, the browser applies the wider colour.
The Python example below checks whether a Display P3 colour fits inside sRGB. It works in linear light (the transfer function is removed) and goes through CIE XYZ, a device-independent space that describes colour by how the eye responds. If any converted channel falls below 0 or above 1, the colour is out of sRGB gamut.
P3_TO_XYZ = [
[0.4865709, 0.2656677, 0.1982173],
[0.2289746, 0.6917385, 0.0792869],
[0.0000000, 0.0451134, 1.0439444],
]
XYZ_TO_SRGB = [
[3.2404542, -1.5371385, -0.4985314],
[-0.9692660, 1.8760108, 0.0415560],
[0.0556434, -0.2040259, 1.0572252],
]
def mat_vec(m, v):
return [sum(m[row][i] * v[i] for i in range(3)) for row in range(3)]
def p3_linear_to_srgb_linear(rgb):
return mat_vec(XYZ_TO_SRGB, mat_vec(P3_TO_XYZ, rgb))
def in_srgb_gamut(rgb, tol=1e-4):
return all(-tol <= c <= 1 + tol for c in rgb)
green = p3_linear_to_srgb_linear([0.0, 1.0, 0.0])
print([round(c, 3) for c in green], in_srgb_gamut(green))
# [-0.225, 1.042, -0.079] False
white = p3_linear_to_srgb_linear([1.0, 1.0, 1.0])
print([round(c, 3) for c in white], in_srgb_gamut(white))
# [1.0, 1.0, 1.0] TruePure Display P3 green converts to a negative red and a negative blue in sRGB. Negative light is impossible, so sRGB cannot show this colour. White converts to (1, 1, 1), because both spaces share the D65 white point.
What happens to out-of-gamut colours
A colour that does not fit must be changed before it can be shown. This change is called gamut mapping. There are two basic strategies.
- Clipping. Each channel that falls outside 0 to 1 is forced to the nearest limit. The result is simple and keeps in-gamut colours exact. Clipping can merge distinct colours. For example, two different out-of-gamut greens can both become the same sRGB green, which flattens detail in saturated areas.
- Compression. The whole image is shifted so that out-of-gamut colours move inward and in-gamut colours move slightly too. Relationships between colours survive, but colours that were already printable become less accurate.
Which one to use depends on the content, and choosing it is the job of rendering intents, covered in a later chapter. For now, remember that out-of-gamut is not an error message. Software silently picks one of these behaviours.
Why screen and print differ
Screen and print differ for two separate reasons, and it helps to keep them apart.
- Different gamuts. Bright, saturated blues, greens and oranges that a monitor makes with light often exceed what CMYK ink on paper can absorb and reflect. Conversion has to move them to something printable, and the result looks duller.
- Different viewing conditions. A screen emits light and can be brightened. Paper only reflects whatever light falls on it. Printed white is the paper colour, which is never as bright as a screen's white. The same printed sheet looks different under warm and cool light.
A calibrated monitor can preview print colours, but only when the software knows the target print space. This is called soft proofing, and it is a standard part of print workflows.
Common errors
- Untagged images. A file with no embedded colour space is shown using whatever the viewer assumes. Most browsers assume sRGB. Some design tools assume the display's space. A wide-gamut photo viewed as sRGB looks dull, and an sRGB image treated as P3 looks oversaturated.
- Mixing spaces in one document. Placing a P3 photo in an sRGB layout, or the reverse, without conversion produces visible shifts that are hard to trace later.
- Treating hex as universal. A hex code like
#ff8800is by definition sRGB in CSS. It cannot express a Display P3 colour outside sRGB. To use the wider gamut in CSS you needcolor(display-p3 …)or another wide-gamut syntax. - Assuming a bigger gamut is always better. A wide-gamut file sent to a service that expects sRGB may be converted badly or not at all. Work in the space your destination expects.
- Judging colours on an uncalibrated monitor. The display itself may not reach full sRGB, or it may exceed it. A colour that looks correct on your screen may look wrong on others.
Summary of the working model
- A colour model gives the recipe. A colour space fixes the primaries, white point and transfer function so the numbers mean specific colours.
- A gamut is the range of colours a space or device can reach. Gamuts overlap and do not nest neatly. Some print colours are outside sRGB, and many screen colours are outside CMYK.
- The same numbers in different spaces are different colours. Always know which space a value belongs to.
- Colours that do not fit are clipped or compressed. Both change the colour.
Exercise
A designer exports a saturated green from a Display P3 design file and pastes its channel values into a CSS hex code, assuming the colour will look identical in the browser. The green looks duller than in the design tool. Give two reasons this can happen, and say how to keep the original colour in CSS.
Show answer
First, CSS hex codes are defined in sRGB, so the browser reads the same channel numbers as an sRGB colour, which is a less saturated green than the P3 colour with those numbers. Second, if the real P3 colour lies outside the sRGB gamut, no sRGB hex code can reproduce it, so even a correct conversion would clip it to the nearest sRGB green. To keep the original colour, write it with color(display-p3 r g b) using the P3 values (as fractions from 0 to 1), and give an sRGB hex fallback for browsers or displays without wide-gamut support.
Exercise
Using the Python example, a colour is converted from Display P3 linear light to sRGB linear light and comes out as [1.08, 0.40, -0.03]. Is it inside the sRGB gamut? What will clipping produce for these three channels, and why might clipping be a problem for a gradient that contains many such colours?
Show answer
It is outside the sRGB gamut, because the first channel is above 1 and the third is below 0. Clipping sets the channels to [1.0, 0.40, 0.0]. In a gradient, many different out-of-gamut colours would clip to the same limits on the affected channels, so neighbouring colours that were distinct become identical. This produces flat patches or visible bands where the gradient should be smooth.
Exercise
True or false: because CMYK has a smaller gamut than sRGB, every CMYK colour can be shown on an sRGB screen. Explain your answer.
Show answer
False. CMYK gamuts are smaller overall but are not a subset of sRGB. Some saturated cyans and other colours that inks can produce fall outside the sRGB triangle, so an sRGB screen cannot show them exactly. They would be clipped or compressed on screen.