The bgcolor attribute in the <th> tag is used to set the background color of a header cell. It was commonly used in older HTML but is now deprecated in HTML5.
- Sets the background color of a header cell.
- Accepts color names, hex codes, or RGB values.
- Used only with the <th> element.
Note: It is not supported by HTML5.
Syntax
<th bgcolor="color_name | hex_number | rgb_number">Attribute Values
- color_name: Sets background color using a color name (e.g., "red")
- hex_number: Sets background color using a hex code (e.g., "#0000ff")
- rgb_number: Sets background color using RGB values (e.g., "rgb(0, 153, 0)")
Example 1: Using Color name
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>
<head>
<title>
HTML th bgcolor Attribute
</title>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>HTML th bgcolor Attribute</h2>
<!--Driver Code Ends-->
<table width="500" border="1">
<tr>
<th bgcolor="green">Name</th>
<th bgcolor="yellow">Expenses</th>
</tr>
<tr>
<td>Ben</td>
<td>2500.00</td>
</tr>
<tr>
<td>Ron</td>
<td>1400.00</td>
</tr>
</table>
<!--Driver Code Starts-->
</body>
</html>
<!--Driver Code Ends-->
Example 2: Using rgb number
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>
<head>
<title>
HTML th bgcolor Attribute
</title>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>HTML th bgcolor Attribute</h2>
<!--Driver Code Ends-->
<table width="500" border="1">
<tr>
<!-- Using Hex Number -->
<th bgcolor="#00FF00">Name</th>
<!-- Using RGB Number -->
<th bgcolor="rgba(255, 255, 0)">Expenses</th>
</tr>
<tr>
<td>Ben</td>
<td>2500.00</td>
</tr>
<tr>
<td>Ron</td>
<td>1400.00</td>
</tr>
</table>
<!--Driver Code Starts-->
</body>
</html>
<!--Driver Code Ends-->