What is bgcolor in HTML?

Learn via video course
FREE
View all courses
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
Topics Covered

In HTML, the bgcolor attribute sets the background color of a HTML element. The bgcolor attribute can be used with the HTML tags like <body>, <table>, <marquee>, <td>, <tr>, <th>.

bgcolor in html example

Pencil: Deprecated warning: HTML5 does not support the bgcolor attribute. It is recommended to use CSS instead.

The syntax for the CSS is

The syntax for bgcolor

  • tag - you can use any HTML tag like <body> , <p>, <button>, etc.
  • rgb/hex/color_name - These are attribute values, there are different ways to use colors but can use only one at a time. The attribute values are specified below :

Attribute Values

Attribute valueDescription
rgb_numberA rgb code determines the background color (like "rgb(255,225,0)")
hex_numberHex code specifies the color of the background (like "#ff0ff0")
color_nameThis color specifies the background color (like "blue")

Examples

Example 1: set the bg color of the body to blue.

In the below example, we are using the bgcolor attribute with the <body> tag, and we are setting the value of the attribute to bgcolor="blue". Hence, we can see that the background color appears as blue in the output image below.

HTML Code

Browser Output

set the bg color of the body to blue

Example 2: HTML bgcolor Attribute by specifying the text as blue & background as pink color.

In below example, we are using the bgcolor attribute with the <body> tag, and we set the value of the attribute to pink along with that we set the text color inside the body to blue. Hence, we can see that the background color appears pink and the text is blue in the output image.

HTML Code

Browser Output set the bg color of the body to pink and text to blue

Example 3: Using bgcolor with table.

In the below example we see the bgcolor for the table as yellow inside the table tag along with that we are using the bgcolor attribute with the tag, and we set the value of the attribute to lightblue.

HTML Code

Browser Output

Using bgcolor with table

Supported Browsers

The bgcolor attribute in HTML is supported by the following browsers :

AttributeChromeMicrosoft EdgeFirefoxSafariOpera
bgcolorYesYesYesYesYes

Conclusion

Given below are the takeaways from this article :

  • The bgcolor element is used to set the background color of an HTML element.
  • The HTML5 does not support the bgcolor attribute.
  • The bgcolor attribute can be used with the HTML tags like <body>, <table>, <marquee>, <td>, <tr>, <th>.
  • The bgcolor almost supports all the main browsers like Chrome, Edge, Firefox, Safari and Opera.