Table
Table shows data in rows and columns, and it scrolls sideways when the columns need more room than the page has.
<Table aria-label="Invoices"> <TableCaption>Invoices this month</TableCaption> <TableHeader> <TableRow> <TableHead>Invoice</TableHead> <TableHead align="end">Amount</TableHead> </TableRow> </TableHeader> <TableBody> <TableRow> <TableCell>INV-001</TableCell> <TableCell align="end">£240.00</TableCell> </TableRow> </TableBody></Table>Use a Table for data that people compare across rows and columns, such as invoices or members. It renders a real table element, so a screen reader can move by row and by column and read out the header for each cell.
The Table draws the lines between rows, the space inside each cell and a header row in a muted colour, and nothing else. Its rows don't react to hover or presses. For sorting, put a Button in a header cell and sort the rows in your own code.
When the columns need more room than the page has, the Table scrolls sideways inside its own box rather than widening the page. That box can take keyboard focus only while it scrolls. Name it with aria-label or aria-labelledby so a screen reader announces it as a named region, and add a TableCaption to name the table itself.
size sets the cell padding and the text size together, from 1 to 4, and the padding also follows the density setting. The first and last columns have no padding on their outer edge, so the text lines up with the content around the table.
Use align on TableHead and TableCell to set start, center or end, and set the same value for every cell in a column. Put words at the start and numbers at the end so the digits line up.
Topics
Every symbol this component exports, grouped by the job it does. Each one carries the props it declares; each one has an anchor of its own.
Laying out the table
Table
Table shows data in rows and columns, and it scrolls sideways when the columns need more room than the page has.
| Prop | Type | What it does |
|---|---|---|
aria-label? | string | The accessible name of the scroll region around the table. |
aria-labelledby? | string | The id of an element that names the scroll region, usually a heading above the table. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
size? | "1" | "2" | "3" | "4" | Sets the cell padding and the text size, from 1 to 4. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
It also takes every prop of a <table>.
Rows and cells
TableRow
One row of the table. It doesn't respond to hover, selection or presses, so use a different component for rows that people pick
It declares no props of its own. It takes every prop of a <tr>.
- A ScrollArea around it — The Table already scrolls sideways by itself and takes focus only when it overflows. A
ScrollAreaneeds a fixed height, which a table rarely has. - Hover, selection and a press on rows — A row that people can select or open needs keyboard support and an accessible name of its own. That will be a separate component, so this Table's rows stay static.
toneandemphasis— A table as a whole has no meaning to colour. To show a status, put a tone on aTextor aChipinside a cell.- A sticky header — Components never decide their own position on the page. For a tall table with a pinned header, put it in a
ScrollAreaand pin the header there. - Sorting and column controls — Sorting needs state and keyboard handling that belong to your app. Put a
Buttonin the header cell, sort the data yourself, and the Table draws the rows in the order you give it.