Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

th — table header cell

The th element represents a table header cell, whereas td represents a data cell. The scope attribute identifies which cells a header applies to.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

<th scope="col">Column label</th>
<th scope="row">Row label</th>

th represents a table header cell; td represents a data cell. Place th directly inside tr. A header can describe a column or a row, so it is not restricted to thead.

scope="col" identifies a column header, and scope="row" identifies a row header. rowgroup and colgroup apply to the respective groups and require the cell to be anchored in such a group. Missing or invalid scope selects the Auto state: associations follow the context.

For complex tables, headers explicitly references space-separated identifiers of th cells in the same table. abbr supplies an alternative header label. colspan and rowspan extend a cell across columns or rows but must not cause cells to overlap.

th allows flow content, but no descendant header, footer, sectioning content, or heading content. In the example, Name and Score describe columns, Ada describes the row, and 8 is data. These relationships are semantic, not merely visual.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Table headers</title>
<table>
  <caption>Scores</caption>
  <thead>
    <tr><th scope="col">Name</th><th scope="col">Score</th></tr>
  </thead>
  <tbody>
    <tr><th scope="row">Ada</th><td>8</td></tr>
  </tbody>
</table>
</html>

Result

Scores
Name Score
Ada 8

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources