Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS background-color Property

CSS background-color Property

Example

Set the background color of different elements:

body

{

background-color:

yellow

;

}

h1

{

background-color:

#00ff00

;

}

p

{

background-color:

rgb

(

255

,

0

,

255

)

;

}

Try it »


Tag Definition and Usage Notes

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

An element's background is the total size of the element, including padding and border (but not margins).

Default value: transparent
Inherited: no
Version: CSS1
JavaScript syntax: object object.style.backgroundColor="#00FF00"

Browser support

The numbers in the table indicate the first browser version that supports this property.

A number immediately before -webkit-, -ms-, or -moz- indicates the first browser version that supports that prefixed property.

property
background-color 1.0 4.0 1.0 1.0 3.5

All major browsers support the background-color property.

Note IE7 and earlier do not support the "inherit" value. IE8 requires a !DOCTYPE definition. IE9 supports "inherit".


Tips and Notes

Tip: Use background and text colors to make text easy to read.


Attribute values

Value Description
color Specifies the background color. SeeCSS color valuesfor a complete list of color values.
transparent Specifies that the background color should be transparent. This is the default
inherit Specifies that the background color should be inherited from the parent element

Online example

Set the background color of part of the text
This example demonstrates how to set the background color of part of the text.


Related Articles

CSS Tutorial: CSS Backgrounds