<!-- generated by scripts/gen-docs.mjs from docs/system/table.md. Edit the source and rerun. -->
# Table

## Description
Shows a few rows a person reads whole, such as the charges on a booking, the parameters of an endpoint or a fund's largest holdings in a card.

`import { Table, TableHeader, TableBody, TableFooter, TableRow, TableHead, TableCell, TableCaption } from "@/components/cobalt/ui/table"`, source `registry/cobalt/ui/table.tsx`, status `ready`.
Foundation: `hand-rolled`. Traps checked: `trap/table-divs`, `trap/numbers-shift`, `trap/empty-value`, `trap/overflow-scrollbar`, `trap/scroll-chain`, `trap/focus-ring-shape`.

`trap/table-divs` is answered by a real `table` with `thead`, `tbody`, `tfoot`, `th` and `scope` (ARIA). `trap/numbers-shift` by tabular figures on the whole table and `align="end"` on figures (Rules). `trap/empty-value` by the rule to write "None" in an empty cell (Content). `trap/overflow-scrollbar` and `trap/scroll-chain` by the box that scrolls sideways only when the table is wider than its column, with `overscroll-x-contain` (States). `trap/focus-ring-shape` by the box's own ring, which takes a Tab stop only while it scrolls (Keyboard), drawn 2px inside the box round a 10px corner (`rounded-lg`) so it is not a square box around a rounded layout and a card's clip never cuts it; the box reaches 10px past the first and last columns, or to a card's edges, so the ring clears the text.

### Foundation
Not applicable: hand-rolled.

| Given by the foundation | Added by the team |
|---|---|
| Not applicable: hand-rolled, the HTML `table` | The DataTable's type and lines: a 40px header (`--control-lg`) in medium muted text over a hairline, 40px rows (`--row`) split by hairlines, 10px cell padding; the first and last columns flush with the text around the table, while the box around it reaches 10px past them by a matching padding (`--table-bleed`), so the 44px touch area of an action in the last column fits inside the box and never scrolls the table sideways, and as the content of a card it reaches the card's edges instead, so a table that scrolls slides under the card's edge rather than stopping 16px short of it; `align="end"` for figures on one line; a row head with `scope="row"` at the body's weight; a box that scrolls sideways when the table is wider than its column and then takes a Tab stop and a region name from `label`; a caption under the table in small muted text |

## Examples
The charges on a booking, with the total in the footer.

Real uses, 0 call sites (`rg -n "<Table\b" app registry --glob '!registry/cobalt/ui/*'`): the part is new. Atlas's docs draw a static table by hand for each endpoint (`docs/research/2026-10-17-coverage.md`, section 3).

### Example files
| File | Covers | Caption |
|---|---|---|
| `docs/system/examples/table/default.tsx` | default | The charges on a booking, with the total in the footer |
| Not applicable: default.tsx holds words at the start of their cells | align=start | Start, for words, names and codes |
| Not applicable: default.tsx and in-card.tsx line figures up at the end | align=end | End, for figures, so each column of amounts lines up on its last digit |
| `docs/system/examples/table/state-scrolls.tsx` | state:scrolls | In a card narrower than its four quarters, the table scrolls sideways inside the card, which then takes a Tab stop |
| `docs/system/examples/table/in-card.tsx` | composition:Card | A short table in a card; its first column lines up with the card's title |

Example: The charges on a booking, with the total in the footer (`docs/system/examples/table/default.tsx`)

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

const charges = [
  { item: "Double room, garden side", detail: "3 nights at $139.00", amount: "$417.00" },
  { item: "Breakfast", detail: "2 guests, 3 mornings", amount: "$54.00" },
  { item: "City tax", detail: "$1.00 per guest per night", amount: "$6.00" },
];

export default function Example() {
  return (
    <Table className="max-w-lg">
      <TableCaption>Charges for booking BK-4821, Oct 24 to Oct 27.</TableCaption>
      <TableHeader>
        <TableRow>
          <TableHead>Item</TableHead>
          <TableHead align="end">Amount</TableHead>
        </TableRow>
      </TableHeader>
      <TableBody>
        {charges.map((c) => (
          <TableRow key={c.item}>
            {/* The detail is a second line under the item, as on a receipt, so a phrase never splits
                across a narrow column of its own. */}
            <TableHead scope="row">
              {c.item}
              <span className="block text-muted-foreground">{c.detail}</span>
            </TableHead>
            <TableCell align="end">{c.amount}</TableCell>
          </TableRow>
        ))}
      </TableBody>
      <TableFooter>
        <TableRow>
          <TableHead scope="row">Total</TableHead>
          <TableCell align="end">$477.00</TableCell>
        </TableRow>
      </TableFooter>
    </Table>
  );
}
```

Example: A short table in a card; its first column lines up with the card's title (`docs/system/examples/table/in-card.tsx`)

```tsx
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/cobalt/ui/card";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/cobalt/ui/table";

const rooms = [
  { room: "Garden double", nights: "41", rate: "$139.00" },
  { room: "Single", nights: "28", rate: "$129.00" },
  { room: "Suite", nights: "9", rate: "$272.00" },
];

export default function Example() {
  return (
    <Card className="w-full max-w-md">
      <CardHeader>
        <CardTitle>Rooms in October</CardTitle>
        <CardDescription>Nights booked so far and the average rate.</CardDescription>
      </CardHeader>
      <CardContent>
        <Table aria-label="Rooms in October">
          <TableHeader>
            <TableRow>
              <TableHead>Room</TableHead>
              <TableHead align="end">Nights</TableHead>
              <TableHead align="end">Rate</TableHead>
            </TableRow>
          </TableHeader>
          <TableBody>
            {rooms.map((r) => (
              <TableRow key={r.room}>
                <TableHead scope="row">{r.room}</TableHead>
                <TableCell align="end">{r.nights}</TableCell>
                <TableCell align="end">{r.rate}</TableCell>
              </TableRow>
            ))}
          </TableBody>
        </Table>
      </CardContent>
    </Card>
  );
}
```

## Variants

### align
- `start`: words, names and codes. The default. Used at 0 call sites.
- `end`: figures, so a column lines up on its last digit; the cell keeps them on one line. Used at 0 call sites.

## States
| State | Trigger | What the user can do | Shown by, besides color | Checked by |
|---|---|---|---|---|
| fits | the table is no wider than its column | read it | every column in view; no Tab stop on the box | test |
| scrolls | the table is wider than its column | scroll sideways by swipe, trackpad or keyboard | columns cut at the box's edge; the box takes a Tab stop and `role="region"` named by `label` | screenshot |
| focus-visible | Tab onto a scrolling box | scroll it with the arrow keys | the 2px ring inside the box's edge | by hand |
| empty | no rows | read the caption | the caption, such as "No holdings in this filing." | screenshot |

Example: In a card narrower than its four quarters, the table scrolls sideways inside the card, which then takes a Tab stop (`docs/system/examples/table/state-scrolls.tsx`)

```tsx
import { Card, CardContent, CardHeader, CardTitle } from "@/components/cobalt/ui/card";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/cobalt/ui/table";

const quarters = ["Q4 2025", "Q1 2026", "Q2 2026", "Q3 2026"];
const rows = [
  { name: "Gross assets", values: ["$4.1B", "$4.3B", "$4.6B", "$4.8B"] },
  { name: "Holdings", values: ["171", "176", "179", "186"] },
];

export default function Example() {
  return (
    // A side-column card, too narrow for every quarter at once.
    <Card size="sm" className="w-full max-w-60">
      <CardHeader>
        <CardTitle>Quarterly figures</CardTitle>
      </CardHeader>
      <CardContent>
      <Table label="Quarterly figures" aria-label="Quarterly figures">
        <TableHeader>
          <TableRow>
            <TableHead>Figure</TableHead>
            {quarters.map((q) => (
              <TableHead key={q} align="end">
                {q}
              </TableHead>
            ))}
          </TableRow>
        </TableHeader>
        <TableBody>
          {rows.map((r) => (
            <TableRow key={r.name}>
              {/* A row's name stays on one line, as the figures beside it do. */}
              <TableHead scope="row" className="whitespace-nowrap">
                {r.name}
              </TableHead>
              {r.values.map((v, i) => (
                <TableCell key={quarters[i]} align="end">
                  {v}
                </TableCell>
              ))}
            </TableRow>
          ))}
        </TableBody>
      </Table>
      </CardContent>
    </Card>
  );
}
```

### State precedence
- Fits and scrolls: Not applicable: the box measures one or the other after every resize.
- Scrolls and focus-visible: both show. The ring is drawn inside the box's edge, in the room the box keeps beside the text, so the cut columns stay as they are and a card never clips it.

### Motion
Not applicable: no motion.

## Props

<!-- Props generated from registry/cobalt/ui/table.tsx with TypeScript by scripts/props-table.mjs -->
### Table

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `label?` | `string` |  | Names the scrolling box for a screen reader when the table is wider than its column. |

Also accepts every native `<table>` attribute.

### TableHeader

No props of its own.

Also accepts every native `<tbody>` attribute.

### TableBody

No props of its own.

Also accepts every native `<tbody>` attribute.

### TableFooter

No props of its own.

Also accepts every native `<tbody>` attribute.

### TableRow

No props of its own.

Also accepts every native `<tr>` attribute.

### TableHead

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `align?` | `"start" \| "end"` | `"start"` | `start` words; `end` figures. |

Also accepts every native HTML attribute.

### TableCell

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `align?` | `"start" \| "end"` | `"start"` | `start` words; `end` figures. |

Also accepts every native HTML attribute.

### TableCaption

No props of its own.

Also accepts every native HTML attribute.

`label` on `Table` names the scrolling box for a screen reader. `align` on `TableHead` and `TableCell` is `start` or `end`. `scope` on `TableHead` is `col` by default and `row` for a row's name. Every native table element's attributes pass through: name the table with `aria-label` or a `TableCaption`.

## Usage

### When to use
- A handful of rows that a person reads whole, in a card, a dialog or a docs page.
- A receipt, a fee breakdown or a list of parameters with columns that line up.

### When not to use
- The rows come from a server, run past 50, or need sorting or filtering. Use DataTable instead.
- The rows describe one thing as label and value pairs. Use DataList instead.
- Each row is a thing to open, with a name and a line about it. Use Item instead.

### Rules
- `rule/table-figures-at-end`: When a column holds figures, set `align="end"` on its `TableHead` and every `TableCell`, because figures compared down a column line up on their last digit only at the end, and tabular figures keep each digit the same width. Evidence: principle platform: tabular figures and end alignment are how a ledger lines up amounts; app 2/2 source apps set amounts at the end, docs/research/2026-10-17-coverage.md section 3. Check: test `table.test.tsx` renders an end cell on one line.
  - Don't: `<TableCell>$318.00</TableCell>`
  - Do: `<TableCell align="end">$318.00</TableCell>`
- `rule/table-row-heads`: When the first cell names its row, such as a charge or a holding, render it as `TableHead scope="row"`, because a screen reader then reads that name before each figure in the row. Evidence: principle wcag: 1.3.1 Info and relationships, a row header is marked as one. Check: test `table.test.tsx` renders `scope="row"` at the body's weight.
  - Don't: `<TableCell>Room, 2 nights</TableCell>`
  - Do: `<TableHead scope="row">Room, 2 nights</TableHead>`
- `rule/table-name-it`: When rendering a `Table`, name it with a `TableCaption` or `aria-label`, and pass `label` when it may scroll, because a table without a name is read as "table" and a scrolling region without a name is a stop that says nothing. Evidence: principle wcag: 1.3.1 Info and relationships; principle wcag: 2.1.1 Keyboard, a scrolling box is reachable. Check: review.
  - Don't: `<Table>`
  - Do: `<Table label="Quarterly figures" aria-label="Quarterly figures">`

### Content
- Follows `rule/writing-no-invented-numbers`.
- `rule/table-say-none`: When a cell has no value, write "None" in it, instead of leaving it blank or writing a dash, because a blank cell reads as still loading and a dash is read aloud as "dash". Evidence: principle heuristic: visibility of system status; single use docs/system/stress/table.tsx:58. Check: review.
  - Don't: `<TableCell>{row.kind}</TableCell>`
  - Do: `<TableCell>{row.kind || "None"}</TableCell>`

### Anti-slop
- `rule/table-no-zebra`: When rows need separating, use the hairlines `TableRow` draws instead of striped rows or a border round every cell, because stripes and grids double the lines the eye reads past to find a figure. Evidence: person D11; principle heuristic: aesthetic and minimalist design. Check: review; lint rule/component-override (scripts/check-system.mjs).
  - Don't: `<TableRow className="odd:bg-muted">`
  - Do: `<TableRow>`

### Limits
- `rule/table-row-count`: When a table runs past 50 rows, use `DataTable` instead, because this table renders every row and has no sort, filter or windowing to find one. Evidence: measured every row in the DOM, 5 of 5 in the worst case, with no windowing, docs/system/stress/table.tsx; person D37. Check: review of every `Table` fed by a list of unknown length.
  - Don't: `<TableBody>{allFilings.map(...)}</TableBody>`
  - Do: `<DataTable rows={allFilings} columns={columns} />`
- `rule/table-columns-in-a-card`: When a table sits in a card on a phone, keep it to 3 columns, because 4 columns needed 261px and the card at 320 gave 192px, so the table scrolled. Evidence: measured the 4-column demo table at 261px inside a 192px card at 320, and in view at 390, docs/system/stress/table.tsx. Check: probe docs/system/stress/table.tsx on the break-ui harness at 320.
  - Don't: four columns, Holding, Kind, Value and Share, in a card at 320
  - Do: three columns, Holding, Value and Share, with the kind in the row head's text

## Accessibility
Rests on the HTML `table`, `caption`, `thead`, `tbody`, `tfoot`, `tr`, `th` and `td`.

### Keyboard
| Key | Where focus is | Effect | Focus after | Checked by |
|---|---|---|---|---|
| Tab | before a table that fits | passes over it to the first link in a cell, if any | that link, or the next focusable element | by hand |
| Tab | before a table that scrolls | focuses the box and shows its ring | the box | by hand |
| Arrow left, arrow right | the scrolling box | scrolls it sideways | stays on the box | by hand |

### ARIA
| Part | Role | Accessible name from | States and properties | Announced | Checked by |
|---|---|---|---|---|---|
| box, scrolling | region | `label`, "Table" if none | `tabIndex` 0 | the name and "region" on focus | by hand |
| table | table | `TableCaption` or `aria-label` | none | the name, the row and column count | test |
| column head | columnheader | its text | `scope="col"` | the head before each cell as you move across | test |
| row head | rowheader | its text | `scope="row"` | the row's name before each figure | test |

## Tokens
| Part | State | Token |
|---|---|---|
| header row | all | `--control-lg`, `--border`, `--muted-foreground` |
| body row | all | `--row`, `--border`, `--foreground` |
| footer | all | `--border`, `--foreground` |
| caption | all | `--muted-foreground` |
| box | focus-visible | `--ring`, `--r-lg` |

## Related
- DataTable: many rows from a server, with sort and filter.
- DataList: label and value pairs about one thing.
- Item: rows a person opens.
- Card: the surface a short table usually sits on.
- Badge: marks one cell with a word, such as a status.
- RelativeTime: how long ago a date was, in a cell.
- MediaTile: things chosen by their photo, laid in a grid.
