Accessible HTML Tables with thead, tbody, and scope
Lesson 15 of 36 in the HTML5 learning path.
How do I associate table headers with their cells?
An HTML table is for a grid of related data, such as quiz scores, where each cell belongs to a row and a column. caption names the table. thead holds the column headers, tbody holds the data rows, and th marks a header cell. scope="col" ties a header to its column. scope="row" ties the student name to the cells in that row. With those associations, a screen reader can speak a quiz column, a student name, and a score instead of a bare number.
Use a table when you truly have tabular data. Do not use one to build a page banner, a form, or a multi-column article. Those are layout jobs for CSS. A score page, a price list, and a schedule are tables. Give them a caption a classmate can read, real headers, and scope on every th so the relationships survive when the CSS that paints borders is removed.
Syntax & Parameters
<table><caption></caption><thead><tr><th scope="col"></th></tr></thead><tbody><tr><th scope="row"></th><td></td></tr></tbody></table>
Example
Interactive preview available<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Section B quiz scores</title>
<style>
body { margin: 0; font: 1.05rem/1.55 Georgia, "Times New Roman", serif; color: #1c1917; background: #faf7f2; }
header { background: #1e3a5f; color: #f8fafc; padding: 1.25rem 1.5rem; }
main { max-width: 42rem; margin: 0 auto; padding: 1.25rem 1.5rem 2rem; }
h1 { font-size: 2rem; line-height: 1.2; margin: 0 0 0.75rem; }
p { margin: 0 0 0.85rem; }
table { border-collapse: collapse; width: 100%; background: #fff; }
caption { caption-side: top; text-align: left; font-weight: 700; margin: 0 0 0.5rem; }
th, td { border: 1px solid #d6d3d1; padding: 0.45rem 0.6rem; text-align: left; }
th { background: #f5f5f4; }
</style>
</head>
<body>
<header>
<p>North Campus, Web Systems 1</p>
</header>
<main>
<h1>Section B quiz scores</h1>
<p>This table is the scores. It is not the layout of the page. Each column header uses scope="col", and each student name is a row header with scope="row".</p>
<table>
<caption>Web Systems 1 quiz scores, section B, November 2026</caption>
<thead>
<tr>
<th scope="col">Student</th>
<th scope="col">Quiz 1</th>
<th scope="col">Quiz 2</th>
<th scope="col">Average</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Amina Cruz</th>
<td>18</td>
<td>20</td>
<td>19</td>
</tr>
<tr>
<th scope="row">Jonah Reyes</th>
<td>16</td>
<td>19</td>
<td>18</td>
</tr>
<tr>
<th scope="row">Liza Santos</th>
<td>20</td>
<td>18</td>
<td>19</td>
</tr>
</tbody>
</table>
</main>
</body>
</html>
Expected Output
The browser shows the heading Section B quiz scores, a sentence that says the table is data, and a grid titled Web Systems 1 quiz scores, section B, November 2026. Column headers are Student, Quiz 1, Quiz 2, and Average. Three rows list Amina Cruz with 18, 20, and 19, Jonah Reyes with 16, 19, and 18, and Liza Santos with 20, 18, and 19. A screen reader can announce the caption, then a cell together with its headers, such as Quiz 2, Amina Cruz, 20. The name cells are row headers. The page around the table is a normal heading and paragraph, not another table used as a layout frame.
Line-by-Line Walkthrough
- The h1 names the page. The table is the scores, not a substitute for the header, main, or footer of the document.
- caption is the first element inside the table and reads Web Systems 1 quiz scores, section B, November 2026. It names the grid.
- thead contains one row of th cells. Each of those headers sets scope="col" so it applies down the column.
- The column headers are Student, Quiz 1, Quiz 2, and Average. They are headers, not ordinary data cells.
- tbody contains one tr per student. The name is a th with scope="row", not a td, because it heads that row.
- The numeric scores are td cells. They inherit their column header from scope="col" and their row header from scope="row".
- Amina Cruz, Jonah Reyes, and Liza Santos are three body rows. None of them repeat the column titles.
- The border CSS only draws lines. Deleting the stylesheet leaves the same caption, headers, and associations.
- The page does not use a table around the heading or the paragraph. Layout stays in normal flow.
Read a data cell with its headers. The 20 in the first body row is Quiz 2 for Amina Cruz. The 16 in the second body row is Quiz 1 for Jonah Reyes. Those pairings come from scope, not from the visual position alone.
Common Pitfalls & Security
Tables get misused in two ways: as layout, which hides the real structure, and as data with headers that are only bold td cells. Bold text is not a header association. scope is.
- A table used for the page banner, the nav, and the footer gives assistive technology a grid instead of landmarks.
- scope="col" on a student name, or scope="row" on Quiz 1, points the header at the wrong set of cells.
- Putting the column titles in td cells means they are data. A screen reader will not treat them as headers.
- An empty th, added to make a corner look square, becomes a header with no name and should be removed or given a real label.
- Repeating the scores in a paragraph and a table is fine. Hiding the only copy of the scores inside an image of a spreadsheet is not, because the table is the accessible version.
Best Practices & Modern Standards
HTML5 tables are for relationships between headers and cells. Write a caption, put column headers in a thead, put records in a tbody, and set scope on every th. Use scope="col" for column titles and scope="row" for the label of each record. Keep the header text short and specific.
Do not reach for a table when you want columns of text. Use landmarks and CSS for that. If the grid is large, keep the same header associations when you add a horizontal scroll style. The scroll is presentation. The scope is the meaning, and it has to be in the HTML.
Real-World Use
The section B score page published after quiz week is this table. Students find their row header, and a screen-reader user in the same section hears the quiz name with the score. The caption records the course, the section, and the month so the grid is not an unlabeled block of numbers.
The registrar export uses the same structure for a price list of lab fees and for a room schedule. None of those pages use a table to position the logo or the navigation. The header and footer stay landmarks, and the table stays the data.
Frequently Asked Questions
When should a cell be th instead of td?
Use th when the cell is a header for other cells. Column titles and the student names in this score table are headers. The numeric scores are td. A th without scope is still a header, but scope makes the direction explicit in a simple grid.
Do I need scope if I use the headers attribute?
For this table, scope is enough and easier to keep correct. The headers attribute is for complex grids where a cell has several headers that scope cannot express. Do not add both in a way that disagrees. Prefer scope until the table actually needs the extra map.
Is a caption the same as an h1?
No, the h1 names the page and the caption names the table, which is announced with it. This page uses both: a heading for the score page and a caption that includes the section and the month. Do not delete the caption because the heading looks similar.
Can I use a table to lay out a form?
No, a form is labels and controls, not a data grid, so use normal flow or CSS for alignment. Reserve table, caption, thead, and scope for data such as these quiz scores. Layout tables break the association model and the landmarks around them.