Example
Specify a background color for an HTML document<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body bgcolor="#E6E6FA"> <h1>Hello world!</h1> <p><a href="http://Xhtml.co.il">Visit Xhtml.co.il !</a></p> <p><b>Note:</b> If using color names, different browsers may render different colors, and Firefox have problems if the attribute value is in RGB code (will not display correct color).</p> <p><b>Tip:</b> To produce equal results in all browsers, always use hex code to specify colors.</p> <p>However, the bgcolor attribute was deprecated in HTML 4, and is not supported in HTML 4.01 Strict DTD or in XHTML 1.0 Strict DTD. Use CSS instead.</p> </body> </html>
Compatibility Notes
The bgcolor attribute of <body> is deprecated, and is not supported in HTML 4.01 Strict / XHTML 1.0 Strict DTD.
A deprecated element or attribute is one that has been outdated.
Deprecated elements may become obsolete in the future, but browsers should continue to support deprecated elements for backward compatibility.
Use CSS instead.
CSS syntax: <body style="background-color:#E6E6FA">
CSS Example: Set the background color of a document.
In our CSS tutorial you can find more details about the background-color property.
Definition and Usage
The bgcolor attribute specifies the background color of a document.
Browser Support
The
bgcolor attribute supported in all major browsersSyntax
<body bgcolor="value">
Attribute Values
| Value | Description |
|---|---|
| color_name | Specifies the link color with a color name (like "red") |
| hex_number | Specifies the link color with a hex code (like "#ff0000") |
| rgb_number | Specifies the link color with an rgb code (like "rgb(255,0,0)") |
Was this information helpful?

