HTML5 <th> Tag

The HTML <th> element defines a cell as header of a group of table cells. The exact nature of this group is defined by the scope and headers attributes.

The only content permitted inside this element is phrasing content. The start tag is mandatory for this element. The end tag may be omitted, if it is immediately followed by a <th> or <td> element or if there are no more data in its parent element. The parent of the <th> tag can only be a <tr> element.

The following style is applied to this element by default:

th {
  display: table-cell;
  vertical-align: inherit;
}

th {
  font-weight: bold;
  text-align: center;
}

Attributes

colspan

This attribute contains a positive integer value that indicates over how many columns a cell is extended. Its default value is 1. If its value is set to 0, the cell is extended to the last element of the <colgroup>. Values higher than 1000 are clipped down to 1000.

headers

This attribute contains a list of space-separated strings, each corresponding to the id attributes of other <th> elements that relate to this element.

rowspan

This attribute contains a positive integer value that indicates over how many rows a cells is extended. Its default value is 1. If its value is set to 0, the cell is extended to the last element of the table sections (<thead>, <tbody> or <tfoot>). Values higher than 65534 are clipped down to 65534.

scope

This enumerated attribute defines the cells that the header (defined in the <th>) element relates to. It may have the following values:

  • row: The header relates to all cells of the row it belongs to.
  • col: The header relates to all cells of the column it belongs to.
  • rowgroup: The header belongs to a rowgroup and relates to all of its cells. These cells can be placed to the right or the left of the header, depending on the value of the dir attribute in the <table> element.
  • colgroup: The header belongs to a colgroup and relates to all of its cells.

Reader Comments

1. You can register or login to post a comment. Asking readers to register improves the quality of discussion.

2. As a registered user, you will also get to access features like choosing between a light and dark theme or anything else that we might implement in future.

Follow Us For Updates

FacebookTwitterGoogle+
Go To Top