CSS bgcolor
You may be familiar with the old HTML bgcolor
attribute. This attribute (which was deprecated in HTML 4 and has been discontinued as of HTML 5) allowed you to set the background color of HTML elements. For example, using that attribute, you could set the background color of elements such as the <table>
element or the <body>
element.
Although there is no CSS bgcolor
property or attribute, there is the CSS background-color
property. The background-color
property is the CSS equivalent to the old HTML bgcolor
attribute. Actually, the CSS background-color
property is more powerful than the HTML bgcolor
attribute. One major advantage of the background-color
property is that it can be applied to any element.
Example of Usage
Background color of a <div>
element.
The following example only sets the background color of a <p>
element inside the <div>
.
Also see the CSS background property for setting all background properties of an element.