HTML Bgcolor Attribute - GeeksforGeeks
Có thể bạn quan tâm
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:
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:- 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 ArticleTừ khóa » Html Bgcolor Tag
-
HTML | Bgcolor Attribute - GeeksforGeeks
-
HTML Colors - W3Schools
-
How To Set Background Color In HTML? - Tutorialspoint
-
HTML Background-color - Javatpoint
-
HTML - Bgcolor - Tizag Tutorials
-
How To Add & Change Background Color In HTML - HubSpot Blog
-
HTML Background Color - HTML Color Codes
-
HTML Body Bgcolor Attribute - W3Schools
-
» - HTML"> » - HTML
-
Color - Web APIs - MDN Web Docs
-
Why Table Bgcolor Is No Longer Valid Code (And What To ... - HTML
-
HTML Tutorial - Bgcolor,colors For Background, Inserting A Picture On ...
-
HTML Background Color - Set And Change - STechies