background-color property

Image Tutorials

Definition and Usage

The background-color CSS property sets the background color of an element, either through a color value or the keyword transparent.

  • Initialtransparent
  • Applies toall elements
  • Inheritedno
  • Mediavisual
  • Computed ValueIf the value is translucent, the computed value will be the rgba() corresponding one. If it isn’t, it will be the rgb() corresponding one. The transparent keyword maps to rgb(0,0,0).
  • Animatableyes, as a color
  • Canonical orderthe unique non-ambiguous order defined by the formal grammar

Syntax

Formal syntax: <color>
background-color: red
background-color: rgb(255, 255, 128)
background-color: hsla(50, 33%, 25%, 0.75)
background-color: currentColor
background-color: transparent
background-color: #bbff00
background-color: inherit

Values

<color>
Is a CSS <color> that describes the uniform color of the background. Even if one or several background-image are defined, this color can be affect the rendering, by transparency if the images aren’t opaque.

Examples

01 .exampleOne {
02         background-colorteal;
03         colorwhite;
04 }
05 .exampleTwo {
06         background-colorrgb(153,102,153);
07         colorrgb(255,255,204);
08 }
09 .exampleThree {
10         background-color#777799;
11         color#FFFFFF;
12 }
13 .exampleFour {
14   background-color: hsla(30020%50%0.8);
15   color: hsla(60100%90%0.8);
16 }

Compatibility

Desktop browsers

Feature Firefox (Gecko) Chrome Internet Explorer Opera Safari (WebKit)
Basic support 1.0 (1.7 or earlier) 1.0 4.0 3.5 1.0 (85)

Mobile browsers

Feature Firefox Mobile (Gecko) Android IE Phone Opera Mobile Safari Mobile
Basic support 1.0 (1.9.2) (Yes) (Yes) (Yes) (Yes)

Rate article