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.

Show demo ❯

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

Browser Support

The numbers in the table specify the first browser version that fully supports the property.

Property
background-color 1.0 4.0 1.0 1.0 3.5


CSS Syntax

background-color: color|transparent|initial|inherit;

Property Values

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

More Examples

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 »

Related Pages

CSS tutorial: CSS Background

HTML DOM reference: backgroundColor property


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.