English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Reference Manual

CSS @rules (RULES)

Complete List of CSS Properties

CSS rgb() function

When using CSS, you can use the CSS rgb() function to provide color values. It allows you to specify RGB color values by directly specifying the red, green, and blue channels.

CSS function

Online example

Using RGB color:

!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Basic Tutorial(oldtoolbag.com)</title>
<style>
#p1 {background-color:rgb(255,0,0);}
#p2 {background-color:rgb(0,255,0);}
#p3 {background-color:rgb(0,0,255);}
#p4 {background-color:rgb(192,192,192);}
#p5 {background-color:rgb(255,255,0);}
#p6 {background-color:rgb(255,0,255);}
</style>
</head>
<body>
<p>RGB color:</p>
<p id="p1">Red</p>
<p id="p2">Green</p>
<p id="p3">Blue</p>
<p id="p4">Gray</p>
<p id="p5">Yellow</p>
<p id="p6">Cherry color</p>
</body>
</html>
Test and see ‹/›

Definition and usage

The rgb() function uses the superposition of three colors: red (R), green (G), and blue (B) to generate various colors.

RGB stands for Red, Green, Blue (English: Red, Green, Blue).

  • Red (R)to 255 The integer between the two represents the red component of the color.

  • Green (G)to 255 The integer between the two represents the green component of the color.

  • Blue (B)to 255 The integer between the two represents the blue component of the color.

Supported version: CSS2

Browser compatibility

The numbers in the table represent the first browser version number that supports the function.

Function




rgb()1.04.01.01.03.5

CSS syntax

rgb(red, green, blue)
ValueDescription
redDefine the red value, the range is 0 ~ 255, also can use percentage 0% ~ 100%
greenDefine the green value, the range is 0 ~ 255, also can use percentage 0% ~ 100%
blueDefine the blue value, the range is 0 ~ 255, also can use percentage 0% ~ 100%

CSS function