HTML Table Headers
A sized, bordered grid still fails if nobody can tell which label belongs to which values. After table sizes taught you to fit the box, this lesson marks the meaning of labels: use th for header cells, optional scope to say column versus row, and caption when the whole table needs a title. Presentation (borders, width, padding) stays in CSS from earlier lessons. Structure and header meaning stay in HTML. Think of th as a nameplate, not as “bold text by default.”
Why header cells are not just bold td
Browsers may bold th by default, but the real win is semantics. Screen readers and other tools can announce column or row names when cells are real headers. Search and future styling hooks also benefit from honest markup. Painting a td with CSS font-weight: bold can look similar to sighted users and still leave assistive tech guessing. If the Tables lesson introduced th briefly, this session makes headers the main skill: when to use them, how scope helps, and when caption belongs above the grid.
Direct answer
Use th for header labels — top-of-column names, side-of-row names, or both in denser tables. Add scope="col" on column headers and scope="row" on row headers when the relationship should be explicit. Put a short <caption> inside the table when the dataset needs a shared title (“Team scores”, “Weekly inventory”). Keep data values in td. Do not rely on bold styling alone to fake headers. Keep one consistent cell count per row so headers still line up with the values they describe.
Column headers with a caption
Start with the most common pattern: a header row across the top, each label marked th scope="col", plus a caption that names the whole table. Data rows below use td for values. This pattern matches scoreboards, price lists, and class rosters where every column has a clear name.
Column headers and caption
html<table>
<caption>Weekly inventory</caption>
<tr>
<th scope="col">Item</th>
<th scope="col">Qty</th>
<th scope="col">Aisle</th>
</tr>
<tr>
<td>Notebook</td>
<td>12</td>
<td>B2</td>
</tr>
<tr>
<td>USB cable</td>
<td>7</td>
<td>A1</td>
</tr>
</table>
Reading the column-header sample
captiontitles the table for everyone; it belongs insidetable, usually first- Each top label is
thwithscope="col"so tools know the header describes a column - Quantity and aisle stay in
tdbecause they are data, not labels - Three cells in every row keep headers aligned with values
- You can still style borders and width with CSS from prior lessons without changing these tags
- If
captionlooks odd in your browser, check that it is not placed outside thetableelement
Row headers for named records
Some tables read like a list of people or products where the first cell of each data row is a name that labels the rest of that row. Mark those name cells with th scope="row". You can combine a top header row (scope="col") with row headers (scope="row") in the same table. That mixed pattern is common in score sheets and comparison grids.
Row headers with a header row
html<table>
<caption>Team scores</caption>
<tr>
<th scope="col">Name</th>
<th scope="col">Points</th>
<th scope="col">Level</th>
</tr>
<tr>
<th scope="row">Ada</th>
<td>98</td>
<td>A</td>
</tr>
<tr>
<th scope="row">Lin</th>
<td>91</td>
<td>B</td>
</tr>
</table>
Reading the row-header sample
- Top row still uses
th scope="col"for Points and Level (and Name) AdaandLinareth scope="row"because they label their rows- Points and Level remain
tddata cells captionagain names the whole dataset- Mixing col and row scopes is valid; do not mark every cell as
th - If a screen reader confuses a row, check that the name cell is really
thand thatscope="row"is present
Scope map (quick reference)
Use this map when you are unsure which scope value fits. Skip scope only on the simplest practice tables; prefer adding it once your grid has both a header row and row labels.
📊 scope attribute values
| Value | Typical use | Example cell |
|---|---|---|
| col | Header labels a column | Top “Qty” label |
| row | Header labels a row | Side “Ada” name |
| colgroup | Header for a group of columns | Advanced multi-header grids |
| rowgroup | Header for a group of rows | Advanced sectioned tables |
For this beginner course, master col and row first. colgroup and rowgroup appear in denser administrative tables later; you do not need them for weekly inventory demos. When in doubt, ask: “Does this label describe a whole column or a whole row?” Then pick col or row.
Practice in your editor
- Build a three-column table about a small club (name, role, votes).
- Add a
captionthat names the club table. - Mark the top labels with
th scope="col". - Mark each person name with
th scope="row". - Keep roles and votes as
td. - View the page, then temporarily change a name cell back to
tdand notice how the meaning gets weaker even if bold CSS still looks “header-like.” - Restore
th scope="row"and write one sentence under the table explaining whyscopehelps. - Optionally reuse border or width CSS from earlier lessons without changing the header markup.
Easy mistakes
- Styling
tdbold (or bigger) and calling it a header without usingth - Putting
captionoutside thetableor using a plain paragraph above as if it were a caption - Forgetting
scopeon mixed grids that have both a header row and row labels - Marking every cell
th, including pure numeric data - Uneven cell counts so column headers no longer match the values below
- Using
captionalone and leaving all cells astd(a title is not a substitute for header cells) - Copying layout-table habits and stuffing page chrome into
th/tdagain
Summary
thmarks real header cells; styledtdis not enoughscope="col"ties a header to a column;scope="row"ties it to a rowcaptiontitles the whole table for people and tools- Keep data in
tdand keep row lengths consistent - Borders and sizing stay in CSS; header meaning stays in HTML
- Next table lessons can add richer structure on top of honest headers
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 Instructions
- Read each question carefully
- Select the best answer for each question
- You can retake the quiz as many times as you want
- Your progress will be shown at the top