The <bgcolor> is the attribute to set the background color of an HTML element. This attribute is used with the following tags:
- <body>
- <table>
- <marquee>
- <td>
- <th>
- <tr>
Syntax
Example
<"tag" bgcolor="Color_name|rgb number|Hex number">
Illustrations: Below are instances demonstrating the utilization of the <bgcolor> attribute within various tags.
Utilize the <bgcolor> attribute in conjunction with the <body> tag.
Example
<!DOCTYPE html>
<html>
<head>
<title>
Example of Background color Attribute
</title>
</head>
<body bgcolor="lightblue">
<!-- The attribute bgcolor use with the body tag to set the background of web page as lightblue -->
<center>
<h1> C# Tutorial</h1>
<br> <br>
<center>
<h2> Hyper Text Markup Language </h2>
</center>
</body>
</html>
Output:
Example 2: Employ the <bgcolor> property in conjunction with the <tr> element.
Example
<!DOCTYPE html>
<html>
<head>
<title>
Example of Bgcolor Attribute
</title>
</head>
<body bgcolor="red">
<!-- The attribute bgcolor use with the 'body' tag to set the background of web page as red -->
<center>
<h1> C# Tutorial</h1>
<br>
<br>
<center>
<table>
<!-- The attribute bgcolor use with the 'tr' tag to set the background of table rows by different colors -->
<tr bgcolor="blue">
<td> Roll No. </td>
<td> Name </td>
</tr>
<tr bgcolor="lightblue">
<td> 101 </td>
<td> Abhay </td>
</tr>
<tr bgcolor="brown">
<td> 102 </td>
<td> Chetan </td>
</tr>
<tr bgcolor="orange">
<td> 103 </td>
<td> Manpreet </td>
</tr>
<tr bgcolor="yellow">
<td> 104 </td>
<td> Rakesh </td>
</tr>
<tr bgcolor="lightgreen">
<td> 105 </td>
<td> Sumit </td>
</tr>
</table>
</center>
</body>
</html>
Output:
Illustrative Example 3: In this instance, the <bgcolor> attribute is applied alongside the <marquee> tag.
Example
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>
Example of Background color Attribute
</title>
</head>
<body bgcolor="lightgreen">
<!-- The attribute bgcolor use with the body tag to set the background of web page as lightgreen -->
<h1> <font color="blue">
<marquee bgcolor="orange">
<!-- The attribute bgcolor use with the marquee tag to set the background of marquee as orange -->
C# Tutorial
</marquee>
</font>
</h1>
</body>
</html>
Output:
Browser Support
| Element | Chrome | IE | Firefox | Opera | Safari |
|---|---|---|---|---|---|
<bgcolor> |
Yes | Yes | Yes | Yes | Yes |