css types color rgb()

The rgb() functional notation expresses a color according to its red, green, and blue components. An optional alpha component represents the color's transparency.

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

Syntax

rgb(255 255 255)
rgb(255 255 255 / .5)

The function also accepts a legacy syntax in which all values are separated with commas.

Values

Functional notation: rgb(R G B[ / A])

R, G, B

Each as a <number>() between 0 and 255, a <percentage>() between 0% and 100%, or the keyword none, which represent the red, green, and blue channels, respectively.

A Optional

An <alpha-value>() or the keyword none, where the number 1 corresponds to 100% (full opacity).

Note: See Missing color components for the effect of none.

Examples

Legacy syntax: comma-separated values

For legacy reasons, the rgb() function accepts a form in which all values are separated using commas.

HTML

<div class="space-separated"></div>
<div class="comma-separated"></div>

CSS

div {
  width: 100px;
  height: 50px;
  margin: 1rem;
}

div.space-separated {
  background-color: rgb(255 0 0 / 0.5);
}

div.comma-separated {
  background-color: rgb(255, 0, 0, 0.5);
}

Legacy syntax: rgba()

The legacy rgba() syntax is an alias for rgb().

HTML

<div class="rgb"></div>
<div class="rgba"></div>

CSS

div {
  width: 100px;
  height: 50px;
  margin: 1rem;
}

div.rgb {
  background-color: rgb(255 0 0 / 0.5);
}

div.rgba {
  background-color: rgba(255 0 0 / 0.5);
}

See also