liveBook · Manning

Color space

As explained in CSS in Depth, Second Edition

A color space is a coordinate system that represents colors with defined component dimensions and ranges.

When translating a design mockup into CSS, choosing a color notation affects how easily you can adjust colors and which colors you can express. A gamut is the range of available colors; a color space is an arrangement of colors within a gamut. The same gamut can be arranged in more than one way. section 11.0 section 11.2.1

Picture color as a three-dimensional space. RGB uses a rectangular arrangement: red, green, and blue values occupy three coordinate axes. HSL uses a cylindrical arrangement, with hue circling a central axis. That difference matters when editing a color: increasing lightness or rotating hue is often easier to predict than changing several RGB components. section 11.2.1

Figure 11.10 RGB rectangular color space
figure

The rectangular RGB diagram makes the three component axes visible. section 11.2.1

Figure 11.11 HSL polar color space
figure

Compare the HSL cylinder with the RGB diagram to see how hue offers a different way to navigate color. section 11.2.1

Choosing a CSS notation

The value #80c090 records red, green, and blue as hexadecimal components; rgb() can express those same components as decimal values. Both are limited to the sRGB gamut. When adjusting a palette by hue or lightness, hsl() offers a more intuitive approach and broad browser compatibility. oklch() is another intuitive option, but as of mid-2024 newer notations may need fallback values for older browsers. section 11.2.2 section 11.2.2

Color space also matters between chosen colors: specifying a gradient’s color space controls how its colors are interpolated. For a reusable design, choose notation for the adjustments and browser support you need, rather than treating every representation of a color as equally convenient. section 13.4 section 11.2.2

How CSS in Depth, Second Edition covers it

How deep it goes
Defines color space against gamut and compares RGB and HSL arrangements, without deriving their coordinate mathematics.
Examples
Uses RGB and HSL diagrams, hexadecimal and rgb() values, and a gradient-backed button.
What it assumes
Builds on HTML and CSS mockup implementation while introducing the distinction between gamuts and color spaces.
What you can do after
Apply it via CSS color notations to choose editable colors and account for browser support.
How it connects
Connects color spaces to color gamuts, CSS color notations, and gradient interpolation.

Also explained in

Compare how 2 books explain color space →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of CSS in Depth, Second Edition. The section links point to the parts of the book it draws on.