Open In App

HTML <body> bgcolor Attribute

Last Updated : 10 May, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The HTML bgcolor attribute determines the background color of elements such as <body>, <table>, <marquee>, <td>, <tr>, and <th>, enhancing visual presentation and design flexibility.

Note: It is not supported by HTML5

Syntax:

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

Parameters:

AttributeDescription
color_nameSpecifies the name of the background color (e.g., red, green, yellow)
hex_numberSpecifies the hex code of the background color (e.g., #RRGGBB)
rgb_numberSpecifies 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.

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:

bgcolor-Attribute-in-body

bgcolor Attribute in body Example Outpuy

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

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 &lt;body&gt; bgcolor Attribute
        </h2>

        <p> It is a Computer Science portal For Geeks </p>

    </center>
</body>
<!-- body tag ends here -->

</html>

Output:

HTML-body-bgcolor-Attribute

HTML bgcolor Attribute Example Output

Supported Browsers:


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads