Open In App

HTML <body> bgcolor Attribute

Last Updated : 02 Jul, 2025
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

The bgcolor attribute in HTML was traditionally used to set background colors for elements such as <body>, <table>, <td>, and <tr>. It supports named colors, hex codes, and RGB values. However, since it's deprecated in HTML5, over 90% of modern developers now prefer using CSS's background-color property for better styling control and cleaner code.

Note: It is not supported by HTML5

Syntax

<body bgcolor="color_name | hex_number | rgb_number">

Parameters

AttributeDescription
color_name Specifies the name of the background color (e.g., red, green, yellow)
hex_number Specifies the hex code of the background color (e.g., #RRGGBB)
rgb_number Specifies the RGB value of the background color (e.g., rgb(255, 255, 255))

Examples of HTML bgcolor attribute

Example 1: In this example, we simply set the bg color of the body to green.

index.html
<!DOCTYPE html>
<html>
<!-- body tag starts here -->
<body bgcolor="green">
    <h2>GeeksforGeeks</h2>
    <p> It is a Computer Science portal For Geeks </p>
</body>
<!-- body tag ends here -->
</html>

Output


Output
Output


Example 2: This example using hex code for background color in HTML.

index.html
<!DOCTYPE html>
<html>
<head>
    <title> HTML body Bgcolor Attribute </title>
</head>
<!-- body tag starts here -->
<body text="green" bgcolor="#FFA500">
    <center>
        <h1>GeeksforGeeks</h1>
        <h2>
            HTML <body> bgcolor Attribute
        </h2>
        <p> It is a Computer Science portal For Geeks </p>
    </center>
</body>
<!-- body tag ends here -->
</html>

Output

Output
Output
Browser Support



Attribute
ChromeEdgeFirefoxSafariOpera
bgcolor
Desktopv1v12v1v1v15
Mobilev18v4v1v14

HTML <body> bgcolor Attribute

Similar Reads