Table
Lay out tabular data with native table parts, density and border variants, and row states.
| Invoice | Status | Method | Amount |
|---|---|---|---|
| INV-001 | Paid | Credit Card | $250.00 |
| INV-002 | Pending | PayPal | $150.00 |
| INV-003 | Unpaid | Bank Transfer | $350.00 |
| INV-004 | Paid | Credit Card | $450.00 |
| INV-005 | Paid | PayPal | $550.00 |
| INV-006 | Pending | Bank Transfer | $200.00 |
| Total | $1,950.00 | ||
Anatomy#
The table sits inside a container element (data-slot="table-container") that scrolls
horizontally, so wide tables do not stretch the page.
Usage#
Use Table to present data you lay out yourself: invoices, comparison grids, or summaries with a known set of columns. When the table needs sorting, selection, pagination, or server data, use DataTable instead. For a one-column collection, use List.
Table is a styled set of native table elements. Compose the parts in table order.
Parts and native attributes#
Each part renders one fixed element and forwards native attributes to it.
| Part | Element | Own props |
|---|---|---|
Table |
table |
Variants, wrapperRef |
Table.Caption |
caption |
None |
Table.Header |
thead |
None |
Table.Body |
tbody |
None |
Table.Footer |
tfoot |
None |
Table.Row |
tr |
selected |
Table.Head |
th |
align |
Table.Cell |
td |
align |
Use native attributes for table semantics: colSpan and rowSpan on cells, and scope="row" on a
Table.Head that labels a body row. Name the table with Table.Caption, or with aria-label when
a visible caption does not fit. Place Table.Caption first in the markup; it renders below the
table.
ref targets the table; wrapperRef targets the element that wraps it.
Density and borders#
size ('sm', 'md', or 'lg'; default 'md') sets cell padding and text size. border draws
row dividers ('row', the default), column dividers ('col'), or both ('both'). striped shades
alternate rows, and highlightOnHover highlights body rows under the pointer. Neither applies to
selected rows.
Alignment and truncation#
align sets text alignment on Table.Head and Table.Cell: 'start' (default), 'center', or
'end'. Because Table.Head defaults to start, header text is not centered the way the browser
centers a plain th. End-align numeric columns in both the header and the cells.
To keep long text on one line with an ellipsis, add the truncate and max-w-* class to
Table.Head or Table.Cell.
Selected rows#
selected on Table.Row applies the selected background through data-selected. It is visual
only: aria-selected is not valid on rows of a static table, so it is not set. Put a labelled
control in the row, such as a checkbox, so assistive technology knows the row is selected.
Building a data grid#
You have two options for a sortable, filterable grid:
- DataTable. Use DataTable from
moraine/data-table. It renders sorting, selection, pagination, pinning, resizing, loading states, and row virtualization from acreateDataTableinstance. - TanStack Table with Table parts. Use
@tanstack/table-corewithcreateTablefrommoraine/data-tableand render its header groups and rows with Table parts. You own every control, as in the TanStack example below.
Examples#
Review transaction invoices#
Compose a caption, header, body, and footer total. Status badges sit in a cell, and amounts are end-aligned in both the header and the cells.
Truncate long header and cell values#
Add truncate and a max-w-* class to keep long text on one line, and center or end-align
the other columns with align.
Build a payments grid with TanStack Table#
Create a TanStack table with sorting, filtering, selection, column visibility, and pagination
features, then render it with Table parts, Checkbox, Input, DropdownMenu, and Pagination.
To get these features without wiring them yourself, use DataTable.
API Reference#
Attributes#
data-selectedProps#
Table#
Props for Table. Renders a <table> element by default.
Header#
Renders a <thead> element by default.
Body#
Renders a <tbody> element by default.
Footer#
Renders a <tfoot> element by default.
Row#
Renders a <tr> element by default.
Head#
Renders a <th> element by default.
Cell#
Renders a <td> element by default.
Caption#
Renders a <caption> element by default.