Encodera

Thanks for reading!

Donate to the site — we work hard for you.

HTML & CSS reference

rgb()

A color from red, green and blue components, with optional transparency.

Syntax

rgb(red green blue / alpha)

Parameters

ParameterTypeDescription
red green blue0–255Three numbers from 0 to 255 separated by spaces.
alpha0–1After a slash: opacity from 0 to 1 or in percent.

Examples

An opaque and a semi-transparent color:

<p style="background: rgb(255 99 71); padding: 8px;">rgb(255 99 71)</p>
<p style="background: rgb(255 99 71 / 0.4); padding: 8px;">rgb(255 99 71 / 0.4) — semi-transparent</p>

Notes

The old syntax with commas, rgba(255, 99, 71, 0.4), still works; the modern one uses spaces and a slash and needs no separate rgba().

See also

  • hsl() — A color by hue, saturation and lightness.
  • oklch() — A color in the OKLCH space: perceived lightness, chroma and hue.
  • color — The color of the text (and the default color of borders and SVG icons).
  • opacity — The transparency of the whole element together with its content.

Related recipes

In the tutorial

  • Colors — Text and background color, ways to write a color in CSS — names, hex, rgb() and hsl() — and transparency.

Thanks for reading!

Donate to the site — we work hard for you.