background-color

The background-color property defines a color for the background of an HTML element.

Syntax

background-color: <value>;

Where <value> can be one of the following:

  • Color keyword: blue, transparent, rebeccapurple
  • Hexadecimal value: #FF0000
  • RGB value: rgb(255, 0, 0)
  • RGBA value: rgba(255, 0, 255, 0.3)
  • HSL value: hsl(0, 100%, 50%)
  • HSLA value: hsla(180, 80%, 100%, 0.8)
  • Special keyword values: currentColor, transparent

Example 1

Set background color of the h1 element to be green:

h1 {
background-color: green;
}

Example 2

Set the background color of the h1 element to be transparent:

h1 {
background-color: transparent;
}

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn CSS on Codecademy