HTML <body> bgcolor Attribute
Last Updated :
10 May, 2024
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:
Attribute | Description |
---|
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.
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 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 <body> bgcolor Attribute
</h2>
<p> It is a Computer Science portal For Geeks </p>
</center>
</body>
<!-- body tag ends here -->
</html>
Output:
HTML bgcolor Attribute Example Output
Supported Browsers:
Share your thoughts in the comments
Please Login to comment...