HTML describes which cells are headers and data; it does not sort the rows when someone clicks a header. Sorting requires JavaScript or server-generated ordering. 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
When a sorted table is presented, aria-sort can describe the current sort direction on the relevant header, but the data still needs to be reordered by real behavior.
Example: See It in Action
Take a look at this small piece of HTML. You can use it in a practice document and change the text to make it your own.
This is a short HTML fragment. To try it as a webpage, put it inside the body element of a complete HTML document.
<table>
<caption>Top scores (not sorted by HTML alone)</caption>
<tr>
<th scope="col">Student</th>
<th scope="col">Score</th>
</tr>
<tr>
<th scope="row">Alex</th>
<td>78</td>
</tr>
<tr>
<th scope="row">Maya</th>
<td>92</td>
</tr>
</table>
Let’s Understand the Example
- Table represents information whose row and column relationships matter.
- Caption gives the whole data table a clear name.
- 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 “Top scores (not sorted by HTML alone)”, with headers such as “Student”, “Score”, “Alex”. 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
- Sort the example rows by hand, then label the sort direction appropriately.
- 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
- Adding aria-sort="ascending" while leaving the rows unsorted.
- Do not replace actual header cells with bold ordinary cells. Header markup is part of the meaning, not just the appearance.
Key Takeaways
- HTML describes which cells are headers and data; it does not sort the rows when someone clicks a header.
- Table represents information whose row and column relationships matter.
- When a sorted table is presented, aria-sort can describe the current sort direction on the relevant header, but the data still needs to be reordered by real behavior.