HTML table header - how to use <th> tag

The HTML <th> tag is used to define header cells for a table. A standard cell can be created using <td> tag.

Text is left aligned by default for <td> tag and center aligned and bold for <th> tag.

Attributes

The th tag supports the global and event attributes.

abbr
Defines an abbreviation for the header cell
colspan
Defines the number of columns a table cell should span
headers
Defines the header cells this cell related to
rowspan
Defines the number of rows a table cell should span
scope
Defines whether the header cell is for the column, group of columns, row or group of columns
sorted
Defines the sort direction for the column

Examples:

<table border="1"> <thead> <tr> <th>Country</th> <th>Capital</th> <th>City</th> </tr> </thead> <tbody> <tr> <td>China</td> <td>Beijing</td> <td>Shanghai</td> </tr> <tr> <td>India</td> <td>New Delhi</td> <td>Hyderabad</td> </tr> </tbody> <tfoot> <tr> <td>Table</td> <td>Ends</td> <td>Here</td></tr> </tfoot> </table>

Related HTML tags and Useful Links:

  • <table> - used to define a table
  • <thead> - used to define header of the table
  • <tbody> - used to define the table body
  • <tfoot> - used to define footer of the table
  • <th> - used to define header cells
  • <tr> - used to define table row
  • <td> - used to define the cell of the table
  • <caption> - used to define caption / title of the table
  • <col> - used to define properties of columns defined within the <colgroup> tag
  • <colgroup> - used to group one or more columns
  • Learn more about HTML table