Skip to content
shadcn.io
shadcn.io is not affiliated with official shadcn/ui

Shadcn Table for React and Tailwind

A responsive table component.

A list of users in your workspace.
NameEmailRoleStatus
Alice Johnson[email protected]Adminactive
Bruno Silva[email protected]Editorinvited
Clara Mendes[email protected]Viewerinactive
David Park[email protected]Editoractive

Installation

bunx --bun shadcn@latest add https://kit.dev/r/table.json

Anatomy

Table
├── TableCaption
├── TableHeader
│   └── TableRow
│       └── TableHead
├── TableBody
│   └── TableRow
│       └── TableCell
└── TableFooter
    └── TableRow
        └── TableCell

Usage

import { 
  Table, 
  TableBody, 
  TableCaption, 
  TableCell, 
  TableHead, 
  TableHeader, 
  TableRow,
  TableFooter,
} from "@/components/ui/table";
<Table>
  <TableCaption />
  <TableHeader>
    <TableRow>
      <TableHead />
      <TableHead />
    </TableRow>
  </TableHeader>
  <TableBody>
    <TableRow>
      <TableCell />
      <TableCell />
    </TableRow>
  </TableBody>
  <TableFooter />
</Table>

Accessibility

Always use a TableCaption to help assistive technologies announce what the table represents.

Use with the sr-only class to make the caption screen-reader only if you don't want to show it.

<Table>
  <TableCaption className="sr-only">
    Monthly revenue by product.
  </TableCaption>
  {/* ... */}
</Table>

Examples

Striped

Use variant="striped" on Table for alternating row backgrounds.

Use TableFooter for summary rows, totals, or notes.

With actions

Add an actions column with buttons per row.

With action bar

Use checkboxes for row selection and an action bar that appears when one or more rows are selected. See the action bar component.

With context menu

Wrap each row with ContextMenuTrigger so right-clicking shows a context menu with row actions.

Disable row hover

Set isHoverable={false} on Table to disable the hover background on body rows.

API Reference

Table

Scrollable wrapper around a native table. Supports striped and hover variants.

PropTypeDefault
variant"plain" | "striped""plain"
isHoverablebooleantrue
classNamestring-
asChildbooleanfalse

TableHeader

Table header row group.

PropTypeDefault
classNamestring-
asChildbooleanfalse

TableBody

Table body row group.

PropTypeDefault
classNamestring-
asChildbooleanfalse

TableFooter

Table footer row group for totals or summary rows.

PropTypeDefault
classNamestring-
asChildbooleanfalse

TableRow

A single table row.

PropTypeDefault
classNamestring-
asChildbooleanfalse

TableHead

Header cell for column titles.

PropTypeDefault
classNamestring-
asChildbooleanfalse

TableCell

Data cell for body or footer rows.

PropTypeDefault
classNamestring-
asChildbooleanfalse

TableCaption

Accessible caption describing the table. Use sr-only for screen-reader only.

PropTypeDefault
classNamestring-
asChildbooleanfalse