HTML Reference ยท Tables
The <col> element
Reference for the HTML <col> element: representing one or more table columns, the span attribute, which CSS properties work on columns, and technical details.
The <col> element stands for one column of a table, or several neighboring columns when you give it a span attribute. It holds no content. Its job is to let you style or describe a whole vertical slice of the table without touching every cell in it.
<col> is a void element (it has no end tag) and lives inside a <colgroup>, which in turn sits near the top of the <table>.
<colgroup> <col> <col span="2" class="totals"> </colgroup>
Try it
The first <col> sets a width for the branch names, the second covers five weekday columns without styling them, and the third tints both weekend columns.
Attributes
| Attribute | Values | Description |
|---|---|---|
span |
A positive integer (1โ1000) | The number of consecutive columns this element represents. Defaults to 1. |
It also accepts the global attributes. The old align, valign, width, char and charoff attributes are obsolete; use CSS on the <col> (for width) or on the cells instead.
Usage notes
- Only four CSS properties apply. Cells don't inherit from columns, because they are not children of
<col>. Browsers apply onlybackground,border(whenborder-collapse: collapseis set),widthandvisibility: collapseto columns. Properties such ascolor,text-alignorpaddinghave no effect. - Columns count from the start. Each
<col>takes the next column (orspancolumns) from the left in left-to-right text. Cells withcolspancount as several columns. - Must be inside a colgroup. In the source you may write
<col>directly in the table, but the parser wraps it in an implied<colgroup>. That group must not have its ownspanattribute. - Style a single column's cells? For text color or alignment in one column, use a CSS selector such as
td:nth-child(3)instead.
Technical summary
| Content categories | None |
| Permitted content | Nothing; it is a void element |
| Tag omission | Must have a start tag and must not have an end tag |
| Permitted parents | A <colgroup> element that has no span attribute |
| Implicit ARIA role | No corresponding role |
| DOM interface | HTMLTableColElement |
| Default display | table-column |
Browser support
Supported in every browser.
Related
<colgroup>โ groups<col>elements<table>โ the table itself<td>โ the cells that make up the column- Lesson: Column Groups
- Lesson: Styling Tables with CSS