CSS rgb()

Anonymous contributor's avatar
Anonymous contributor
Published Jul 21, 2021Updated Nov 14, 2023
Contribute to Docs

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

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • In this CSS tutorial, you’ll learn how to add CSS to visually transform HTML into eye-catching sites.
    • Beginner Friendly.
      6 hours

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

Contribute to Docs

Learn CSS on Codecademy

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • In this CSS tutorial, you’ll learn how to add CSS to visually transform HTML into eye-catching sites.
    • Beginner Friendly.
      6 hours