rgb()

Published Jul 21, 2021Updated Nov 14, 2023
Contribute to Docs

Defines a color by providing three comma separated values for red, green, and blue.

Syntax

<property>: rbg(red, green, blue);

where red, green, blue can be one of the following:

  • Number values: ranging between 0 and 255
  • Percentage values: ranging between 0% and 100%

Example 1

Set the font color of the h1 element to be white:

h1 {
color: rgb(255, 255, 255);
}

RGB White Font Example

Example 2

Set the font color of the h1 element to be black:

h1 {
color: rgb(0, 0, 0);
}

RGB Black Font Example

Example 3

Set the font color of the h1 element to be a lavender color:

h1 {
color: rgb(124, 124, 242);
}

RGB Lavender Font Example

All contributors

Looking to contribute?

Learn CSS on Codecademy