John Doe
- Email:
- john@example.com
- Role:
- Developer
Loading content...
Comprehensive guide to creating accessible tables with semantic HTML and ARIA patterns. Learn multiple implementation approaches for different use cases.
Tables must comply with multiple WCAG 2.2 success criteria to ensure accessibility. Below are the key requirements and how to implement them.
<th> for headersscope or headers attributes<caption> or aria-label to describe table purpose<thead>, <tbody>, and <tfoot> for structure<table>, <thead>, <tbody>, <th>, and <td> elements provide built-in semantics that screen readers understand.scope attribute on <th> elements to indicate whether they are column headers (scope="col") or row headers (scope="row").<caption> or aria-label to describe the table's purpose. The caption should be placed immediately after the opening <table> tag.Testing Guide
| Name | Role | |
|---|---|---|
| John Doe | john@example.com | Developer |
| Jane Smith | jane@example.com | Designer |
| Bob Johnson | bob@example.com | Manager |
| Alice Williams | alice@example.com | Developer |
div elements with ARIA roles. This approach requires careful implementation of role="table", role="row", role="columnheader", role="rowheader", and role="cell". You must also implement keyboard navigation manually using arrow keys, Home, End, and Tab. All cells must be focusable with tabIndex="0" or tabIndex="-1" for programmatic focus. Ensure all relationships are properly communicated via ARIA attributes. This approach is more complex and should only be used when semantic HTML tables are not feasible.Testing Guide
<button> elements inside <th> elements to make columns sortable. The aria-sort attribute indicates the current sort state: none (not sorted), ascending, or descending. Always provide visual indicators (arrows) and ensure the sort state is announced to screen readers via an aria-live region. Include a descriptive aria-label on the button that describes what will happen when clicked, including the current sort state. The status message should be announced immediately after sorting.Testing Guide
| John Doe | john@example.com | Developer |
| Jane Smith | jane@example.com | Designer |
| Bob Johnson | bob@example.com | Manager |
| Alice Williams | alice@example.com | Developer |
role="button" on sortable headers with aria-sort to indicate sort state. Provide descriptive aria-label that describes the sort action and current state. Use aria-live regions with aria-atomic="true" to announce sort changes. Keyboard navigation must be manually implemented for the div-based structure, including arrow key navigation between cells.Testing Guide
<dl>, <dt>, <dd>) and ensure all data is accessible. Use proper heading levels in cards. The card approach is often more usable on small screens and provides better accessibility.Testing Guide
| Name | Role | |
|---|---|---|
| John Doe | john@example.com | Developer |
| Jane Smith | jane@example.com | Designer |
| Bob Johnson | bob@example.com | Manager |
| Alice Williams | alice@example.com | Developer |
scope attribute for simple relationships, but for complex tables with multiple header levels, use the headers attribute on each <td> to explicitly reference its header cells. Each header cell should have a unique id, and data cells reference these IDs in their headers attribute (space-separated for multiple headers). Use scope="colgroup" for column group headers. This ensures screen readers can correctly associate data with all relevant headers, including both row and column headers.Testing Guide
| Region | Quarters | |||
|---|---|---|---|---|
| Q1 | Q2 | Q3 | Q4 | |
| North | $10k | $12k | $15k | $18k |
| South | $8k | $9k | $11k | $13k |
| East | $12k | $14k | $16k | $20k |
Follow these best practices to ensure your tables are fully accessible and provide the best user experience for all users, including those using assistive technologies.