CSS rgb() Function

❮ Previous Functions Next ❯

Example

.example1 {
  background: rgb(0, 255, 0);
}

.example2 {
  background: rgb(0%, 100%, 0%);
}




Meaning

The rgb() css function defines a given color in the sRGB color space according to its red, green, and blue components.

Note: RGB colors can be expressed through both hexadecimal (prefixed with #) and functional (rgb(), rgba()) notations.

Note: The legacy rgba() syntax is an alias for rgb(), accepting the same parameters and behaving in the same way.

The rgb() function accepts three space-separated values, representing respectively values for red, green, and blue.

Live Demonstration:

Red:


Green:


Blue:

Version: CSS3




Standard Syntax

/* Syntax with space-separated values */
rgb(r g b)

/* Syntax with comma-separated values */
rgb(r, g, b)



Browser Support

The numbers in the table specify the first browser version that fully supports the property.




Status







Function Arguments

The following table describes the arguments of this function.

Argument Description
r Red. Specifies numbers or percentages, where the number 255 corresponds to 100%.
g Green. Specifies numbers or percentages, where the number 255 corresponds to 100%.
b Blue. Specifies numbers or percentages, where the number 255 corresponds to 100%.
❮ Previous Functions Next ❯