HTML <col> column Tag Reference
The col HTML tag means column, and it is used to apply certain styles to a whole column in a table.
The col HTML tag means column, and it is used to apply certain styles to a whole column in a table.
The column tag is used at the start of a table to define a column, allowing certain styles to be applied to every cell in the column.
The really useful thing about tags is that they let you easily assign the same properties (especially widths) to multiple tables. If you have 2 tables on a page, which contain similar data but in differing amounts, if left to its own devices a web browser will automatically resize columns to make each table as short as possible. What you want is a neat way to make the first column in both tables line up etc. That’s where the <col /> or the multiple column tag <colgroup /> come in. (The colgroup is used to assign the same properties to more than one consecutive column.)
By simply assigning the same columns to each table, you can give each column 1 the same classname, which might fix the width as a set percentage of the table width.
Use <col /> tags only to assign class or style properties to whole columns in HTML tables.
It’s valid in all current versions of HTML and xHTML, and it’s a self-closing tag, so if you are using xHTML you need to remember the trailing forward-slash />
See how the column widths in these 2 tables are different, which doesn’t look tidy.
| Name | Favourite pudding | Golf handicap |
|---|---|---|
| Great Uncle Bulgaria | Crème brulée | 2 |
| Madame Cholet | Apple tart | 5 |
| Tomsk | Chocolate muffin | 14 |
| Name | Favourite pudding | Golf handicap |
|---|---|---|
| Pootle | Rhubarb and custard, with cinnamon | (Doesn’t play golf) |
| Mrs. Flump | Anything with vanilla | 4 |
The easiest way to align the columns is to use <col /> tags.
| Name | Favourite pudding | Golf handicap |
|---|---|---|
| Great Uncle Bulgaria | Crème brulée | 2 |
| Madame Cholet | Apple tart | 5 |
| Tomsk | Chocolate muffin | 14 |
| Name | Favourite pudding | Golf handicap |
|---|---|---|
| Pootle | Rhubarb and custard, with cinnamon | (Doesn’t play golf) |
| Mrs. Flump | Anything with vanilla | 4 |
</style>
<table style=”width:30em;”>
</tr>
</thead>
<tbody>
</tr>
<tr>
</tr>
<tr>
</tr>
</tbody>
</table>
<table style=”width:30em;”>
</tr>
</thead>
<tbody>
</tr>
<tr>
</tr>
</tbody>
</table>
You may also consider using:
Do you love our approach to crafting simple & effective web sites that just work for people?
We'd love to hear about your web strategy.
Contact one of our team today!
<thead>
<th>Favourite pudding</th>
<th>Golf handicap</th>
</tr>
</thead>
<tbody>
<td>Crème brulée</td>
<td>2</td>
</tr>
<tr>
<td>Apple tart</td>
<td>5</td>
</tr>
<tr>
<td>Chocolate muffin</td>
<td>14</td>
</tr>
</tbody>
</table>
<table style=”width:30em;”>
<thead>
<th>Favourite pudding</th>
<th>Golf handicap</th>
</tr>
</thead>
<tbody>
<td>Rhubarb and custard, with cinnamon</td>
<td>(Doesn’t play golf)</td>
</tr>
<tr>
<td>Anything with vanilla</td>
<td>4</td>
</tr>
</tbody>
</table>