HTML Bgcolor Attribute - GeeksforGeeks

The HTML bgcolor attribute sets background colors for elements like <body>, <table>, <td>, and <tr>. While it accepts color names, hex, or RGB values, it is deprecated in HTML5. CSS’s background-color property is now preferred for styling backgrounds.

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 <body> 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:

  • Google Chrome
  • Edge
  • Firefox
  • Opera
  • Safari

HTML <body> bgcolor Attribute – FAQs

What are the alternatives to the <body> bgcolor attribute in HTML5?

Use CSS with the background-color property, e.g., <body style=”background-color: blue;”>.

Can I use hexadecimal colors with the <body> bgcolor attribute?

Yes, hexadecimal color codes are supported, e.g., <body bgcolor=”#FF5733″>.

Can I use color names with the <body> bgcolor attribute?

Yes, standard color names are supported, e.g., <body bgcolor=”red”>.

Does the <body> bgcolor attribute support RGB values?

Yes, RGB values are supported, but it’s better to use CSS for such values, e.g., <body style=”background-color: rgb(255, 0, 0);”>.

Why should I avoid using the <body> bgcolor attribute?

It is outdated and not supported in modern HTML standards. CSS is the preferred method for styling.

H

hritikbhatnagar2182 Follow Improve Previous Article HTML <font> face Attribute Next Article

Từ khóa » Html Bgcolor Codes