HTML <col> bgcolor Attribute
The HTML <col> element bgcolor attribute was used in HTML to set background colors for table columns. It is deprecated in HTML 4.01 and not supported in HTML5. Instead, CSS should be used to style table columns with the background-color property.
Syntax:
<col bgcolor= "color_name | hex_number | rgb_number">
Attribute Values:
Attribute name | Description | Example |
---|---|---|
color_name | Sets the text color by using the color name. | “red” |
hex_number | Sets the text color by using the color hex code. | “#0000ff” |
rgb_number | Sets the text color by using the RGB code. | “RGB(0, 153, 0)” |
Example: In this example we showcases a table with three columns, where the first two share a green background, and the third has a blue background. It lists names, branches, and expenses for each entry.
<!DOCTYPE html>
<html>
<head>
<title>
HTML col bgcolor Attribute
</title>
</head>
<body>
<h2>HTML col bgcolor Attribute</h2>
<table border="1">
<colgroup>
<col span="2" bgcolor="green">
<col bgcolor="blue">
</colgroup>
<tr>
<th>Name</th>
<th>Branch</th>
<th>Expenses</th>
</tr>
<tr>
<td>BITTU</td>
<td>CSE</td>
<td>2500.00</td>
</tr>
<tr>
<td>RAKESH</td>
<td>ECE</td>
<td>1400.00</td>
</tr>
</table>
</body>
</html>
Output:
Example: In this example we defines a table with three columns, each with a different background color. The table contains two rows of data.
<!DOCTYPE html>
<html>
<head>
<title>Table Column Background Color</title>
</head>
<body>
<table border="1">
<colgroup>
<col bgcolor="lightblue">
<col bgcolor="lightgreen">
<col bgcolor="lightyellow">
</colgroup>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr>
<td>Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
<td>Row 1, Cell 3</td>
</tr>
<tr>
<td>Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
<td>Row 2, Cell 3</td>
</tr>
</table>
</body>
</html>
Output:
Supported Browsers: