HTML <thead> Tag

The <thead> tag contains the row(s) that make up the header of the table. The header contains one or more rows at the top of the table.

HTML Tag

Example

#

A styled <thead> tag.

First Name Last Name
Denice Hobermann
Paulo Cornell
Jane Hollander
<style>
  table.tb { width: 300px; border-collapse: collapse; }
  .tb th, .tb td { border: solid 1px #777; padding: 5px; }
  .tb thead { background-color:lightblue; }
</style>

<table class="tb">
  <thead>
    <tr>
      <th>First Name</th>
      <th>Last Name</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Denice</td>
      <td>Hobermann</td>
    </tr>
    <tr>
      <td>Paulo</td>
      <td>Cornell</td>
    </tr>
    <tr>
      <td>Jane</td>
      <td>Hollander</td>
    </tr>
  </tbody>
</table>
thead = table header
tbody = table body
tfoot = table footer

Using <thead>

Tables can be partitioned in 3 logical parts: <thead>, <tbody> and <tfoot>.

The <thead> tag creates a table header at the beginning of a table.

<thead> is used to style all header rows and columns as a group.

More Examples

A <thead> element that styles the header row.

First name Last name Email City Country
Tim Hallman thall@aa.com Dallas USA
Jelle van Loenen jelle@loenen.org Arnhem Netherlands
Jose Lopez lopez@argtech.ph Manila Philippines
Jeroen Harmsma jharm@gmail.com The Hague Netherlands
Sunil Gupta sunil@traf.in Mumbai India
Henry Wong henry@google.com San Francisco USA
Cindy Velasquez cindy@alicante.mx Mexico City Mexico
This table has 7 data rows
<style>
 table.tbl { width:100%; border-collapse: collapse; }
 .tbl th, .tbl td { padding:3px; border: 1px solid #999; }
  .tbl thead { background-color: #3630a3; color: white; }
</style>

<table class="tbl">

 <thead>
  <tr>
    <th>First name</th>
    <th>Last name</th>
    <th>Email</th>
    <th>City</th>
    <th>Country</th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>Tim</td>
    <td>Hallman</td>
    <td>thall@aa.com</td>
    <td>Dallas</td>
    <td>USA</td>
  </tr>
  <tr>
    <td>Jelle</td>
    <td>van Loenen</td>
    <td>jelle@loenen.org</td>
    <td>Arnhem</td>
    <td>Netherlands</td>
  </tr> <tr>
    <td>Jose</td>
    <td>Lopez</td>
    <td>lopez@argtech.ph</td>
    <td>Manila</td>
    <td>Philippines</td>
  </tr>
  <tr>
    <td>Jeroen</td>
    <td>Harmsma</td>
    <td>jharm@gmail.com</td>
    <td>The Hague</td>
    <td>Netherlands</td>
  </tr>
  <tr>
    <td>Sunil</td>
    <td>Gupta</td>
    <td>sunil@traf.in</td>
    <td>Mumbai</td>
    <td>India</td>
  </tr>
  <tr>
    <td>Henry</td>
    <td>Wong</td>
    <td>henry@google.com</td>
    <td>San Francisco</td>
    <td>USA</td>
  </tr>
  <tr>
    <td>Cindy</td>
    <td>Velasquez</td>
    <td>cindy@alicante.mx</td>
    <td>Mexico City</td>
    <td>Mexico</td>
  </tr>
 </tbody>

 <tfoot>
  <tr>
   <td colspan="5">This table has 7 data rows</td>
  </tr>
 </tfoot>

</table>

Attributes for <thead>

The <thead> element has no attributes, but it does accept global attributes.
The following are commonly used.

Attribute Value Description
id    identifier Defines a unique identifier for the thead element.
class    classnames Sets one or more CSS classes to be applied to the thead element.
style    CSS-styles Sets the style for the thead element.
data-*    value Defines additional data that can be used by JavaScript.
hidden    hidden Specifies whether the thead element is hidden.

For additional global attributes see our global attributes list.


Obsolete Attributes

Do not use the attributes listed below.  They are no longer valid on thead in HTML5.

Attribute Description Alternative
align Aligns the content in the thead element. CSS text-align
bgcolor Defines the background color for the thead element. CSS background-color
char Aligns content to a character, for example "," or ".". CSS text-align
charoff Shifts column data to the right relative to char attribute. CSS text-align
valign Sets the vertical alignment of content in the thead element. CSS vertical-align

Table Tags

The <thead> tag is part of a group of tags that are used to create HTML tables. This group is referred to as the Table tag group. Together, these tags allow you to create comprehensive HTML tables.

Here is a list of table tags

Element Description
<table> Creates a table that contains elements listed below
<caption> Creates a caption above or under a table
<colgroup> Creates a container for col elements
<col> Creates a style for one or more columns in a table
<thead> Creates a table header that can style all header cells
<tbody> Creates a table body that can style all data cells
<tfoot> Creates table footer that can style all footer cells
<tr> Creates a table row that contains table cells
<th> Creates a table header cell
<td> Creates a table data cell

Browser support

Here is when <thead> support started for each browser:

Chrome
1.0 Sep 2008
Firefox
1.0 Sep 2002
IE/Edge
1.0 Aug 1995
Opera
1.0 Jan 2006
Safari
1.0 Jan 2003

You may also like

Guides