Table
Rows and columns of data to scan and compare.
When to use
- Rows of records to scan and compare across the same columns: sources, API keys, clinicians.
- Read-only data where each row has the same shape.
When not to use
- Users filter, sort, or select rows to act on them: use Data Table, which adds selection to Table.
- A few items with an image, a description and actions: use Item.
- Page layout or a form: use CSS grid or Field. A table is for data only.
Install
npx shadcn@latest add @clinia/table| ID | Name | Status | Last visit |
|---|---|---|---|
| P-001 | Jane Cooper | Active | Jun 3, 2025 |
| P-002 | Floyd Miles | Inactive | May 20, 2025 |
| P-003 | Ronald Richards | Active | Jun 4, 2025 |
Anatomy
| Source | Records |
|---|---|
| Lab results | 12,480 |
| Imaging | 860 |
| Referrals | 3,112 |
- 1Column header
[data-slot=table-head]:last-childfont-medium · text-foreground - 2Row
[data-slot=table-body] [data-slot=table-row]border-b · data-interactive:hover:bg-foreground/4 - 3Cell
[data-slot=table-body] [data-slot=table-cell]p-3 · text-sm - 4Caption
data-slot="table-caption"text-sm · text-muted-foreground
Clinia rules
- A selected row (
data-state="selected", set by Data Table) is tintedbg-accent/15. The tint is not the only cue: pair it with a checked Checkbox. - Rows don't hover by default. Set
interactiveon a row that opens, selects or links to something: it takes thebg-foreground/4hover tint. Rows of static data, such as a permissions matrix, stay still. - The header and footer sit on
bg-foreground/3, a faint ink tint that follows the theme. - Right-align numbers and set them in
tabular-nums, so values line up and compare at a glance. - Headers are sentence case and name the content:
Last sync, notLast SyncorDate. classNameonTablestyles thetable, not the scrolling container around it.
Do and don't
| Source | Records |
|---|---|
| Lab results | 12,480 |
| Imaging | 860 |
| Referrals | 3,112 |
| Source | Records |
|---|---|
| Lab results | 12,480 |
| Imaging | 860 |
| Referrals | 3,112 |
States
resting
| P-001 | Jane Cooper | Jun 3, 2025 |
| P-002 | Floyd Miles | May 20, 2025 |
interactive · hover
| P-001 | Jane Cooper | Jun 3, 2025 |
| P-002 | Floyd Miles | May 20, 2025 |
selected
| P-001 | Jane Cooper | Jun 3, 2025 | |
| P-002 | Floyd Miles | May 20, 2025 |
overflow · named scroll region
| ID | Name | Status | Last visit |
|---|---|---|---|
| P-001 | Jane Cooper | Active | Jun 3, 2025 |
| P-002 | Floyd Miles | Inactive | May 20, 2025 |
Toggle the site theme to review both themes.
Accessibility
Built in
- Renders native
<table>,<thead>,<th>and<td>elements, so screen readers announce the row, the column and its header. - The table sits in a container that scrolls sideways, so a wide table never widens the page.
- While the table is wider than its container, the container is a tab stop and a region named like the table, so a keyboard user can scroll it with the arrow keys. It shows the Trust focus ring.
Your responsibility
- Name the table: a
TableCaption, or anaria-labelonTablewhen a heading above already names it. The scroll container takes the same name, so a table that can overflow always needs one. - Put column headers in
TableHeadinsideTableHeader. For a row header, renderTableHeadin the row withscope="row". - Write empty cells out (
Never,None) or use a dash with a caption that explains it. A blank cell reads as missing data.
How to test
- With a screen reader, move into the table: it announces the caption, then the number of rows and columns.
- Move cell by cell (Ctrl+Option+arrows in VoiceOver, Ctrl+Alt+arrows in NVDA): each cell is read with its column header.
- Narrow the window to 320px: the table scrolls inside its container and the page does not scroll sideways.
- At that width, press Tab: the container takes focus with the Trust ring, the arrow keys scroll it, and a screen reader announces it as a region with the table's name.
API
Table
| Prop | Values | Default | Description |
|---|---|---|---|
| aria-label | string | – | Names the table, and its scroll container while it overflows. Leave it off when a |
TableRow
| Prop | Values | Default | Description |
|---|---|---|---|
| interactive | boolean | false | Tints the row on hover. Set it on a row that opens, selects or links to something; leave it off for rows of static data. |
All other props come from the native table element.