CSS RGB

CSS Tutorial

CSS Advanced

CSS Responsive

CSS Grid

CSS RGB

The RGB color value stands for  RED, GREEN, and BLUE light sources.

RGB Value

In CSS, a color can be defined as an RGB value, using this formula:

rgb(red, green, blue)

Each parameter (red, green, and blue) specifies the intensity of the color between 0 and 255.

For example, rgb(255, 0, 0) is displayed as red, because red is set to its highest value (255) and the others are set to 0.

To use the black color, set all color parameters to 0, like this: rgb(0, 0, 0).

To use the white color, set all color parameters to 255, like this: rgb(255, 255, 255).

Experiment by mixing the RGB values below:

				
					<p>By using equal values for red, green, and blue, you will get different shades of gray:</p>
<h2 style="background-color:rgb(60, 60, 60);">rgb(60, 60, 60)</h2>
<h2 style="background-color:rgb(90, 90, 90);">rgb(90, 90, 90)</h2>
<h2 style="background-color:rgb(120, 120, 120);">rgb(120, 120, 120)</h2>
<h2 style="background-color:rgb(180, 180, 180);">rgb(180, 180, 180)</h2>
<h2 style="background-color:rgb(210, 210, 210);">rgb(210, 210, 210)</h2>
<h2 style="background-color:rgb(240, 240, 240);">rgb(240, 240, 240)</h2>

				
			

Output

Specify colors using RGB values

rgb(255, 0, 0)

rgb(0, 0, 255)

rgb(60, 179, 113)

rgb(238, 130, 238)

rgb(255, 165, 0)

rgb(106, 90, 205)

Shades of gray are often specified by using equal values for all the 3 light sources:

				
					<p>By using equal values for red, green, and blue, you will get different shades of gray:</p>
<h2 style="background-color:rgb(60, 60, 60);">rgb(60, 60, 60)</h2>
<h2 style="background-color:rgb(90, 90, 90);">rgb(90, 90, 90)</h2>
<h2 style="background-color:rgb(120, 120, 120);">rgb(120, 120, 120)</h2>
<h2 style="background-color:rgb(180, 180, 180);">rgb(180, 180, 180)</h2>
<h2 style="background-color:rgb(210, 210, 210);">rgb(210, 210, 210)</h2>
<h2 style="background-color:rgb(240, 240, 240);">rgb(240, 240, 240)</h2>

				
			

Output

By using equal values for red, green, and blue, you will get different shades of gray:

rgb(60, 60, 60)

rgb(90, 90, 90)

rgb(120, 120, 120)

rgb(180, 180, 180)

rgb(210, 210, 210)

rgb(240, 240, 240)