本文へスキップ

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>.

HTML
<colgroup>
  <col>
  <col span="2" class="totals">
</colgroup>

Try it

Styling columns with col

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 only background, border (when border-collapse: collapse is set), width and visibility: collapse to columns. Properties such as color, text-align or padding have no effect.
  • Columns count from the start. Each <col> takes the next column (or span columns) from the left in left-to-right text. Cells with colspan count 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 own span attribute.
  • 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.