**`<col>`** is a void element used inside `<colgroup>` to apply styling to a whole column at once (background color, width) without repeating a class on every single `<td>` in that column. The **`span`** attribute lets one `<col>` apply to several consecutive columns instead of writing one `<col>` per column. Only a limited set of CSS properties (mainly background and width/visibility-related ones) actually apply through `<col>` — most styling still needs to go directly on cells.
1Understanding <col>
`<col>` is a void element used inside <colgroup> to apply styling to a whole column at once (background color, width) without repeating a class on every single <td> in that column. The `span` attribute lets one <col> apply to several consecutive columns instead of writing one <col> per column. Only a limited set of CSS properties (mainly background and width/visibility-related ones) actually apply through <col> — most styling still needs to go directly on cells.
Because only a narrow set of CSS properties work through <col> (mostly background-color and width), for anything beyond that, you'll still need :nth-child(n) selectors targeting the actual <td> cells in that column.
<table>
<colgroup>
<col style="background-color: #eef;">
<col>
</colgroup>
<tr><td>Highlighted column</td><td>Normal column</td></tr>
</table>2Practical Example
Here is a real-world application of <col> showing how it is used in production HTML.
<!-- One col spanning multiple columns -->
<colgroup>
<col span="3" style="width: 100px;">
</colgroup>3Best Practices
Follow these guidelines when working with <col>:
1. Use <col>/<colgroup> to set a background color or width for an entire column efficiently
2. Use the span attribute to cover multiple identical columns with one <col>
3. Fall back to :nth-child CSS selectors on cells for styling properties <col> doesn't support
Tip: Because only a narrow set of CSS properties work through <col> (mostly background-color and width), for anything beyond that, you'll still need :nth-child(n) selectors targeting the actual <td> cells in that column.
<table>
<colgroup>
<col style="background-color: #eef;">
<col>
</colgroup>
<tr><td>Highlighted column</td><td>Normal column</td></tr>
</table>