Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

CSS background-color property


May 05, 2021 CSS Reference Manual


Table of contents


CSS background-color property


Set the background color of different elements:

body
{
background-color:yellow;
}
h1
{
background-color:#00ff00;
}
p
{
background-color:rgb(255,0,255);
}

Try it out . . .

Label definition and instructions for use

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 boundaries (but not margins).

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


Browser support

The numbers in the table support the first browser version number of the property.

The number immediately before -webkit-, -ms- or -moz- is the first browser version number that supports the prefix property.

Attributes
background-color 1.0 4.0 1.0 1.0 3.5

Background-color properties are supported by all major browsers.

Note I E7 and earlier versions do not support "inherited" values. I E8 needs to be defined! D OCTYPE。 IE9 supports inheritance.


Tips and comments

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


The property value

Value Describe
color Specify the background color. A complete list of color values that are nearly possible in CSS Color Values.
transparent The specified background color should be transparent. This is the default
inherit Specify the background color, which should be inherited from the parent element


CSS background-color property

Online instance

Set the background color of some text
This example shows how to set the background color of some text.


Related articles

CSS tutorial: CSS background