HTML <col>
Tag
The <col>
tag in HTML is used to define a column within a <table>
element. It allows you to set specific attributes for individual columns in a table, such as width, alignment, and background color. This can be useful for formatting tables and making them more visually appealing.
How to Use the <col>
Tag
To use the <col>
tag, you need to include it within a <colgroup>
element inside the <table>
element. Each <col>
tag specifies the attributes for a single column in the table. Here is an example:
<table>
<colgroup>
<col span="1" style="background-color: lightblue;">
<col span="1" style="background-color: lightgreen;">
</colgroup>
<tr>
<td>Column 1</td>
<td>Column 2</td>
</tr>
</table>
In this example, we have defined two columns with different background colors using the style
attribute inside the <col>
tags.
Main Attributes of the <col>
Tag
Attribute | Description |
span |
Specifies the number of columns the <col> tag should apply to. Default is 1. |
style |
Specifies the CSS styles for the column, such as background color, width, and text alignment. |
By using the <col>
tag effectively, you can customize the appearance of your tables and improve the readability of your data.