CSS background-color Property

Example

Set the background color for a page:

body {background-color: coral;}

Try it Yourself »

More “Try it Yourself” examples below.

Definition and Usage

The background-color property sets the background color of an element.

The background of an element is the total size of the element, including padding and border (but not the margin).

Tip: Use a background color and a text color that makes the text easy to read.

Default value: transparent
Inherited: no
Animatable: yes. Read about animatable – Try it
Version: CSS1
JavaScript syntax: object.style.backgroundColor=”#00FF00″
Try it

CSS Syntax
background-color: color|transparent|initial|inherit;
Property Values
Value Description
color Specifies the background color. Look at CSS Color Values for a complete list of possible color values.
transparent Specifies that the background color should be transparent. This is default
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit

Example

Specify the background color with a HEX value:

body {background-color: #92a8d1;}

Try it Yourself »

Example

Specify the background color with an RGB value:

body {background-color: rgb(201, 76, 76);}

Try it Yourself »

Example

Specify the background color with an RGBA value:

body {background-color: rgba(201, 76, 76, 0.3);}

Try it Yourself »

Example

Specify the background color with a HSL value:

body {background-color: hsl(89, 43%, 51%);}

Try it Yourself »

Example

Specify the background color with a HSLA value:

body {background-color: hsla(89, 43%, 51%, 0.3);}

Try it Yourself »

Example

Set background colors for different elements:

body {
background-color: #fefbd8;
}h1 {
background-color: #80ced6;
}div {
background-color: #d5f4e6;
}span {
background-color: #f18973;
}

Try it Yourself »

Post Author: Zahid Farid