# Table

A semantic data table for rows of comparable values. The parts render the native `<table>`, `<thead>`, `<tbody>`, `<tr>`, `<th>` and `<td>` elements, styled from the tokens. Each is a Box, so cells take Box props such as `textAlign`. Use Grid or Stack for layout, not Table.

```tsx
import { Table, TableBody, TableCell, TableContainer, TableHead, TableHeader, TableRow } from '@blocks/design-system'
```

## Usage

Name the table with a native `<caption>` as its first child. Give column headers `scope="col"`; when the first cell of each row identifies the row, make it a `TableHead` with `scope="row"`. Links inside cells stay ordinary links.

**Example: Holdings** (`examples/table/holdings.tsx`)

```tsx
import {
  Link,
  Table,
  TableBody,
  TableCell,
  TableContainer,
  TableHead,
  TableHeader,
  TableRow,
} from '@blocks/design-system'

const holdings = [
  { symbol: 'VTI', name: 'Vanguard Total Stock Market ETF', shares: 120, price: '$291.40', value: '$34,968.00', change: '+0.8%' },
  { symbol: 'VXUS', name: 'Vanguard Total International Stock ETF', shares: 210, price: '$66.12', value: '$13,885.20', change: '-0.3%' },
  { symbol: 'BND', name: 'Vanguard Total Bond Market ETF', shares: 95, price: '$73.05', value: '$6,939.75', change: '+0.1%' },
]

export default function Holdings() {
  return (
    <TableContainer tabIndex={0} role="region" aria-labelledby="holdings-caption">
      <Table>
        <caption id="holdings-caption">Holdings on December 1, 2026</caption>
        <TableHeader>
          <TableRow>
            <TableHead scope="col">Symbol</TableHead>
            <TableHead scope="col">Name</TableHead>
            <TableHead scope="col" textAlign="right">Shares</TableHead>
            <TableHead scope="col" textAlign="right">Price</TableHead>
            <TableHead scope="col" textAlign="right">Value</TableHead>
            <TableHead scope="col" textAlign="right">Today</TableHead>
          </TableRow>
        </TableHeader>
        <TableBody>
          {holdings.map((holding) => (
            <TableRow key={holding.symbol}>
              <TableHead scope="row">
                <Link href={`#equity-${holding.symbol.toLowerCase()}`} fontSize="sm">{holding.symbol}</Link>
              </TableHead>
              <TableCell>{holding.name}</TableCell>
              <TableCell textAlign="right">{holding.shares}</TableCell>
              <TableCell textAlign="right">{holding.price}</TableCell>
              <TableCell textAlign="right">{holding.value}</TableCell>
              <TableCell textAlign="right">{holding.change}</TableCell>
            </TableRow>
          ))}
        </TableBody>
      </Table>
    </TableContainer>
  )
}
```

## Wide tables

`TableContainer` lets a table scroll sideways inside itself instead of widening the page on a narrow screen. Make it reachable by keyboard: `tabIndex={0}`, `role="region"` and `aria-labelledby` pointing at the caption, as above.

## Empty and loading states

Keep the header row and put the message in a single cell that spans every column, so the table still says what it would hold.

**Example: Empty watchlist** (`examples/table/empty-state.tsx`)

```tsx
import { BodySmall, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@blocks/design-system'

export default function EmptyState() {
  return (
    <Table>
      <caption>Watchlist</caption>
      <TableHeader>
        <TableRow>
          <TableHead scope="col">Symbol</TableHead>
          <TableHead scope="col">Price</TableHead>
        </TableRow>
      </TableHeader>
      <TableBody>
        <TableRow>
          <TableCell colSpan={2} textAlign="center" paddingY="lg">
            <BodySmall margin="none" color="text-muted">
              No equities on your watchlist yet.
            </BodySmall>
          </TableCell>
        </TableRow>
      </TableBody>
    </Table>
  )
}
```

## Parts

| Part | Element |
| --- | --- |
| `Table` | `<table>` |
| `TableContainer` | `<div>` that scrolls horizontally |
| `TableHeader` | `<thead>` |
| `TableBody` | `<tbody>` |
| `TableRow` | `<tr>` |
| `TableHead` | `<th>`, with `scope` |
| `TableCell` | `<td>` |

## Props

**`Table` props**

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `as` | `ElementType` | — | The element or component to render, e.g. `as={NextLink}`. |

Also accepts [Box layout props](https://design-system.blocks-ui.com/components/box.md#props), [styling escape hatches](https://design-system.blocks-ui.com/components/box.md#escape-hatches), [margin props](https://design-system.blocks-ui.com/components/box.md#spacing), [padding props](https://design-system.blocks-ui.com/components/box.md#spacing) and [a ref](https://design-system.blocks-ui.com/components/box.md#refs), and the native attributes of the element it renders.

**`TableContainer` props**

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `as` | `ElementType` | — | The element or component to render, e.g. `as={NextLink}`. |

Also accepts [Box layout props](https://design-system.blocks-ui.com/components/box.md#props), [styling escape hatches](https://design-system.blocks-ui.com/components/box.md#escape-hatches), [margin props](https://design-system.blocks-ui.com/components/box.md#spacing), [padding props](https://design-system.blocks-ui.com/components/box.md#spacing) and [a ref](https://design-system.blocks-ui.com/components/box.md#refs), and the native attributes of the element it renders.

**`TableHeader` props**

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `as` | `ElementType` | — | The element or component to render, e.g. `as={NextLink}`. |

Also accepts [Box layout props](https://design-system.blocks-ui.com/components/box.md#props), [styling escape hatches](https://design-system.blocks-ui.com/components/box.md#escape-hatches), [margin props](https://design-system.blocks-ui.com/components/box.md#spacing), [padding props](https://design-system.blocks-ui.com/components/box.md#spacing) and [a ref](https://design-system.blocks-ui.com/components/box.md#refs), and the native attributes of the element it renders.

**`TableBody` props**

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `as` | `ElementType` | — | The element or component to render, e.g. `as={NextLink}`. |

Also accepts [Box layout props](https://design-system.blocks-ui.com/components/box.md#props), [styling escape hatches](https://design-system.blocks-ui.com/components/box.md#escape-hatches), [margin props](https://design-system.blocks-ui.com/components/box.md#spacing), [padding props](https://design-system.blocks-ui.com/components/box.md#spacing) and [a ref](https://design-system.blocks-ui.com/components/box.md#refs), and the native attributes of the element it renders.

**`TableRow` props**

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `as` | `ElementType` | — | The element or component to render, e.g. `as={NextLink}`. |

Also accepts [Box layout props](https://design-system.blocks-ui.com/components/box.md#props), [styling escape hatches](https://design-system.blocks-ui.com/components/box.md#escape-hatches), [margin props](https://design-system.blocks-ui.com/components/box.md#spacing), [padding props](https://design-system.blocks-ui.com/components/box.md#spacing) and [a ref](https://design-system.blocks-ui.com/components/box.md#refs), and the native attributes of the element it renders.

**`TableHead` props**

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `as` | `ElementType` | — | The element or component to render, e.g. `as={NextLink}`. |

Also accepts [Box layout props](https://design-system.blocks-ui.com/components/box.md#props), [styling escape hatches](https://design-system.blocks-ui.com/components/box.md#escape-hatches), [margin props](https://design-system.blocks-ui.com/components/box.md#spacing), [padding props](https://design-system.blocks-ui.com/components/box.md#spacing) and [a ref](https://design-system.blocks-ui.com/components/box.md#refs), and the native attributes of the element it renders.

**`TableCell` props**

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `as` | `ElementType` | — | The element or component to render, e.g. `as={NextLink}`. |

Also accepts [Box layout props](https://design-system.blocks-ui.com/components/box.md#props), [styling escape hatches](https://design-system.blocks-ui.com/components/box.md#escape-hatches), [margin props](https://design-system.blocks-ui.com/components/box.md#spacing), [padding props](https://design-system.blocks-ui.com/components/box.md#spacing) and [a ref](https://design-system.blocks-ui.com/components/box.md#refs), and the native attributes of the element it renders.

## Accessibility

- A caption names the table for screen readers and everyone else; prefer it to a nearby heading.
- `scope` tells assistive technology which cells a header describes. Without it, reading a cell gives no context.
- Sorting controls belong in a button inside the header cell, not on the cell itself, so they are focusable and announced.
