thead HTML Tag - Table Header

The thead HTML tag sets the header of an HTML table. The table header is marked by the opening <thead> and closing </thead> tags. The table header contains one or more th cells.

Syntax

<table>
  <thead>
    <tr>
      <th>Name</th>
      <th>Salary</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>John</td>
      <td>$99</td>
    </tr>
  </tbody>
</table>
Name Salary
John $99

Use Of Thead

  1. Table headers don't render differently from table body and footer by default. It can be styled differently with CSS.
  2. Browsers can use sticky thead and tfoot elements to enabling scrolling of a high table body independently.
  3. When printing large tables spanning multiple pages the header and footer can be printed on each page.
<table>
  <thead class="blue">
    <tr>
      <th>Product</th><th>Price</th>
    </tr>
  </thead>
  <tbody class="green">
    <tr>
      <td>Rubik's Cube</td><td>$9</td>
    </tr>
    <tr>
      <td>Pyraminx</td><td>$7</td>
    </tr>
  </tbody>
  <tfoot class="black">
    <tr>
      <td>Sum</td><td>$16</td>
    </tr>
  </tfoot>
</table>
ProductPrice
Rubik's Cube$9
Pyraminx$7
Sum$16

Default CSS Styles

By default, most web browsers show the header with bold text, aligned to the center of the cell. The rest of the table shows with normal font, aligned to the left.

default thead styles
The table above, rendered in Google Chrome without any CSS styles.

thead {
   display: table-header-group;
   vertical-align: middle;
   border-color: inherit;
}

Tag Attributes

The following attributes are obsolete in HTML5 and you should use CSS styles instead. Make sure to update the markup, when copying content from an outdated website.

Multiple Table Header Rows

HTML markup allows to add multiple header lines to our tables, and even to set colspan and rowspan to the cells.

<table>
  <thead>
    <tr>
      <th colspan="2">Head1</th>
    </tr>
    <tr>
      <th>Head2</th>
      <th rowspan="2">Head4</th>
    </tr>
    <tr>
      <th>Head3</th>
    </tr>
  </thead>
  <tbody>
    <tr><td>A</td><td>B</td></tr>
    <tr><td>C</td><td>D</td></tr>
  </tbody>
  <tfoot>
    <tr>
      <td>Foot1</td>
      <td>Foot2</td>
    </tr>
  </tfoot>
</table>
Head1
Head2 Head4
Head3
AB
CD
Foot1 Foot2

Row-, and colspans used in the header.
<table>
  <thead>
    <tr>
      <th>A</th>
      <th>B</th>
      <th>C</th>
    </tr>
    <tr>
      <th>D</th>
      <th>E</th>
      <th>F</th>
    </tr>
    <tr>
      <th>G</th>
      <th>H</th>
      <th>I</th>
    </tr>
  </thead>
</table>
A B C
D E F
G H I

An entire table, made of 3 header rows, without tbody and tfoot.
It's valid code.

Table Header In DIV Tables

Div tables are structured <div> elements that render as tables. We can assign a class name to the first row of the table and style it with CSS styles.

<div class="divTable">
  <div class="divTableHeading">
    <div class="divTableRow">
      <div class="divTableHead">Head 1</div>
      <div class="divTableHead">Head 2</div>
    </div>
  </div>
  <div class="divTableBody">
    <div class="divTableRow">
      <div class="divTableCell">Cell 1</div>
      <div class="divTableCell">Cell 2</div>
    </div>
    <div class="divTableRow">
      <div class="divTableCell">Cell 3</div>
      <div class="divTableCell">Cell 4</div>
    </div>
  </div>
</div>
Head 1
Head 2
Cell 1
Cell 2
Cell 3
Cell 4
.divTableHeading {
   background-color: #EEE;
   display: table-header-group;
   font-weight: bold;
}
.divTableHead {
   background-color: rgba(0,0,0,0.1);
   font-weight: bold;
}

HTML Table Generator With Header

Generate HTML tables easily, with just a couple of clicks below. Make sure to activate the Header checkbox to add a header to the generated code.

2 × 2

Table

Style Name
Georgia
Georgia
Palatino
Times New Roman
Arial
Arial Black
Comic Sans
Impact
Lucida Sans
Tahoma
Trebuchet
Verdana
Courier
Lucida Console
Left Center Right
px
px

Body

Left Center Right

HTML
Preview Apply »
HTML Copy
CSS « Apply