# Table

> A semantic data table with header, body, rows and cells.

Use a table for records people compare across columns, such as invoices or members. It is native `<table>` markup with Aloxe styles, so it renders on the server and screen readers navigate it by row and column.

Pro example source is available to licensed users. See [Pro access](/docs/pro/access).

## Installation

Pro components install from the Aloxe registry with the shadcn CLI. Once per project, add the registry to `components.json` and put a [registry token](/account/tokens) in the `ALOXE_TOKEN` environment variable. [Registry](/docs/pro/registry) has the details.

```json
{
  "registries": {
    "@aloxe": {
      "url": "https://<aloxe-site>/r/{name}.json",
      "headers": { "Authorization": "Bearer ${ALOXE_TOKEN}" }
    }
  }
}
```

Then add the component:

```bash
npx shadcn@latest add @aloxe/table
```

The CLI copies the source into `components/ui/aloxe/`, so it never overwrites your own `ui` components. It also installs `@aloxe/react`, `@aloxe/tokens` and `@base-ui/react`.

Import the tokens once in your global stylesheet, after Tailwind, and add an `@source` for the copied files and one for `@aloxe/react`, so Tailwind generates their classes. `@source` paths are relative to the stylesheet; these assume `src/app/globals.css` and `src/components/ui/aloxe/`.

```css
@import "tailwindcss";
@import "@aloxe/tokens/aloxe.css";
@import "@aloxe/tokens/tailwind.css";
@source "../components/ui/aloxe";
@source "../../node_modules/@aloxe/react/dist";
```

[Installation](/docs/getting-started/installation) covers the theme and brand attributes.

## Usage

```tsx
import { Table, TableBody, TableCell, TableHeader, TableRow } from "@/components/ui/aloxe/table";

<Table>
  <caption>Invoices issued this quarter</caption>
  <TableHeader>
    <TableRow>
      <TableCell header>Client</TableCell>
      <TableCell header numeric>Amount</TableCell>
    </TableRow>
  </TableHeader>
  <TableBody>
    <TableRow>
      <TableCell>Northwind Studio</TableCell>
      <TableCell numeric>€1,240.00</TableCell>
    </TableRow>
  </TableBody>
</Table>
```

Name the table with a `<caption>` (visually hidden, read out) or `aria-label`. Use `header` cells in `TableHeader`, and `numeric` on every cell of a column of amounts, counts or dates so the figures line up.

The table sits in a scroll container with a hairline border, so a wide table scrolls sideways on a small screen instead of widening the page.

## Examples

### Selection

`selected` gives a row the accent subtle background. It is visual only: put a `Checkbox` in the row so keyboard and screen reader users can select it, and a header checkbox that shows the mixed state.

Pro example source is available to licensed users. See [Pro access](/docs/pro/access).

### Loading and empty

While data loads, keep the header and fill the rows with [skeletons](/docs/components/skeleton) the width of the data, so nothing shifts when it arrives. With no rows, span one cell across the table and put an [empty state](/docs/components/empty-state) in it.

Pro example source is available to licensed users. See [Pro access](/docs/pro/access).

## Accessibility

| Key | Action |
| --- | --- |
| Tab and Shift+Tab | Move between the interactive elements in the table, such as checkboxes and links. Rows and cells aren't tab stops. |
| Space | Toggles the focused row checkbox. |

- Native table semantics: screen readers announce the column header for each cell and let people move by row and column.
- `TableCell header` renders `<th scope="col">`. Use `scope="row"` on the first cell when it names the row, such as an invoice number.
- Row hover is a visual aid only; never put the only way to an action in a hover state.
- Status in a cell uses a `Badge` with a text label, so it doesn't rely on colour.

## API reference

Every part accepts `className` and renders a `data-aloxe` attribute you can target in CSS, such as `[data-aloxe="table-row"]`. Other props go to the native element.

**Table** (extends <table>)

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `containerClassName` | `string` |  |  | Classes for the scroll container around the table: border, radius, max width or height. |
| `aria-label` | `string` |  |  | Names the table when it has no <caption>. A caption is visually hidden but read out. |
| `className` | `string` |  |  | Classes for the <table> element. |

**TableHeader** (extends <thead>)

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `className` | `string` |  |  | Merged with the default classes (raised surface). |

**TableBody** (extends <tbody>)

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `className` | `string` |  |  | Merged with the default classes. Rows show the hover overlay under the pointer. |

**TableRow** (extends <tr>)

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `selected` | `boolean` | `false` |  | Accent subtle background and data-selected. Visual only: convey selection with a checkbox in the row. |
| `className` | `string` |  |  | Merged with the default classes. |

**TableCell** (extends <td> or <th>)

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `header` | `boolean` | `false` |  | Renders a <th> with Label Sm. Use it in TableHeader, and for the first cell that names a row. |
| `scope` | `"col" \| "row" \| "colgroup" \| "rowgroup"` | `"col"` |  | With header: "row" makes a row header in Label Md and the primary text colour. |
| `numeric` | `boolean` | `false` |  | Right-aligns the cell and uses tabular figures, for amounts, counts and dates. |
| `colSpan` | `number` |  |  | Spans several columns, such as an empty state across the whole table. |
| `className` | `string` |  |  | Merged with the default classes. Add max-w-* and truncate to cut long text. |

## Figma

Matches the **Table** and **Table row** components in the Pro Figma file. Table row `Kind` maps as follows: `Header` is a row in `TableHeader`, `Default` and `Hover` are rows in `TableBody`, `Selected` is `selected`.

See [Figma](/docs/getting-started/figma) for where to get the file and how its names map to code.

## Pro

Table is part of Aloxe Pro. The previews on this page are open to everyone; the Code tab shows the example source once you sign in with a Pro license. See [Access and licenses](/docs/pro/access) and [Pricing](/pricing#pro).
