CSS Reference ยท Colors and Backgrounds
The background-color property
Reference for CSS background-color: accepted color notations, transparency, which box it paints, how it sits under background images, and live examples.
The background-color property fills the background of an element with a single solid color. The color is painted underneath any background images and covers the area chosen by background-clip, which by default is the whole border box (content, padding and the area under the border).
The default is transparent, so most elements show whatever is behind them until you give them a color.
.alert { background-color: #fff4e5; } .overlay { background-color: rgb(0 0 0 / 60%); }
Try it
Syntax
background-color: <color>; background-color: #eef; background-color: rgb(0 0 0 / 50%); background-color: currentcolor;
- Initial value:
transparent - Applies to: all elements
- Inherited: no
- Animatable: yes (as a color)
- Computed value: the computed color
Values
| Value | Description |
|---|---|
Named color, hex, rgb(), hsl(), hwb(), oklch() and so on |
Any CSS color. Alpha channels make the fill translucent. |
transparent |
Fully transparent black. The default. |
currentcolor |
The element's text color, handy for badges and bars that follow color. |
color-mix(), light-dark() |
Computed colors, mixed or scheme-dependent. |
| System color | Such as Canvas or ButtonFace, which follows the user's theme. |
Usage notes
- Not inherited. A child with no background shows its parent's background through it. If you want the same color, set it explicitly or use
inherit. - Page background. The background of
htmlorbodyis propagated to the whole canvas, so one rule colors the entire viewport even ifbodyis short. - Layering order. The color is always the bottom layer, painted below every
background-image. In thebackgroundshorthand it must be in the last layer. - Painted under the border. With a translucent or dashed border, the background color shows through the gaps. Use
background-clip: padding-boxto stop it at the border edge. - Alpha versus
opacity. A color with alpha fades only the background.opacitywould fade the text and children too. - Accessibility. Always check text contrast against the background. Forced-colors modes (such as Windows high contrast) replace author backgrounds on many elements, so do not rely on a background alone to show state: use a border or text as well.
Browser support
Supported in every browser. Modern color functions in the value are available in current browsers; check a compatibility table for older targets.
Related
backgroundโ the shorthandbackground-clipโ which box gets paintedcolorโ text coloropacity- Lesson: Backgrounds
- Lesson: Colors