Web Lab Documentation

Background Color

Category:CSS Properties

Background Color

The background-color property specifies the background color of an element. Color values can be defined with HEX, RGB, or color name.

Examples

Background with Color Names

Setting the background with a color Name.

body {
  background-color: blue;
}

Background Color in RGB

Setting the background color with an RGB value.

body {
  background-color: rgb(100, 70, 200);
}

Background Color in Hex

Setting the background color with a HEX value.

body {
  background-color: #92a8d1;
}

Syntax

background-color: value;

Tips

  • The default background color is transparent.
  • The background of an element is the total size of the element, including padding and border (but not the margin).
  • Use a background color and a text color that makes the text readable.

Additional Information

Found a bug in the documentation? Let us know at support@code.org.