<th>

The HTML <th> element creates a header cell in a table, used to label columns or rows with bold, centered text, indicating the title for the corresponding data.

<th> Tag

The <th> element in HTML represents a header cell within a table. It is placed inside a <tr> row and serves as a label for the corresponding columns or rows. By default, browsers render the content inside a <th> tag as bold and centered, though these styles can be modified using CSS.

Syntax

index.html
<th>Header Content</th>

<th> Demo

If you need a table cell to act as a header, use the <th> tag instead of the <td> tag.

ID Name Department
001 John Doe IT
Total Employees: 1
index.html
<table>
  <thead>
    <tr>
      <th>ID</th>
      <th>Name</th>
      <th>Department</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>001</td>
      <td>John Doe</td>
      <td>IT</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <td colspan="3">Total Employees: 1</td>
    </tr>
  </tfoot>
</table>
The <th> tag is used for table headers.

Attributes

  • abbr (HTML5, obsolete): Previously used for a short description of the cell’s content. Instead, use the title attribute for accessibility.
  • align (Deprecated in HTML5): Controlled horizontal alignment of text within the cell:
    • left: Aligns text to the left.
    • center: Centers the content.
    • right: Aligns text to the right.
    • justify: Expands text to fit the cell.
    • char: Aligns text based on a specific character using char and charoff attributes.

Other HTML elements for working with tables:

<caption>
<col>
<colgroup>
<table>
<tbody>
<td>
<tfoot>
<thead>
<tr>.

Conclusion

The <th> tag in HTML defines a header cell in a table, typically used in the <thead> section to label columns or rows. By default, content inside a <th> tag is bold and centered. Deprecated attributes like align should be replaced with CSS for styling, and the abbr attribute is no longer recommended for short descriptions.