content logo

Learn HTML:

Html th tag

The HTML <th> tag is used for specifying a header cell (or table header) within a table.

This tag must be nested inside a <tr> tag, which in turn must also be nested correctly. You can find out more by viewing the <table> tag specifications.

Also see the <td> tag for declaring table data.

<table border = "1">
<th>Header cell</th>
<th>Header cell</th>
<td>Cell 1</td>
<td>Cell 2</td>

Element-Specific Attributes

The following table shows the attributes that are specific to this tag/element.

Attribute Description
colspan Specifies the number of columns the current cell spans across.
rowspan Specifies the number of rows the current cell spans across.
headers Specifies a space-separated list of header cells that contain information about this cell. The value needs to correspond with the id of the header cell (which is set using the id attribute). This attribute is useful for non-visual browsers.
scope This attribute is used on header cells and specifies the cells that will use this header's information.

Possible values:

     -  row (current row)

     -  col (current column)

     -  rowgroup (current rowgroup)

     -  colgroup (current column group)

abbr Specifies an alternative label for the header cell. For example, this could be an abbreviated form of the full header cell, an expansion, or different phrasing.
sorted Specifies the sort direction of a table column.

Possible values:

     -  [Empty String]

     -  reversed

     -  [number]

     -  reversed [number]

     -  [number] reversed

Where [number] is any number greater than or equal to 1.

The reversed keyword means that the column sort direction is reversed, rather than normal, which is the default if the keyword is omitted. The number, if present, indicates the column key ordinality; if the number is omitted, the column is the primary key, as if the value 1 had been specified.

A table must not have two <th> elements whose sorted attribute have the same column key ordinality.


HTML Th Example


HTML Th Code


HTML Th Tutorial