CodeBlanks Logo Icon CodeBlanks

Table sections

HTML course · Beginner · Lesson 43/68

Split a table into logical sections with <thead>, <tbody> and <tfoot>.

Splitting a table into sections

Splitting long tables into logical sections improves readability and accessibility. HTML offers three tags for this:

  • <thead> — table head (usually the <th> row)
  • <tbody> — the main data rows
  • <tfoot> — table foot (totals, summaries)

These three tags are written inside <table> to group rows.

Order of the sections

The recommended order is: first <thead>, then <tbody>, last <tfoot>. In older versions <tfoot> was written before <tbody>; today writing it last is preferred.

Not every table needs all three. Using only <tbody> is fine. But when a header or total exists, putting them in <thead> and <tfoot> is the right approach.

Exercise Write a sectioned table

Add a <table> to body. It should contain <thead>, <tbody> and <tfoot> sections in order. Each section must hold at least one <tr> row. Example: thead with Item / Qty, tbody with Flour / 3, tfoot with Total / 3.

Show example solution
<body>
  <table>
    <thead>
      <tr><th scope="col">Item</th><th scope="col">Qty</th></tr>
    </thead>
    <tbody>
      <tr><td>Flour</td><td>3</td></tr>
    </tbody>
    <tfoot>
      <tr><td>Total</td><td>3</td></tr>
    </tfoot>
  </table>
</body>

Test yourself

  1. Close the tbody

    <table>
      <thead>
        <tr><th>Day</th></tr>
      </thead>
      <tbody>
        <tr><td>Monday</td></tr>____
    </table>
    Show answer
    <table>
      <thead>
        <tr><th>Day</th></tr>
      </thead>
      <tbody>
        <tr><td>Monday</td></tr></tbody>
    </table>
  2. Where does a 'Total' row at the bottom of a table belong?

    • <thead>
    • <tbody>
    • <caption>
    • <tfoot>
    Show answer

    <tfoot> — Correct. Summary and total rows go inside <tfoot>.

  3. Match each section to its role

    <thead>
    Header row section
    <tbody>
    Main data rows
    <tfoot>
    Summary and totals
    <caption>
    Text describing the table

All lessons in Beginner