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

Accessible Table Headers with scope

Use the scope attribute to associate headers with their data cells.

Accessible Table Headers with scope

You'll learn how to explicitly tell screen readers which table cells are headers for rows or columns, making your data tables accessible to all users.

Why Table Scope Matters

You've already used <th> to mark table headers, but sometimes tables get complex—screen readers need extra help understanding whether a header describes a column, a row, or something else. The scope attribute provides this clarity.

The Core Idea

The scope attribute on a <th> element explicitly states what that header describes:

  • scope="col" – This header describes a column (cells below it)
  • scope="row" – This header describes a row (cells to its right)
  • scope="colgroup" – This header describes a group of columns
  • scope="rowgroup" – This header describes a group of rows

When to Use It

Think of scope as giving directions to someone who can't see your table. Without it, they might not know if "January" is labeling a column of sales data or a row of employees who started that month.

<table>
  <thead>
    <tr>
      <th scope="col">Month</th>
      <th scope="col">Sales</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">January</th>
      <td>$5,000</td>
    </tr>
    <tr>
      <th scope="row">February</th>
      <td>$6,200</td>
    </tr>
  </tbody>
</table>

Notice how column headers use scope="col" and row headers (like month names) use scope="row". This helps screen readers announce "January: $5,000" instead of just reading cell values in isolation.

Key Takeaway: Use the scope attribute on <th> elements to explicitly define whether headers describe columns (col) or rows (row), making tables accessible to screen reader users.