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 class="w-[100px]">Invoice</TableHead>
<TableHead>Status</TableHead>
<TableHead>Method</TableHead>
<TableHead class="text-end">Amount</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{invoices.map((invoice) => (
<TableRow key={invoice.id}>
<TableCell class="font-medium">{invoice.id}</TableCell>
<TableCell>{invoice.status}</TableCell>
<TableCell>{invoice.method}</TableCell>
<TableCell class="text-end">{invoice.amount}</TableCell>
</TableRow>
))}
</TableBody>
<TableFooter>
<TableRow>
<TableCell colSpan={3}>Total</TableCell>
<TableCell class="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.
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 Solid table?
Sort, filter and slice the rows in your own state, then render the result, since the Table parts hold no state of their own. Once sorting, filtering and paging all apply at once, TanStack Table's Solid adapter has row models that do the work, and a Pagination under the table moves between pages. Rows your server already sorted and paged render the same way.
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 ids of the selected rows in state and render a Checkbox in a first column, bound to that state, with one in the header that selects every row on the page.
Set data-state to selected on a selected TableRow and the row style tints it. Label each checkbox with its row, such as Select INV001, 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 Ark UI?
Set variant to striped on Table, and every second row in the body gets a light muted background. The setting covers the whole table, so no row needs a class of its own.
Rows also tint on hover by default, though on a striped table only the unshaded rows show it. Set isHoverable to false on Table to turn the tint off, which suits a table people read rather than click through. On a striped table that setting also clears a shaded row's stripe while the pointer is over it.
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
<table> data-slot="table-container"
isHoverable?boolean
Whether the table rows are hoverable.
- Default
true
variant?"plain" | "striped"
The variant of the table.
- Type
"plain" | "striped"- Default
"plain"
asChild?(props: ParentProps) => JSX.Element
Render your own element: a function that gets the part's props to spread on it.
- Type
(props: ParentProps) => JSX.Element
class?string
Merged with the part's classes.
data-hoverable?string
"true" when isHoverable is true, otherwise "false".
data-variant?string
Mirrors variant.
TableHeader
<thead> data-slot="table-header"
asChild?(props: ParentProps) => JSX.Element
Render your own element: a function that gets the part's props to spread on it.
- Type
(props: ParentProps) => JSX.Element
class?string
Merged with the part's classes.
TableBody
<tbody> data-slot="table-body"
asChild?(props: ParentProps) => JSX.Element
Render your own element: a function that gets the part's props to spread on it.
- Type
(props: ParentProps) => JSX.Element
class?string
Merged with the part's classes.
TableFooter
<tfoot> data-slot="table-footer"
asChild?(props: ParentProps) => JSX.Element
Render your own element: a function that gets the part's props to spread on it.
- Type
(props: ParentProps) => JSX.Element
class?string
Merged with the part's classes.
TableRow
<tr> data-slot="table-row"
asChild?(props: ParentProps) => JSX.Element
Render your own element: a function that gets the part's props to spread on it.
- Type
(props: ParentProps) => JSX.Element
class?string
Merged with the part's classes.
TableHead
<th> data-slot="table-head"
asChild?(props: ParentProps) => JSX.Element
Render your own element: a function that gets the part's props to spread on it.
- Type
(props: ParentProps) => JSX.Element
class?string
Merged with the part's classes.
TableCell
<td> data-slot="table-cell"
asChild?(props: ParentProps) => JSX.Element
Render your own element: a function that gets the part's props to spread on it.
- Type
(props: ParentProps) => JSX.Element
class?string
Merged with the part's classes.
TableCaption
<caption> data-slot="table-caption"
asChild?(props: ParentProps) => JSX.Element
Render your own element: a function that gets the part's props to spread on it.
- Type
(props: ParentProps) => JSX.Element
class?string
Merged with the part's classes.











