# rgb() / rgba()

> The `rgb()` CSS function specifies a color using red, green and blue values. The `rgba()` CSS function extends it with an alpha channel for transparency.

## How do I add transparency to an rgb() color in CSS?

The functions that define colors with red, green and blue channels, like `rgb(255 136 0)`. An optional alpha value after a slash adds transparency, like `rgb(0 0 0 / 50%)`, while `rgba()` is an older alias that works the same way.

- Topic: Colors
- Type: function
- Browser support: Chrome 1+, Chrome Android 18+, Edge 12+, Firefox 1+, Firefox Android 4+, Safari 1+, Safari iOS 1+

## Example

Wrong:

```css
.overlay {
  background: rgb(0 0 0);
  opacity: 0.5;
}
```

Right:

```css
.overlay {
  background: rgb(0 0 0 / 50%);
}
```

Alpha in the color fades only the background, while `opacity` also fades the text and children.

## Common mistakes

- Mixing commas with the slash, which makes the color invalid.
- Using `opacity` to fade a background, which also fades the text.

## Key points

- Code uses the space-separated form `rgb(0 0 0 / 50%)` rather than `rgba()` with commas.
- Commas and the slash are not mixed in one function, like `rgb(0, 0, 0 / 50%)`.
- When only the background should fade, alpha goes in the color, not in `opacity`.

## Interview questions

### What is the difference between rgb() and rgba()?

None in practice. Both accept an alpha value, and `rgba()` is kept as an alias of `rgb()`.

### Can rgb() values be percentages?

Yes, like `rgb(100% 50% 0%)`. The space syntax allows mixing numbers and percentages; the comma form needs all channels of one type.

## Related cards

- [HEX Color](https://wonderium.dev/css/hex-color.md)
- [hsl()](https://wonderium.dev/css/hsl.md)
- [oklch()](https://wonderium.dev/css/oklch.md)
- [opacity](https://wonderium.dev/css/opacity-property.md)
- [color-mix()](https://wonderium.dev/css/color-mix.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/rgb
- Last updated: 2026-11-25
