Skip to content
Tutorials Center
My learning

Topics

HTML Reference ยท Tables

The <th> element

Reference for the HTML <th> element: header cells for rows and columns, the scope, abbr, headers, colspan and rowspan attributes, accessibility and technical details.

The <th> element is a header cell. It labels the data cells in its column, its row, or a whole group of rows or columns. Screen readers use these labels to tell users where they are: moving into a cell, they hear something like "Wednesday, Bus 14, 08:20" instead of just "08:20".

Browsers show header cells in bold and centered by default. Like <td>, a <th> lives inside a <tr>.

HTML
<tr>
  <th scope="col">Route</th>
  <th scope="col">First bus</th>
</tr>

Try it

Row and column headers

The top row labels columns (scope="col") and the first cell of each body row labels its row (scope="row"). The abbr values give screen readers a shorter label to repeat in every cell of the long-titled columns.

Attributes

Attribute Values Description
scope row, col, rowgroup, colgroup Which cells this header applies to: the rest of its row, its column, its row group (<tbody> etc.) or its column group. If omitted, the browser guesses from the cell's position.
abbr Text A short alternative label, used by assistive technology when it repeats the header for each cell.
colspan A positive integer (1โ€“1000) The number of columns the cell covers. Defaults to 1.
rowspan A non-negative integer (0โ€“65534) The number of rows the cell covers. 0 stretches it to the end of its row group.
headers Space-separated list of ids The ids of other <th> cells that label this header, for multi-level headings.

It also accepts the global attributes. The obsolete align, valign, width, height, bgcolor, nowrap and axis attributes should be replaced with CSS or, for axis, with scope and headers.

Usage notes

  • Set scope when it isn't obvious. A plain top row of headers usually works without it, but headers in the first column, headers in the middle of a table, and spanned headers should always say what they label.
  • Group headers. A <th scope="rowgroup"> at the start of a <tbody> labels every row in that body. A <th scope="colgroup" colspan="3"> labels a three-column group, usually matching a <colgroup>.
  • Don't fake headers. A <td> styled bold is not a header for assistive technology. Use <th> whenever a cell labels other cells.
  • Content limits. A <th> may contain flow content, but no headings, sectioning elements, <header> or <footer>. Keep header text short.
  • The empty corner. The top-left cell of a two-way table often labels nothing; use an empty <td> there.

Technical summary

Content categories None
Permitted content Flow content, but with no <header>, <footer>, sectioning content or heading content descendants
Tag omission The start tag is required. The end tag can be omitted if the cell is immediately followed by a <td> or <th>, or if there is no more content in the parent element
Permitted parents A <tr> element
Implicit ARIA role columnheader or rowheader, depending on what it labels; cell or gridcell if it labels nothing
DOM interface HTMLTableCellElement
Default display table-cell (bold, centered)

Browser support

Supported in every browser.