The best CSS background-color attribute Tutorial In 2024, In this tutorial you can learn Examples,Tag definitions and instructions,Browser Support,Tips and Notes,Property Value,Online examples,related articles,

CSS background-color attribute

Examples

Set the background color of different elements:

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


Tag definitions and instructions

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

The total size of the background elements of the element, including padding and border (but not including margins).

Defaults: transparent
inherit: no
version: CSS1
JavaScript syntax: object object.style.backgroundColor = "# 00FF00"


Browser Support

Figures in the table represent the first browser to support the version number of the property.

Immediately following the digital -webkit-, -ms- or -moz- ago in support of the prefix attribute first browser version number.

属性
background-color 1.0 4.0 1.0 1.0 3.5

All major browsers support background-color property.

Note that IE7 and earlier versions do not support "inherit" value.IE8 need to define! DOCTYPE. IE9 support the "inheritance."


Tips and Notes

Tip: Use thebackground and text colors to make the text easier to read.


Property Value

value description
color Specifies the background color. In value CSS color as possible to find a complete list of color values.
transparent Specifies the background color should be transparent. This is the default
inherit Specifies the background color should be inherited from the parent element


Examples

Online examples

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


related articles

CSS tutorial: CSS background

CSS background-color attribute
10/30