Add Headers Cells with th element

Description

The th element marks a header cell, allowing us to differentiate between data and its descriptions.

th element's parent is tr element. It has local Attributes:colspan, rowspan, scope, headers.

The abbr, axis, align, width, char, charoff, valign, bgcolor, height, and nowrap attributes are obsolete, and you must use CSS instead.

Example

The following code adds header cells to a table.


<!DOCTYPE HTML>
<html>
<body>
  <table>
    <tr>
      <th>Rank</th>
      <th>Name</th>
      <th>Color</th>
      <th>Size</th>
    </tr><!--from   ww  w .  j a v a2  s.  c  o m-->
    <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>

Click to view the demo

The th and td elements are mixed together in a row. It adds vertical header and row header to the table.





















Home »
  HTML CSS »
    HTML »




HTML Introduction
HTML Document
HTML Section
HTML Group Content
HTML Text Marker
HTML Table
HTML Form
HTML Embed