Skip to content

Now in the official shadcn registry directory.

Start free

Table

Composable table primitives (header, body, footer, rows, cells and caption) with hover rows, a selected state and built-in horizontal scroll.

displaydata
A free styled version is available
EndpointRegionp95
/v1/deploymentsus-east-148ms
/v1/webhookseu-central-171ms
/v1/keys/rotateap-south-163ms

Installation

Run the following command

npx shadcn@latest add @ai2/table

Dependencies, the @ai2/tokens theme and the component file are installed together.

Usage

TS
import {
  Table,
  TableBody,
  TableCell,
  TableHead,
  TableHeader,
  TableRow,
} from "@/components/ui/table"

<Table>
  <TableHeader>
    <TableRow>
      <TableHead>Endpoint</TableHead>
      <TableHead className="text-right">p95</TableHead>
    </TableRow>
  </TableHeader>
  <TableBody>
    <TableRow>
      <TableCell className="font-mono text-xs">/v1/deployments</TableCell>
      <TableCell className="text-right">48ms</TableCell>
    </TableRow>
  </TableBody>
</Table>

The parts mirror native table elements one-to-one. The root Table wraps itself in a scroll container, so wide tables overflow horizontally instead of breaking the layout. Wrap it in your own data logic (e.g. TanStack Table) or use it directly.

Examples

Density

density="compact"
BranchRegionStatus
mainus-east-1Deployed
feat/billingeu-central-1Building
fix/webhooksap-south-1Queued
density="comfortable"
BranchRegionStatus
mainus-east-1Deployed
feat/billingeu-central-1Building
fix/webhooksap-south-1Queued
density="relaxed"
BranchRegionStatus
mainus-east-1Deployed
feat/billingeu-central-1Building
fix/webhooksap-south-1Queued

density sets header and cell padding across the whole table: compact for dense dashboards, comfortable (the default) and relaxed for roomier reading. It flows to every cell through context.

Variants

variant="line"
BranchRegionStatus
mainus-east-1Deployed
feat/billingeu-central-1Building
fix/webhooksap-south-1Queued
variant="striped"
BranchRegionStatus
mainus-east-1Deployed
feat/billingeu-central-1Building
fix/webhooksap-south-1Queued
variant="outline"
BranchRegionStatus
mainus-east-1Deployed
feat/billingeu-central-1Building
fix/webhooksap-south-1Queued

variant controls row separation: line (the default) divides rows with a border, striped zebra-stripes even rows, and outline draws a boxed grid with cell borders.

Invoice totals for June 2026.
InvoiceStatusAmount
INV-0042Paid$250.00
INV-0043Pending$150.00
Total$400.00

Selected rows

BranchStatus
mainDeployed
feat/billingBuilding

Set data-state="selected" on a TableRow to highlight it - selection libraries like TanStack Table set this attribute for you.

Props

Table adds the two axes below and passes them to every head and cell through context; all parts also accept every native prop of their underlying element.

PropTypeDefaultDescription
density"compact" | "comfortable" | "relaxed""comfortable"Row and cell spacing. compact tightens padding for dense dashboards; relaxed opens it up. Flows to every head and cell via context.
variant"line" | "striped" | "outline""line"Row separation style. line divides rows with a bottom border; striped zebra-stripes even rows; outline draws a boxed grid with cell borders.

The remaining seven parts add no props of their own: TableHeader (<thead>), TableBody (<tbody>), TableFooter (<tfoot>), TableRow (<tr>), TableHead (<th>), TableCell (<td>) and TableCaption (<caption>).

ai2 Table: semantic data tables for React, tuned for density

The ai2 Table is a shadcn-compatible table component for React, built on plain semantic HTML table elements and styled with Tailwind CSS v4. It gives you composable primitives for headers, bodies, footers, rows, cells and captions, tuned for the data density of dashboards, billing pages and admin screens: compact paddings, quiet muted headers and a hover highlight on every row.

Because it ships through the shadcn registry format, you install it with one CLI command, an MCP agent, or a copy-paste, and the source lands in your own project. You own the file; there is no runtime dependency on ai2 itself. The live example above is the exact component you get.

What is the ai2 Table?

It is an eight-part composition that mirrors native table elements one-to-one: Table, TableHeader, TableBody, TableFooter, TableRow, TableHead, TableCell and TableCaption. The anatomy matches shadcn/ui exactly, so existing snippets, muscle memory and AI agents keep working without changes.

The root wraps the table in an overflow container, so wide tables scroll horizontally instead of breaking the page layout. A density axis (compact, comfortable, relaxed) and a variant axis (line, striped, outline) flow from the root to every cell through context. Styling comes from the ai2 token file, which means header text, borders, the footer surface and the row hover follow your theme in both light and dark mode from day one.

Why use it

  • Semantic HTML underneath: Each part renders its native element (table, thead, tbody, tfoot, tr, th, td, caption), so screen readers, keyboard users and search engines get real table semantics for free.
  • Density axis for data: A density prop (compact, comfortable, relaxed) sets header and cell padding across the whole table, so you tune large datasets to fit without custom overrides.
  • Row states built in: Rows highlight on hover and switch to the accent surface when data-state="selected" is set, which is exactly the attribute selection libraries like TanStack Table emit.
  • Horizontal scroll by default: The root wraps itself in an overflow-x-auto container, so a wide table scrolls in place instead of blowing up your grid.
  • Agent-readable metadata: The registry item describes its parts and intended use in plain words, so an MCP agent can find, inspect and install it without guessing.

Features

  • shadcn registry install: One command adds the component, its dependencies and the @ai2/tokens theme to your project.
  • Eight composable parts: Header, body, footer, row, head cell, data cell and caption compose freely, so you only render the parts a given table needs.
  • Footer and caption support: TableFooter gets a surface-2 background and medium weight for totals; TableCaption renders below the table in muted text.
  • Checkbox-ready cells: TableHead and TableCell drop their right padding automatically when they contain a checkbox, so selection columns align tightly.
  • Motion from tokens: The row hover transition reads --motion-fast from the shared token file instead of a hardcoded duration, matching every other ai2 component.
  • Data attributes for styling: Every part exposes data-slot (table, table-header, table-row and so on), so you can restyle any layer from CSS without forking the component.

Production tips

  • Add a caption for context: TableCaption is the accessible name of the table. A short caption like "Invoice totals for June 2026" helps screen reader users and costs one line.
  • Right-align numbers: Add text-right to numeric TableHead and TableCell pairs so amounts and latencies line up on the decimal side and scan faster.
  • Let libraries drive selection: Do not hand-roll selected state. Wire TanStack Table or your own logic to set data-state="selected" on TableRow and the accent highlight follows.
  • Mind very wide tables on mobile: The built-in horizontal scroll saves the layout, but consider hiding low-priority columns at small breakpoints instead of making users pan.
  • Use the footer for totals only: TableFooter is styled as a summary surface. Keep repeated data rows in TableBody so the visual hierarchy stays honest.

Works with the rest of ai2

Tables get better with the rest of the registry. Put an ai2 Badge in a status column, an ai2 Checkbox in the selection column (the cells already handle its padding), and an ai2 Dropdown Menu behind a row actions button.

For page-level composition, follow the table with ai2 Pagination for long datasets, and show ai2 Skeleton rows while the data loads. Everything shares one token source, so combinations stay visually consistent in both modes.

FAQs

Get new components in your inbox

Component drops, new themes and release notes. No spam, and you can unsubscribe from any email.

© 2026 ai2 design system · MIT licensed · Built with its own components