Quackit Logo
HTML
CSS
Scripting
Database
Hosting
Design
XML
IMCreator - Free Website Builder

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.

CodeResult

CSS background color example.

The following example only sets the background color of a <p> element inside the <div>.

CodeResult

CSS background color example.

Also see the CSS background property for setting all background properties of an element.

Enjoy this page?

  1. Link to this page (copy/paste into your own website or blog):
  2. Link to Quackit using one of these banner ads.

Thanks for supporting Quackit!