How it works
The card holds a real table: the header is 12px muted text over one hairline, rows are separated by faint hairlines (or alternating fills with zebra), and the hovered row becomes a soft rounded band. Right-aligned columns use tabular figures. The card is an inline-size container, so it responds to its own width rather than the window: below 520px each row becomes a card in which the primary cell is the title over a hairline and the other cells form a two-column grid of label and value, taken from the column titles. Cards rise in with a short stagger.
Use it for
- Short lists of records people scan and compare: invoices, members, orders, files.
- Tables that must also work in a narrow side panel or on a phone.
Look elsewhere when
- Sorting, selection or editing: use the sort, select or edit tables.
- Hundreds of rows: use a virtual table.
Usage
import { BasicTable } from './BasicTable.jsx'
export function Invoices({ invoices }) {
return (
<BasicTable
title="Invoices"
caption="Invoices this month"
columns={[
{ key: 'client', title: 'Client', primary: true },
{ key: 'id', title: 'Invoice' },
{ key: 'amount', title: 'Amount', align: 'right', render: (r) => `$${r.amount.toFixed(2)}` },
]}
rows={invoices}
zebra
/>
)
}Props
| Prop | Type | Default | What it does |
|---|---|---|---|
columns | { key: string, title: ReactNode, align?: 'left' | 'right' | 'center', width?: number | string, render?: (row) => ReactNode, primary?: boolean, hideInCard?: boolean }[] | — | The primary column (the first by default) is the row header and the title of each stacked card; hideInCard drops a column from the cards. |
rows / rowKey | object[] / (row, index) => key | row.id ?? index | The data and a stable key per row. |
title / subtitle / actions / caption | ReactNode / string | — | A title row with optional actions on the right; caption names the table for screen readers. |
zebra | boolean | false | Alternate row fills instead of hairlines. |
density | 'compact' | 'regular' | 'relaxed' | 'regular' | Rows of 38, 48 or 58px. |
stack | 'auto' | 'never' | 'always' | 'auto' | Stacked cards below 520px of the table's own width (a container query), never, or always. |
emptyText | ReactNode | 'No rows' | Shown when rows is empty. |
Accessibility
- It is a native table with a caption, column headers (scope col) and a row header (scope row) for the primary cell.
- In stacked cards the header row is visually hidden, not removed, and every value is preceded by its visible label.
- Status cells should carry text, not colour alone, as in the demo.
- Reduced motion removes the card entrance.
Add it to your project
Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the component next to your own.
BasicTable.jsxbasic-table.csstokens.cssREADME.md
Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.





