Accessible data table patterns for shadcn
Rules / Tables: 3 rules and 1 guideline
Much of the work in an app happens in tables: orders, tickets, invoices, results. A sighted person reads a value by glancing up at its column and across to its row, sorts by pressing a heading, and opens a record by clicking its row. Each of those has to exist in the code as well, or a keyboard or screen reader user gets a run of loose numbers and controls they cannot reach. shadcn’s Table renders real table, th and td elements, and TanStack Table supplies the sorting state. Neither decides how the header row is built, where the sort control goes, or what a click on a row should do.
Where tables go wrong
- A grid of
divs styled to look like a table, or TanStack headings rendered asTableCell, so no value is tied to its heading. TBL-001 - A header row in one table above a second, scrolling table for the body. TBL-001
- A sortable heading with
onClickon the cell, so it works only with a pointer, and an arrow icon as the only sign of the order. TBL-002 - A row that opens its record on click, with no link inside it. TBL-003
- Row actions that appear only on hover, so a keyboard user tabs onto Close ticket without seeing it. TBL-003
- Two tables on one page that are both announced as “table”, or a title above a table with nothing in code that ties the two. TBL-004, a guideline (our choice)
How the rules fit together
TBL-001 is the base. Values shown in rows and columns under headings are a table in code, and each heading cell is marked as the header of its column or row. shadcn’s TableHead and TableCell already render th and td, so most of the work is elsewhere: keeping the header and the body in one table, giving every header cell text, also over a column of checkboxes, and keeping each value’s label when a narrow layout turns rows into cards.
TBL-002 makes a sortable heading a real control: a button or a link inside the header cell, so the cell stays a header, with the sorted column’s order exposed in code, usually as aria-sort. TBL-003 does the same for actions in a row. Each one is its own link, button or menu item that the keyboard reaches; a click on the row may be a shortcut on top, never the only way; and an action hidden until hover shows whenever it has focus. Both are the table case of KBD-001.
TBL-004, a guideline (our choice), gives every data table a visible title that says what its rows have in common, tied to the table as its caption or with aria-labelledby. The same title can name the table’s own scroll area, which LAY-001 asks for when a wide table scrolls by itself. A heading above the table follows STR-002a in the page structure patterns.
When a table has no rows, the loading and empty state patterns say what goes in its place: a wait while it loads, a first step when it is empty, a way back when a filter matched nothing. A checkbox on each row is named as FRM-010 says, and the buttons in a row follow the button patterns.
What WCAG requires and what the judges decide
Three rules here come from WCAG 2.2. Headers in code follow from 1.3.1 Info and Relationships. Sort controls follow from 2.1.1 Keyboard, 4.1.2 Name, Role, Value and 1.3.1. Row actions follow from 2.1.1, 4.1.2 and 2.4.7 Focus Visible. For these the law decides; both judges who spoke supported the first two, and the one who spoke supported the third.
No criterion asks that a table has a title, and only one judge has spoken on it, so TBL-004 is a guideline: our choice, with our reasons on its page. Where a title is there, 1.3.1 still asks that it is marked in code as what it looks like, such as a heading or a caption.
Rules and guidelines
Each one has its own page with the full rule, Do and Don't cases, exceptions and the verdict. A rule is decided by WCAG 2.2 or by the judges. A guideline is our own choice. How the method works
Required by WCAG 2.2
A WCAG 2.2 Level AA criterion requires the behaviour. Where a rule adds advice of its own, it says so.
TBL-001Build data in rows and columns as a table in code, with its headings marked as headersWhen values are shown in rows and columns under headings, build them as a table in code. Mark each heading cell as the header of its column or row, so assistive technology can tell which headings every value belongs to.TBL-002Put a keyboard sort control in a sortable header, and expose its order in codeWhen a column's header sorts the table, make the sort a button or link inside the header cell that works from the keyboard. Expose the sorted column's order in code, ascending or descending, so the direction is never shown by an arrow icon alone.TBL-003Give every row action its own control the keyboard reaches, and show hidden actions on focusGive every action a table row offers its own control the keyboard reaches, such as a link, a button or a menu item. A click on the row may be a shortcut, never the only way. An action hidden until the pointer hovers the row is visible whenever it has focus.
Guidelines, our choice
The judges are split or too few have spoken, so we choose and give our reasons. A product that chooses otherwise is not wrong.
TBL-004Give every data table a visible title and tie it to the table in codeGive every data table a visible title that says what its rows have in common. Tie that title to the table in code, as its caption or through aria-labelledby.
All rules · Is shadcn accessible? · Give the rules to an AI agent
Justified by Blackwood & Blake helps you work toward WCAG 2.2 AA. It is not a certification. Read more
Justified is an independent project. It is not affiliated with, sponsored or endorsed by the organisations whose guidance it cites. Read the full statement.
Apple is a trademark of Apple Inc., registered in the U.S. and other countries and regions.