# background-color

> The `background-color` CSS property sets the color of an element's background.

## How do I set a transparent background color in CSS?

The property that sets the background color of an element. It fills the entire area of the element with the specified color, which can be solid or semi-transparent.

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

## Example

Wrong:

```css
.overlay {
  background-color: black;
  opacity: 0.5;
}
```

Right:

```css
.overlay {
  background-color: rgb(0 0 0 / 0.5);
}
```

An alpha color makes only the background transparent, while `opacity` fades the content too.

## Common mistakes

- Using `opacity` for a see-through background and the text fades too.

## Key points

- Text on the background meets WCAG contrast minimums against its text color.
- Semi-transparent backgrounds use an alpha color like `rgb(0 0 0 / 50%)`, not `opacity`, so children stay opaque.
- Theme colors come from custom properties or `light-dark()` instead of repeated hardcoded hex values.

## Interview questions

### What is the default background-color?

It is 'transparent', so the parent's background shows through.

### Does background-color cover the padding and border?

It covers the padding and the area under the border by default. Use `background-clip` to change that.

## Related cards

- [background](https://wonderium.dev/css/background.md)
- [rgb() / rgba()](https://wonderium.dev/css/rgb.md)
- [opacity()](https://wonderium.dev/css/opacity.md)
- [light-dark()](https://wonderium.dev/css/light-dark.md)
- [background-clip](https://wonderium.dev/css/background-clip.md)

---

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