English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS reference manual

CSS @rule (RULES)

CSS attribute encyclopedia

CSS background-color attribute usage and examples

CSS background-The color attribute sets the background color of the element. You can set the background color by color values or the keyword 'transparent'.

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

The following table summarizes the usage context and version history of this attribute.

Default value:transparent
Applicable to:All elements
Inheritance:No
Animatable:Yes.Please refer to Animation properties.
Version:CSS 1,2,3
JavaScript syntax:    
object    object.style.backgroundColor="#00FF00"

background-color usage syntax

The syntax of this attribute is as follows:

background-color: color | transparent | initial | inherit

The following examples demonstrate how to use background-color attribute.

body { background-color: yellow;}
h1 {background-color: rgb(255,0,0);}
p {background-color: #00ff00;}
Test to see‹/›

Attribute values

The following table describes the values of this attribute.

ValueDescription
colorSpecify the background color. SeeCSS color valuesto get the list of possible color values.
transparentSet background-Color is transparent, meaning the content and background of the element under a transparent background will be visible. This is the default value.
initialSet this attribute to its default value.
inheritIf specified, the associated element adopts its parent element's background-Calculated value of the color attribute.

Browser compatibility

background-Browser compatibility of the color attribute, all mainstream browsers support this attribute.

  • Firefox 1+

  • Google Chrome1+

  • Internet Explorer 4+

  • Apple Safari 1+

  • Opera 3.5+

Further reading

Please refer to the following tutorials:CSS background,CSS3Background.

Related attributes:background,background-attachment,background-clip,background-image,background-origin,background-position,background-repeat,background-size.