liveBook · Manning

Rgb() function

As explained in CSS in Depth, Second Edition

The CSS rgb() color function specifies a color using red, green, and blue components in the sRGB color space.

Use `rgb()` to specify a CSS color with decimal red, green, and blue values. Each component ranges from 0 to 255. Like hex notation, `rgb()` represents colors within the sRGB gamut. section 11.2.2

Reading equivalent colors

`rgb(0 0 0)` is black, equivalent to `#000`. `rgb(136 0 0)` is brick red, equivalent to `#800`. Hex writes the same channel values in base 16 rather than decimal. section 11.2.2

`rgb()` is well supported across browsers. When using newer color notations such as `oklch()`, consider a fallback in a better-supported notation while browser support catches up. section 11.2.2

How CSS in Depth, Second Edition covers it

How deep it goes
Defines component ranges and hex equivalence, but stops short of a broader `rgb()` syntax reference.
Examples
Compares `rgb(0 0 0)` with `#000` and `rgb(136 0 0)` with `#800`.
What it assumes
Introduces hexadecimal base-16 digits and their decimal equivalents before comparing color values.
What you can do after
Evaluate/understand equivalent RGB and hex values when choosing a CSS color notation.
How it connects
Connects hex color notation, the sRGB gamut, and browser support for CSS color notations.

Also explained in

Compare how 3 books explain rgb() function →

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.