Tables show data in rows and columns. Making them accessible helps everyone, including people using screen readers, understand the data clearly.
Table accessibility basics in HTML
<table> <caption>Table title</caption> <thead> <tr> <th scope="col">Column header</th> <th scope="col">Column header</th> </tr> </thead> <tbody> <tr> <th scope="row">Row header</th> <td>Data cell</td> </tr> </tbody> </table>
The <caption> tag gives the table a clear title for screen readers.
Use scope="col" for column headers and scope="row" for row headers to help screen readers understand the table structure.
scope attributes for headers, making it easy to understand.<table> <caption>Monthly Sales</caption> <thead> <tr> <th scope="col">Month</th> <th scope="col">Sales</th> </tr> </thead> <tbody> <tr> <th scope="row">January</th> <td>$1000</td> </tr> <tr> <th scope="row">February</th> <td>$1200</td> </tr> </tbody> </table>
<table> <caption>Team Members</caption> <thead> <tr> <th scope="col">Name</th> <th scope="col">Role</th> </tr> </thead> <tbody> <tr> <th scope="row">Alice</th> <td>Designer</td> </tr> <tr> <th scope="row">Bob</th> <td>Developer</td> </tr> </tbody> </table>
This example shows a simple accessible table with a caption and proper header scopes. It is easy to read visually and by screen readers.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Accessible Table Example</title> <style> body { font-family: Arial, sans-serif; padding: 1rem; line-height: 1.5; } table { border-collapse: collapse; width: 100%; max-width: 600px; margin: 1rem 0; } caption { caption-side: top; font-weight: bold; font-size: 1.25rem; margin-bottom: 0.5rem; } th, td { border: 1px solid #333; padding: 0.5rem 1rem; text-align: left; } th { background-color: #f0f0f0; } </style> </head> <body> <main> <table> <caption>Weekly Schedule</caption> <thead> <tr> <th scope="col">Day</th> <th scope="col">Activity</th> </tr> </thead> <tbody> <tr> <th scope="row">Monday</th> <td>Yoga class</td> </tr> <tr> <th scope="row">Tuesday</th> <td>Grocery shopping</td> </tr> <tr> <th scope="row">Wednesday</th> <td>Work meeting</td> </tr> </tbody> </table> </main> </body> </html>
Always use <caption> to describe the table's purpose.
Use scope attributes on <th> to help screen readers link headers to cells.
Keep tables simple and avoid using tables for layout to improve accessibility.
Tables organize data in rows and columns for easy reading.
Use <caption> and scope attributes to make tables accessible.
Accessible tables help everyone, especially people using screen readers, understand the data clearly.
Practice
<caption> element in an HTML table?Solution
Step 1: Understand the role of
The<caption><caption>element is used to give a title or description to a table, which helps screen readers and users understand the table's content.Step 2: Compare with other options
Options B, C, and D describe other table parts or styling, but only<caption>provides a descriptive title.Final Answer:
To provide a title or description for the table, improving accessibility. -> Option BQuick Check:
<caption>= Table title [OK]
- Confusing <caption> with <tfoot> or <thead>
- Thinking <caption> styles the table
- Ignoring accessibility benefits of <caption>
Solution
Step 1: Identify the correct element for header cells
The<th>element is used for header cells, not<td>.Step 2: Understand the scope attribute
For column headers,scope="col"is correct.<th scope="col">Header</th>uses<th scope="col">, which is the proper syntax.Final Answer:
<th scope="col">Header</th> -> Option DQuick Check:
<th scope="col">= Column header [OK]
- Using <td> instead of <th> for headers
- Mixing scope="row" with column headers
- Omitting the scope attribute
<table>
<caption>User List</caption>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Age</th>
</tr>
</thead>
<tbody>
<tr>
<td>Alice</td>
<td>30</td>
</tr>
</tbody>
</table>Solution
Step 1: Understand scope="col" usage
Thescope="col"attribute on the<th>means the header applies to the entire column below it.Step 2: Identify which cells belong to the "Name" column
The first column cells, such as "Alice", are associated with the "Name" header for screen readers.Final Answer:
The header "Name" is linked to the first column cells like "Alice". -> Option AQuick Check:
scope="col" links header to column cells [OK]
- Confusing row and column scope
- Thinking headers need id attributes to link
- Assuming caption links headers
<table>
<tr>
<td>Product</td>
<td>Price</td>
</tr>
<tr>
<td>Book</td>
<td>$10</td>
</tr>
</table>Solution
Step 1: Check for caption element
The table lacks a<caption>, which helps describe the table for screen readers.Step 2: Check header cell tags and attributes
The first row uses<td>instead of<th>for headers, and noscopeattributes are present.Final Answer:
All of the above. -> Option CQuick Check:
Missing caption, wrong header tags, and no scope = C [OK]
- Using <td> for headers
- Skipping caption element
- Not adding scope attribute to headers
Solution
Step 1: Use
This helps all users understand the table's purpose.<caption>for table descriptionStep 2: Use
Column headers get<th>with proper scope for headersscope="col", row headers getscope="row". This clarifies relationships for screen readers.Final Answer:
Use <caption> for the title, <th scope="col"> for column headers, and <th scope="row"> for row headers. -> Option AQuick Check:
Caption + th with scope col/row = best accessibility [OK]
- Using <td> for headers
- Skipping scope attributes
- Relying only on aria-labels on data cells
Ready to prove it?
Pass the test and this pattern moves unknown
