Scope helps a th identify the cells it labels. For simple tables, scope="col" marks a column header and scope="row" marks a row header. Before writing the code, picture the information as a small grid. Each label should help a reader understand the value next to it.
What You Need to Know
Use real th elements with headers that describe the data. Complicated spanning tables may need more explicit associations.
Read a table like a story about data. The caption says what you are looking at; row and column headers explain what the numbers or words mean.
Example: See It in Action
Add this example to the appropriate part of a practice HTML page. Read each line before you open the page in your browser.
This is a short HTML fragment. To try it as a webpage, put it inside the body element of a complete HTML document.
<table>
<tr>
<th scope="col">Course</th>
<th scope="col">Points</th>
</tr>
<tr>
<th scope="row">HTML</th>
<td>20</td>
</tr>
<tr>
<th scope="row">CSS</th>
<td>15</td>
</tr>
</table>
Let’s Understand the Example
- Table represents information whose row and column relationships matter.
- Th is a header cell. Its text explains what nearby data cells mean.
- Scope explains which table row, column or group a th cell labels.
Look at a data cell and ask: “What row and column does this value belong to?” The header elements help answer that question, including for people who navigate the table with a screen reader.
What Should You See?
You should see a grid for the data table, with headers such as “Course”, “Points”, “HTML”. The browser displays cells, but meaningful table markup also helps readers connect each cell to its labels.
Read the first data row aloud together with its column labels. If you cannot explain a value without pointing to its position on screen, strengthen the headers.
Try It Yourself
- Add scope values to the missing header cells in the table.
- Save your changes, open or refresh the page, and compare the result with the original example.
- Tell a friend what your change did. If you are not sure, undo it, refresh the page, and compare.
Common Beginner Mistakes
- Writing scope on a td element and expecting it to become a proper header.
- Do not replace actual header cells with bold ordinary cells. Header markup is part of the meaning, not just the appearance.
Key Takeaways
- Scope helps a th identify the cells it labels.
- Table represents information whose row and column relationships matter.
- Use real th elements with headers that describe the data. Complicated spanning tables may need more explicit associations.