rgb()
A color from red, green and blue components, with optional transparency.
Syntax
rgb(red green blue / alpha)Parameters
| Parameter | Type | Description |
|---|---|---|
| red green blue | 0–255 | Three numbers from 0 to 255 separated by spaces. |
| alpha | 0–1 | After 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
Related recipes
In the tutorial
- Colors — Text and background color, ways to write a color in CSS — names, hex, rgb() and hsl() — and transparency.