Course contentsShow
← Web Development
Lesson 114 of 2,9822. HTML FundamentalsFree lesson

Grouping with <thead>, <tbody>, <tfoot>

Organize table content into logical header, body, and footer sections.

Grouping with <thead>, <tbody>, <tfoot>

What you'll learn: How to organize table content into logical header, body, and footer sections for better structure and styling.

The Core Idea

Just like a well-organized document has distinct sections (title, main content, conclusion), HTML tables can be divided into three logical groups: <thead> for header rows, <tbody> for data rows, and <tfoot> for summary rows. These elements wrap your <tr> rows to create clear, semantic boundaries.

Think of it like a restaurant menu: The top section shows category headers ("Appetizers," "Main Courses"), the middle contains all the actual menu items with prices, and the bottom might show totals or footnotes. Each section has a different purpose.

How It Works

<table>
  <caption>Monthly Sales Report</caption>
  
  <thead>
    <tr>
      <th>Product</th>
      <th>Units Sold</th>
      <th>Revenue</th>
    </tr>
  </thead>
  
  <tbody>
    <tr>
      <td>Widget A</td>
      <td>150</td>
      <td>$1,500</td>
    </tr>
    <tr>
      <td>Widget B</td>
      <td>200</td>
      <td>$3,000</td>
    </tr>
  </tbody>
  
  <tfoot>
    <tr>
      <th>Total</th>
      <td>350</td>
      <td>$4,500</td>
    </tr>
  </tfoot>
</table>

The browser understands these groups even if you place <tfoot> before <tbody> in your code—it will still render the footer at the bottom! This grouping also makes it easier to style each section differently with CSS later and helps screen readers navigate large tables more efficiently.

Why Group Your Tables?

These semantic sections make your table more accessible, easier to style, and more maintainable. When you eventually add CSS, you can target thead to make headers sticky while scrolling, or give tfoot a different background color.

Key Takeaway: Use <thead>, <tbody>, and <tfoot> to organize table rows into logical sections—headers, data, and summaries—creating clearer, more semantic table structure.