shadcn.io is an independent project built on shadcn/ui
On this page9 sections
A table lays out records that share the same fields, such as invoices or payments, so people can compare values down a column. These parts are the HTML table elements with styles: a caption, a footer for totals, and a container that scrolls sideways when the columns don't fit. Sorting, filtering and paging are yours to add.
For the fields of a single record, an order or a profile, use a Data List. When the rows are items people reorder or drag between groups, a List fits better.
Installation
Anatomy

Usage
import {
Table, TableBody, TableCaption, TableCell, TableFooter, TableHead,
TableHeader, TableRow,
} from "@/components/ui/table";const invoices = [
{ amount: "$250.00", id: "INV001", method: "Credit Card", status: "Paid" },
{ amount: "$150.00", id: "INV002", method: "PayPal", status: "Pending" },
{ amount: "$350.00", id: "INV003", method: "Bank Transfer", status: "Unpaid" },
];
export const InvoiceTable = () => (
<Table>
<TableCaption>A list of your recent invoices.</TableCaption>
<TableHeader>
<TableRow>
<TableHead className="w-[100px]">Invoice</TableHead>
<TableHead>Status</TableHead>
<TableHead>Method</TableHead>
<TableHead className="text-end">Amount</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{invoices.map((invoice) => (
<TableRow key={invoice.id}>
<TableCell className="font-medium">{invoice.id}</TableCell>
<TableCell>{invoice.status}</TableCell>
<TableCell>{invoice.method}</TableCell>
<TableCell className="text-end">{invoice.amount}</TableCell>
</TableRow>
))}
</TableBody>
<TableFooter>
<TableRow>
<TableCell colSpan={3}>Total</TableCell>
<TableCell className="text-end">$750.00</TableCell>
</TableRow>
</TableFooter>
</Table>
);Accessibility
The parts render the HTML table elements, so a screen reader announces how many rows and columns there are, reads each cell with its column header and offers its table commands for moving cell by cell. Name the table with TableCaption, which renders a caption, or with an aria-label on Table. A table wider than its container scrolls inside it, and not every browser puts that box in the tab order. Give Table a tab index of 0 so the keyboard always reaches it, and an aria-label, which makes the box a region with the same name.
- Tab
- Moves focus to the next focusable element, such as a button in a cell. Once
Tablehas a tab index of 0, its scroll container is one of them, ahead of anything inside it. - Shift+Tab
- Moves focus to the previous focusable element.
- Arrow Right
- While the scroll container has focus, scrolls a table wider than it to the right.
- Arrow Left
- While the scroll container has focus, scrolls it back to the left.
Demos
Footer
Three invoices sit above a TableFooter, whose one row stretches Total across the first three columns and puts the amount under Amount. The footer has a muted background and a top border, so it reads as a summary of the rows and not as a fourth invoice. Use a footer for a sum, a count or a balance, and work it out from the same rows you render.
Actions
Three products, each ending in a ghost icon button that opens a menu with Edit, Duplicate and a destructive Delete. Each button's aria-label names its product, Open menu for Wireless Mouse, and the row keeps its hover tint while its menu is open. Reach for a row menu when the actions belong to one record and a row of buttons would crowd the cell.
Data table
Payments run through TanStack Table: a search field filters by email, the Email header sorts, a Columns menu hides Status, Email or Amount, checkboxes select rows, and Previous and Next page through five at a time. TanStack holds that state, and the Table parts draw the rows it returns. Use it for an admin list of many records, and the plain table for a short, fixed one.
RTL
The invoices in Arabic, with dir set to rtl on Table, so the columns run from the right: the invoice number at the right edge, the amount at the left. Table gives its scroll container the same dir, so a table wider than its space opens on the invoice numbers and scrolls left toward the amounts.
FAQ
How do I add sorting, filtering and pagination to a React table?
Hand the rows to a table library and render what it returns. The Data table demo does this with TanStack Table: its row models filter by email, sort the Email column and cut the result into pages of five, and the Table parts draw the current page. The parts hold no state of their own, so rows your server already sorted and paged render the same way.
Once the Email column is sorted, the demo sets aria-sort on its TableHead, so a screen reader announces the order along with the column's name.
How do I make a table scroll horizontally on mobile?
It already does: the table sits in a container that scrolls sideways once the columns are wider than the screen. Every cell has whitespace-nowrap, so long values widen the table instead of wrapping. To wrap a column, add whitespace-normal and a width such as w-64 to its TableHead and its cells.
For keyboard users, set tabIndex to 0 on Table and give it an aria-label: the container becomes a named region they can tab to and scroll with the arrow keys. To drop a column on phones, add hidden md:table-cell to its head and cells.
How do I keep the table header visible while the rows scroll?
Give the rows a box of their own to scroll in. The container around the table has overflow-x-auto, which makes it the box a sticky header sticks within, and it grows with the rows, so a sticky header never engages while the page scrolls.
In your installed table file, add a maximum height such as max-h-96 to the container div, whose data-slot is table-container. Then add sticky top-0 z-10 bg-background to TableHeader. The header stays in place while the body scrolls inside that height.
How do I select table rows with checkboxes?
Keep the selected rows in state and render a Checkbox in a first column, with one in the header for the whole page. The Data table demo takes that state from TanStack Table's row selection.
Set data-state to selected on a selected TableRow and the row style tints it. Label each checkbox with its row, as the demo does with Select ken99@example.com, so a screen reader can tell them apart.
How do I add an actions menu to each table row?
Put an icon button in the last TableCell that opens a Dropdown Menu, as the Actions demo does, and keep that column narrow. Name the button after its row, Open menu for Wireless Mouse rather than the same Open menu on every row, so a screen reader user knows which record it acts on.
The row keeps its hover tint while the menu is open, through a style on TableRow that reacts to the expanded trigger inside it.
How do I add a caption or a totals row to a table?
Put TableCaption first inside Table. It renders a caption, which the style places under the table and screen readers announce as the table's name.
For totals, add TableFooter after TableBody with one TableRow, and stretch a label across the leading columns with a column span, as the Footer demo does. Work the total out from the rows you render, so it can't drift from them.
How do I make a striped table with UI SDK?
This Table has no striped option, so add a class: even:bg-muted/30 on each TableRow in the body tints every second one.
Rows also tint on hover through the row's own style, and hover:bg-transparent on a row turns that off. Both classes merge with the row's defaults and win over them, so the component itself needs no edit.
When should I use a table instead of a data list or cards?
Use a table when there are many records with the same fields and people compare them down a column: invoices, payments, the users in an admin list. Each column is named once in the header, and the eye runs straight down the amounts.
For the fields of one record, an order summary or a profile, a Data List reads better than a two-column table of labels and values. On a narrow screen with a few fields per record, a stack of cards can beat a table that scrolls sideways.
API Reference
Table
<div> data-slot="table-container"
className?string
Merged with the part's classes.
TableHeader
<thead> data-slot="table-header"
className?string
Merged with the part's classes.
TableBody
<tbody> data-slot="table-body"
className?string
Merged with the part's classes.
TableFooter
<tfoot> data-slot="table-footer"
className?string
Merged with the part's classes.
TableRow
<tr> data-slot="table-row"
className?string
Merged with the part's classes.
TableHead
<th> data-slot="table-head"
className?string
Merged with the part's classes.
TableCell
<td> data-slot="table-cell"
className?string
Merged with the part's classes.
TableCaption
<caption> data-slot="table-caption"
className?string
Merged with the part's classes.











