Back to HTML Notes
Topic #143

thead

Learn how to use the <thead> element to semantically group header rows in an HTML table, improving accessibility and enabling better styling control.

What it is

The <thead> element defines a semantic section for the header rows of a table. It groups one or more <tr> elements that contain column headers (typically using <th>). This separation allows browsers and assistive technologies to distinguish between header content and body content (<tbody>) or footer content (<tfoot>).

Mental Model: Think of a table as having three distinct zones: the top (headers), the middle (data), and optionally the bottom (summary/footer). <thead> explicitly marks the top zone.

Related terms: <tbody>, <tfoot>, <th>, scope attribute.

Why it matters

  • Accessibility: Screen readers can announce header cells when navigating data cells if the structure is clear.
  • Styling Control: You can apply CSS specifically to headers without affecting body rows (e.g., bold text, background color).
  • Print Behavior: Browsers often repeat <thead> content on each printed page if the table spans multiple pages.
  • JavaScript Manipulation: Easier to target header sections for dynamic updates or sorting logic.

Syntax or steps

  1. Open a <table>.
  2. Add a <thead> element immediately after the opening <table> tag.
  3. Inside <thead>, place one or more <tr> elements.
  4. Use <th> tags within those rows to define column labels.
  5. Follow with <tbody> for the main data.

Example

<table>
  <thead>
    <tr>
      <th scope="col">Name</th>
      <th scope="col">Role</th>
      <th scope="col">Status</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Alice</td>
      <td>Developer</td>
      <td>Active</td>
    </tr>
    <tr>
      <td>Bob</td>
      <td>Designer</td>
      <td>Inactive</td>
    </tr>
  </tbody>
</table>

Explanation: The <thead> block contains a single row with three <th> elements. The scope="col" attribute helps screen readers associate these headers with the columns below them. The actual data resides in <tbody>, keeping the structure clean and logical.

Common mistakes

  • Missing <tbody>: While optional, omitting <tbody> can make styling complex tables harder. Always pair <thead> with <tbody> for clarity.
  • Using <td> in headers: Header cells should use <th>, not <td>, to ensure proper semantics and default bold styling.
  • Nesting incorrectly: <thead> must be a direct child of <table>. Do not place it inside <tbody>.
  • Forgetting scope: Without scope attributes on <th>, some assistive technologies may struggle to map headers to data cells.

When to use it

Scenario Recommended Approach
Simple 2x2 table <thead> is optional but good practice.
Complex data grid Required for accessibility and print styles.
Dynamic JS tables Use <thead> to separate static headers from dynamic body content.

Practice

Guided Exercise: Create a table listing three books with columns for Title, Author, and Year. Wrap the header row in <thead> and the data rows in <tbody>.

Challenge: Add CSS to make all text inside <thead> uppercase and bold. Hint: Use the selector thead th { text-transform: uppercase; }.

Quick check

Q: Can you have multiple <thead> elements in one table?

A: No. A table can have only one <thead> element, though it can contain multiple <tr> rows.

Summary

The <thead> element provides essential semantic structure for HTML tables by isolating header information. Using it correctly enhances accessibility, simplifies CSS targeting, and improves print layout behavior.

Want to go beyond the notes?

Join Coding Now Tech Institute's HTML course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

thead – FAQs

Quick answers about learning thead in HTML.

This free note from Coding Now Tech Institute explains thead in HTML — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every HTML topic on Coding Now Tech Institute, including thead, is 100% free with no signup required.
With focused practice, most students grasp thead in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now