HTML Tutorial

HTML Tag: <th>

Purpose:

The <th> tag defines a header cell in a table.

Usage:

  • Use the <th> tag to create a header cell in a table row (<tr>).
  • The contents of a tag can be text, images, or other HTML elements.
  • <th> tags are typically used to differentiate the header cells from the body cells in a table.

Attributes:

  • colspan: Specifies the number of columns the header cell spans.
  • rowspan: Specifies the number of rows the header cell spans.
  • scope: Specifies the scope of the header cell (e.g., "row", "col", or "colgroup").

Examples:

<table>
  <thead>
    <tr>
      <th>Name</th>
      <th>Age</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>John Doe</td>
      <td>30</td>
    </tr>
  </tbody>
</table>

Exploring the <th> Tag:

<!DOCTYPE html>
<html>
<body>
  <table>
    <thead>
      <tr>
        <th>Name</th>
        <th>Age</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>John Doe</td>
        <td>30</td>
      </tr>
      <tr>
        <td>Jane Smith</td>
        <td>25</td>
      </tr>
    </tbody>
  </table>
</body>
</html>

Key Concepts:

  • <th> tags are used to create header cells in tables.
  • <th> tags can be styled using CSS.
  • Header cells can span multiple rows or columns using the colspan and rowspan attributes.