Search

Find a component, token or page

Base · Data display

Table

Displays rows of data in aligned columns.

HTML / JSPlannedReactStableReact NativeDraftSwift (SwiftUI)PlannedGodotPlannedVueDraftSvelteDraftSolidDraft
Reviewed
Outbound shipments, week 47
ShipmentDestinationCarrierWeight
PDC-4821RotterdamBlue Harbor Lines1,240 kg
PDC-4822HamburgSummit Rail860 kg
PDC-4823AntwerpAtlas Freight2,015 kg
Total weight4,115 kg

Props

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

<Table>
  <TableCaption>Outbound shipments, week 47</TableCaption>
  <TableHeader>
    <TableRow>
      <TableHead>Shipment</TableHead>
      <TableHead>Destination</TableHead>
      <TableHead>Carrier</TableHead>
      <TableHead className="text-right">Weight</TableHead>
    </TableRow>
  </TableHeader>
  <TableBody>
    <TableRow>
      <TableCell className="font-medium">PDC-4821</TableCell>
      <TableCell>Rotterdam</TableCell>
      <TableCell className="text-muted-foreground">Blue Harbor Lines</TableCell>
      <TableCell className="text-right tabular-nums">1,240 kg</TableCell>
    </TableRow>
  </TableBody>
  <TableFooter>
    <TableRow>
      <TableCell colSpan={3}>Total weight</TableCell>
      <TableCell className="text-right tabular-nums">1,240 kg</TableCell>
    </TableRow>
  </TableFooter>
</Table>

Overview

Table is a set of styled parts for the native table elements: header, body, footer, rows, cells and a caption. It handles appearance only and scrolls horizontally when the columns do not fit.

When to use

  • To show a short, fixed set of records with the same fields, so values can be compared down a column.
  • For summaries such as an order’s line items with a total in the footer.
  • As the building block when you need full control over the markup.

When not to use

  • When people need to sort or filter the rows: use Data table, which adds that on top of these parts.
  • For a list of items with one main field each: use a simple list.
  • For page layout or aligning form fields: use grid or flex layout.
  • For label and value pairs about a single record: use a description list.

Anatomy

  1. Container

    A wrapper that scrolls horizontally when the table is wider than its parent.

  2. Header

    TableHeader with TableHead cells: medium-weight column titles above a bottom border.

  3. Body

    TableBody with a TableRow per record, divided by 1px borders.

  4. Cell

    TableCell: 8px padding, single line, vertically centered.

  5. Footer (optional)

    TableFooter: a muted row for totals.

  6. Caption (optional)

    TableCaption: a muted description below the table.

Props

The contract every language implements. Names follow each language’s conventions (camelCase in React, snake_case in Rust).

PropTypeDefaultDescription
captionstringOutbound shipments, week 47Describes the table. Passed as children of TableCaption.
footerLabelstringTotal weightLabel of the totals row in the demo. Passed as children of a TableCell in TableFooter.
childrennode–TableCaption, TableHeader, TableBody and TableFooter.

States

Row rest
Transparent background with a bottom border.
Row hover
Muted background at 50% strength. Pointer devices only.
Row selected
Muted background when the row has data-state="selected".

Accessibility

Role: table

  • Uses native table, thead, th and td elements, so screen readers announce row and column positions and offer table navigation.
  • Add a TableCaption, or an aria-label on Table, so the table has a name.
  • TableHead renders th; add scope="row" to a th used as a row header.
  • Right-align numeric columns and use tabular numerals so digits line up.
  • The table itself has no keyboard interaction. Put real buttons or links in cells for row actions rather than making the row clickable.

Design tokens

Change any of these in Foundations and this component follows, in every language.

Platform notes

HTML / JS
Planned
Not built in HTML / JS yet.
React
Stable
Matches the contract with no platform differences.
React Native
Draft
Rows of flex Views inside a horizontal ScrollView. Columns line up through matching flex, minWidth or width on each cell; `span` replaces colSpan and `align="end"` replaces text-right. On phones a list of cards often fits better.
Swift (SwiftUI)
Planned
Not built in Swift yet.
Godot
Planned
Not built in Godot yet.
Vue
Draft
Usage snippet only; same props and behavior as the React component.
Svelte
Draft
Usage snippet only; same props and behavior as the React component.
Solid
Draft
Usage snippet only; same props and behavior as the React component.

Related