🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEhtml

html Documentation

LOADING ENGINE...

<th>

AI & DATA SCIENCE // th-tag

The <th> element represents a header cell in a table — labeling the row or column it belongs to — rendered bold and centered by default.

Syntax

<tr>
  <th scope="col">Name</th>
  <th scope="col">Age</th>
</tr>

Deep Dive Course

**`<th>`** marks a cell as a header rather than plain data, which browsers style as bold and centered by default, and — more importantly — which screen readers use to announce column/row context for every related data cell. The **`scope`** attribute clarifies exactly what the header applies to: `scope="col"` for a column header, `scope="row"` for a row header, helping assistive technology correctly associate each `<td>` with its header when reading the table cell-by-cell.

1Understanding <th>

`<th>` marks a cell as a header rather than plain data, which browsers style as bold and centered by default, and — more importantly — which screen readers use to announce column/row context for every related data cell. The `scope` attribute clarifies exactly what the header applies to: scope="col" for a column header, scope="row" for a row header, helping assistive technology correctly associate each <td> with its header when reading the table cell-by-cell.

💡

Without scope (or a matching headers/id setup for complex tables), screen readers have to guess which header applies to a given cell based on position alone — explicit scope removes that ambiguity, especially for irregular tables.

editor.html
<table>
  <tr>
    <th scope="col">Country</th>
    <th scope="col">Capital</th>
  </tr>
  <tr>
    <td>France</td>
    <td>Paris</td>
  </tr>
</table>
localhost:3000

2Practical Example

Here is a real-world application of <th> showing how it is used in production HTML.

editor.html
<!-- Row headers for a table where each row represents an entity -->
<tr>
  <th scope="row">Total</th>
  <td>$1,250</td>
</tr>
localhost:3000

3Best Practices

Follow these guidelines when working with <th>:

1. Use <th> for every header cell — column headers and, where relevant, row headers

2. Set scope="col" or scope="row" explicitly for accessibility

3. Reserve <th> for genuine headers — don't use it just to make a data cell look bold, use CSS for that instead

⚠️

Tip: Without scope (or a matching headers/id setup for complex tables), screen readers have to guess which header applies to a given cell based on position alone — explicit scope removes that ambiguity, especially for irregular tables.

editor.html
<table>
  <tr>
    <th scope="col">Country</th>
    <th scope="col">Capital</th>
  </tr>
  <tr>
    <td>France</td>
    <td>Paris</td>
  </tr>
</table>
localhost:3000

Examples

Example 01Basic Usage
<table>
  <tr>
    <th scope="col">Country</th>
    <th scope="col">Capital</th>
  </tr>
  <tr>
    <td>France</td>
    <td>Paris</td>
  </tr>
</table>
Example 02Advanced Example
<!-- Row headers for a table where each row represents an entity -->
<tr>
  <th scope="row">Total</th>
  <td>$1,250</td>
</tr>

Best Practices

  • Use for every header cell — column headers and, where relevant, row headers
  • Set scope="col" or scope="row" explicitly for accessibility
  • Reserve for genuine headers — don't use it just to make a data cell look bold, use CSS for that instead

Interview Question

What problem does the scope attribute on <th> solve for screen reader users?

Hint: Think about a data cell deep in a large table — how does a screen reader know which header(s) it belongs to?

In a large table, when a screen reader user tabs or arrows to a specific data cell, scope tells the assistive technology exactly which header(s) describe that cell — scope="col" means 'this header applies to every cell below it in this column', scope="row" means 'this header applies to every cell to its right in this row'. Without it, screen readers must infer the relationship purely from table position, which becomes unreliable in tables with merged cells or unusual structure.

Exercises

EasyPractice using <th> in a real scenario.
View Solution
<table>
  <tr>
    <th scope="col">Country</th>
    <th scope="col">Capital</th>
  </tr>
  <tr>
    <td>France</td>
    <td>Paris</td>
  </tr>
</table>

Frequently Asked Questions

What problem does the scope attribute on <th> solve for screen reader users?

In a large table, when a screen reader user tabs or arrows to a specific data cell, scope tells the assistive technology exactly which header(s) describe that cell — scope="col" means 'this header applies to every cell below it in this column', scope="row" means 'this header applies to every cell to its right in this row'. Without it, screen readers must infer the relationship purely from table position, which becomes unreliable in tables with merged cells or unusual structure.

Related Functions

table-tagtr-tagtd-tag