docs.rodeo

MDN Web Docs mirror

Color space

{{GlossarySidebar}} 

Color spaces are named organizations of colors for underlying color models of coordinate-based color arrangements. A color model defines how the components of a color (for example, the h, w, and b channels of an hwb() color) relate to a color space. Most color spaces are three- or four- dimensional grids that represent colors. Each dimension (or axis) corresponds to a different channel. Colors can be expressed in multiple color spaces, and can be transformed from one color space to another, while still looking the same.

Color spaces categorize and define specific ranges of colors. Each color space is defined by a mathematical model and associated rule set. Each color space has a defined {{glossary("Gamut", "gamut")}} , which refers to the specific range of colors it can represent. These rules enable consistent and reproducible color representation across different devices and software.

The sRGB color space (standard red, green, and blue) was created for the web, but we are no longer limited to this color space. CSS Color Module Level 4 specifies several predefined color spaces, and CSS Color Module Level 5 goes further, specifying features for defining custom color spaces.

Named color spaces

The predefined RGB color spaces include srgb, srgb-linear, display-p3, a98-rgb, prophoto-rgb, and rec2020. The predefined CIELAB color spaces include lab-d50 and lab-d65. The predefined XYZ color spaces include xyz-d50, and xyz-d65 (and xyz, an alias for xyz-d65).

Color spaces are either rectangular or polar. Rectangular color spaces include srgb, srgb-linear, display-p3, a98-rgb, prophoto-rgb, rec2020, lab, oklab, xyz-d50, and xyz-d65 (or xyz). The polar color spaces include hsl, hwb, lch, and oklch.

RGB color spaces

RGB is a color model that represents colors as mixtures of three underlying components — red, green, and blue color channels — that create various hues when combined. sRGB, or “Standard RGB”, is the underlying color space for {{Glossary("RGB")}}  colors. sRGB is intended to codify the display specification of PC and the {{glossary("world wide web", "Web")}}  based imaging systems. It is now usually the assumed color space for those without tagged or without an embedded color profile.

There are several RGB color spaces, like the Adobe RGB color space, that can represent a wider {{glossary("gamut")}}  of color than the sRGB color space. The coordinates in sRGB and Adobe RGB (a98-rgb) are different. There are many ways to describe the RGB components of a color. In {{Glossary("CSS")}}  they can be represented as a single 24-bit integer in hexadecimal notation (for example, #add8e6 is light blue), or in rgb() functional notation as three separate numbers between 0 and 255 (for example, rgb(46 139.5 87)).

CSS <color> values in the sRGB color spaces include {{cssxref("hex-color")}} , {{cssxref("named-color")}} , {{cssxref("color_value/rgb", "rgb()")}} , {{cssxref("color_value/hsl", "hsl()")}}  (hue, saturation, lightness), and {{cssxref("color_value/hwb", "hwb()")}}  (hue, whiteness, blackness). There are also the srgb, srgb-linear, a98-rgb, and prophoto-rgb color spaces for the color() function.

The HSV (hue, saturation, and value) color space, and its synonym HSB (hue, saturation, and brightness), are represented in CSS as hwb(). Named colors are simply keywords mapped to specific hex values. Converting these various color notations to sRGB is straightforward mathematically. Note that {{cssxref("&lt;color&gt;","currentcolor","#currentcolor_keyword")}}  can be any color — it is not restricted to sRGB.

The rgb() color function is not the only color function that can represent the sRGB color space. Cylindrical coordinate systems like the HSL (hue-saturation-lightness) or HWB (hue-whiteness-blackness) color models are also used to represent a sRGB color on the web.

[!NOTE] Additional cylindrical RGB spaces that are not in the CSS specification include: HSI (hue, saturation, and intensity), Okhsv, Okhsl, HSLuv, HPLuv, and Cubehelix.

CIELAB color spaces

The CIELAB (or CIELab) color space, also referred to as L*a*b* (or Lab* for short), represents the entire range of color that humans can see. This color space was defined by International Commission on Illumination (CIE). It expresses color as three values: L* for perceptual lightness, and a* and b* for the four unique colors of human vision: red, green, blue, and yellow.

Lab is a rectangular coordinate system, with a central lightness L axis. Positive values along the a axis are a purplish red while negative values are the complement: green. Positive values along the b axis are yellow and negative are blue/violet. Desaturated colors have small values for a and b with greater absolute values being more saturated.

CIELab color functions include {{CSSXref("color_value/lab", "lab()")}}  (lightness, a-axis, b-axis) and {{CSSXref("color_value/lch", "lch()")}}  (lightness, chroma, hue) as well as {{CSSXref("color_value/oklab", "oklab()")}}  and {{CSSXref("color_value/oklch", "oklch()")}} . The lightness values are the same, but lch() and oklch are polar, cylindrical coordinate systems, that use polar coordinates C (chroma) and H (hue) rather than axes.

[!NOTE] The hue and lightness in lch() and oklch are different from the same-named values in {{cssxref("color_value/hsl", "hsl()")}}  or other sRGB color spaces.

CIELab color spaces, including Lab, Lch, Oklab, and Oklch, are device-independent color spaces.

XYZ color spaces

While combinations of red, green, and blue work well for representing colors on screen, sRGB doesn’t directly correspond to how humans perceive color. Created by the International Commission on Illumination (CIE) in 1931, the CIE 1931 XYZ (or XYZ for short) color spaces are the first defined quantitative links between distributions of wavelengths in the electromagnetic visible spectrum and perceived colors in human vision.

People with normal vision have three kinds of cone cells that sense light, having peaks of spectral sensitivity in differing wavelengths. The CIE X, Y, and Z parameters correspond to levels of stimuli of the three kinds of cone cells which, in principle, describe every visible color. The Y channel represents the luminance of a color. The Z channel reflects the amount of blue in the color but is not the same as the B in RGB. The X axis is orthogonal to the Y- and Z- axis of the XYZ color 3D coordinate system.

See also

In this article

View on MDN