## HTML <body> `bgcolor` Attribute
The `bgcolor` attribute is used to specify the background color of an HTML document.
> **β οΈ Deprecation Notice:** The `bgcolor` attribute was deprecated in HTML 4.01 and is **not supported in HTML5**. Modern web development standards require using CSS instead of this attribute to style document backgrounds.
---
## Browser Support
| Attribute | Chrome | Firefox | Safari | Edge/IE | Opera |
| :--- | :--- | :--- | :--- | :--- | :--- |
| **bgcolor** | Yes | Yes | Yes | Yes | Yes |
*Note: Although all major browsers still support this attribute for backward compatibility, you should avoid using it in modern web projects.*
---
## Syntax
```html
```
### Attribute Values
| Value | Description | Example |
| :--- | :--- | :--- |
| *color_name* | Specifies the background color using a standard color name. | `bgcolor="red"` |
| *hex_number* | Specifies the background color using a hexadecimal value. | `bgcolor="#ff0000"` |
| *rgb_number* | Specifies the background color using an RGB value. | `bgcolor="rgb(255,0,0)"` |
---
## Code Examples
### Legacy HTML Example (Not Recommended)
This example demonstrates how the `bgcolor` attribute was traditionally used to set a light gray background color for the document.
```html
Legacy bgcolor Example
Hello World!
This page uses the legacy bgcolor attribute to set the background color.
```
### Modern CSS Example (Recommended)
To comply with modern web standards (HTML5), you should use the CSS `background-color` property instead. This can be applied inline or via an external/internal stylesheet.
#### Inline CSS:
```html
Modern CSS Background Example
Hello World!
This page uses modern inline CSS to set the background color.
```
#### Internal CSS (Best Practice for Single Pages):
```html
Modern CSS Background Example
Hello World!
This page uses an internal stylesheet to set the background color.
```
---
## Compatibility Notes
* **HTML 4.01:** The `bgcolor` attribute was deprecated in favor of style sheets.
* **XHTML 1.0 Strict:** The `bgcolor` attribute is not supported.
* **HTML5:** The `bgcolor` attribute is completely obsolete.
### Why you should use CSS instead:
1. **Separation of Concerns:** HTML should only define the structure of the document, while CSS handles the presentation and styling.
2. **Maintainability:** Changing the background color across multiple pages is much easier when managed through a single external CSS file rather than updating individual `` tags on every page.
3. **Flexibility:** CSS allows for advanced background styling, such as gradients, background images, and media queries for dark/light mode switching.