CSS rgb()
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.
Syntax
<property>: rbg(red, green, blue);
where red, green, blue can be one of the following:
- Number values: ranging between
0and255 - Percentage values: ranging between
0%and100%
Example 1
Set the font color of the h1 element to be white:
h1 {color: rgb(255, 255, 255);}

Example 2
Set the font color of the h1 element to be black:
h1 {color: rgb(0, 0, 0);}

Example 3
Set the font color of the h1 element to be a lavender color:
h1 {color: rgb(124, 124, 242);}

Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve 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