Categories
HTML Tutorials

Adding Headers Cells

The th element denotes a header cell, allowing us to differentiate between data and the descriptions of that data. You can see how we added th elements to the table to provide some context for the data values contained in the td elements.

<html>
  <head>
    <title>Example</title>
  </head>
  <body>
    <table>
      <tr>
        <th>Rank</th>
        <th>Name</th>
        <th>Color</th>
        <th>Size</th>
      </tr>
      <tr>
        <th>Favorite:</th>
        <td>Apples</td>
        <td>Green</td>
        <td>Medium</td>
      </tr>
      <tr>
        <th>2nd Favorite:</th>
        <td>Oranges</td>
        <td>Orange</td>
        <td>Large</td>
      </tr>
      <tr>
        <th>3rd Favorite:</th>
        <td>Pomegranate</td>
        <td>A kind of greeny-red</td>
        <td>Varies from medium to large</td>
      </tr>
    </table>
  </body>
</html>
RankNameColorSize
Favorite:ApplesGreenMedium
2nd Favorite:OrangesOrangeLarge
3rd Favorite:PomegranateA kind of greeny-redVaries from medium to large

You can see that we are able to mix the th and td elements together in a row and also create a row that just contains th elements.