# Table

Semantic table anatomy with a responsive overflow container.

Semantic table anatomy with a responsive overflow container.

```tsx
import { Badge, Table } from "@zentara-co/zenos-ui";

function TableExample() {
  const assets = [
    ["api.zenos-ui.pages.dev", "Production", "Healthy", "success"],
    ["console.zenos-ui.pages.dev", "Production", "Review", "warning"],
    ["worker.staging.local", "Staging", "Paused", "neutral"],
  ] as const;

  return (
    <Table.Root aria-label="Assets" className="min-w-[34rem]">
      <Table.Header>
        <Table.Row>
          <Table.Head scope="col">Asset</Table.Head>
          <Table.Head scope="col">Environment</Table.Head>
          <Table.Head scope="col">Status</Table.Head>
        </Table.Row>
      </Table.Header>
      <Table.Body>
        {assets.map(([asset, environment, status, color]) => (
          <Table.Row key={asset}>
            <Table.Cell className="font-medium">{asset}</Table.Cell>
            <Table.Cell>{environment}</Table.Cell>
            <Table.Cell>
              <Badge variant={color === "neutral" ? "soft" : "default"} color={color}>
                {status}
              </Badge>
            </Table.Cell>
          </Table.Row>
        ))}
      </Table.Body>
    </Table.Root>
  );
}
```

## Import

```tsx
import { Table } from "@zentara-co/zenos-ui";
```

`Table.Root` defaults to `variant="panel"` for a neutral card shell. Use `variant="plain"` when the table sits inside another surface.

## Spacing and typography

Header and data cells share the same comfortable spacing (16px horizontally and 12px vertically) and body-medium typography. Headers add semibold weight to preserve hierarchy. Captions use the same horizontal inset and font size so they align with the table content.

For a denser table, override `Table.Head` and `Table.Cell` with matching padding and typography classes. Keep both parts in sync so column content remains aligned.

## Alignment, footer, and caption

Keep descriptive content aligned to the start. Align numeric columns to the end and use tabular numbers to make comparison easier. A footer summarizes columns; a caption gives the table a concise visible description.

```tsx
import { Table } from "@zentara-co/zenos-ui";

function TableAlignmentExample() {
  const rows = [
    ["API gateway", "12,480", "99.98%", "$184.20"],
    ["Background workers", "8,106", "99.91%", "$96.40"],
    ["Admin console", "2,904", "99.99%", "$42.10"],
  ];

  return (
    <Table.Root aria-label="Service usage" className="min-w-[38rem]">
      <Table.Header>
        <Table.Row>
          <Table.Head scope="col">Service</Table.Head>
          <Table.Head scope="col" className="text-end">
            Requests
          </Table.Head>
          <Table.Head scope="col" className="text-end">
            Availability
          </Table.Head>
          <Table.Head scope="col" className="text-end">
            Cost
          </Table.Head>
        </Table.Row>
      </Table.Header>
      <Table.Body>
        {rows.map(([service, requests, availability, cost]) => (
          <Table.Row key={service}>
            <Table.Cell className="font-medium">{service}</Table.Cell>
            <Table.Cell className="text-end tabular-nums">{requests}</Table.Cell>
            <Table.Cell className="text-end tabular-nums">{availability}</Table.Cell>
            <Table.Cell className="text-end tabular-nums">{cost}</Table.Cell>
          </Table.Row>
        ))}
      </Table.Body>
      <Table.Footer>
        <Table.Row>
          <Table.Cell colSpan={3}>Monthly total</Table.Cell>
          <Table.Cell className="text-end tabular-nums">$322.70</Table.Cell>
        </Table.Row>
      </Table.Footer>
      <Table.Caption>Service usage for September 2026.</Table.Caption>
    </Table.Root>
  );
}
```

## Selected rows

Set `data-selected="true"` for the visual selected state. When row selection is meaningful to assistive technology, also expose `aria-selected` and provide a labeled Checkbox or other selection control in the row.

```tsx
import { Table } from "@zentara-co/zenos-ui";

function TableSelectedRowsExample() {
  return (
    <Table.Root aria-label="Workspace members" className="min-w-[32rem]">
      <Table.Header>
        <Table.Row>
          <Table.Head scope="col">Member</Table.Head>
          <Table.Head scope="col">Role</Table.Head>
          <Table.Head scope="col">Access</Table.Head>
        </Table.Row>
      </Table.Header>
      <Table.Body>
        <Table.Row data-selected="true" aria-selected="true">
          <Table.Cell className="font-medium">Maya Chen</Table.Cell>
          <Table.Cell>Administrator</Table.Cell>
          <Table.Cell>Selected</Table.Cell>
        </Table.Row>
        <Table.Row>
          <Table.Cell className="font-medium">Owen Reed</Table.Cell>
          <Table.Cell>Analyst</Table.Cell>
          <Table.Cell>Available</Table.Cell>
        </Table.Row>
      </Table.Body>
    </Table.Root>
  );
}
```

## Empty and loading states

Table provides semantic markup and styling while the consumer owns data state. Keep empty and loading messages inside the table structure with a cell spanning every column. Mark loading tables as busy and include readable status text.

```tsx
import { Skeleton, Stack, Table } from "@zentara-co/zenos-ui";

function TableEmptyLoadingExample() {
  return (
    <Stack gap="8" className="w-full">
      <Table.Root aria-label="Empty findings">
        <Table.Header>
          <Table.Row>
            <Table.Head scope="col">Finding</Table.Head>
            <Table.Head scope="col">Severity</Table.Head>
          </Table.Row>
        </Table.Header>
        <Table.Body>
          <Table.Row>
            <Table.Cell colSpan={2} className="h-24 text-center text-text-subtle">
              No findings match the current filters.
            </Table.Cell>
          </Table.Row>
        </Table.Body>
      </Table.Root>

      <Table.Root aria-label="Loading assets" aria-busy="true">
        <Table.Header>
          <Table.Row>
            <Table.Head scope="col">Asset</Table.Head>
            <Table.Head scope="col">Status</Table.Head>
          </Table.Row>
        </Table.Header>
        <Table.Body>
          {Array.from({ length: 3 }, (_, index) => (
            <Table.Row key={index}>
              <Table.Cell>
                <Skeleton shape="text" className="w-40" />
              </Table.Cell>
              <Table.Cell>
                <Skeleton className="h-6 w-20" />
              </Table.Cell>
            </Table.Row>
          ))}
        </Table.Body>
        <Table.Caption>Loading assets…</Table.Caption>
      </Table.Root>
    </Stack>
  );
}
```

## Responsive overflow

`Table.Root` automatically renders a horizontal overflow container. Give wide tables an appropriate minimum width so columns remain readable on small screens, and use `containerClassName` to style or constrain that wrapper.

## Anatomy

```text
Table.Root
Table.Header
Table.Body
Table.Footer
Table.Row
Table.Head
Table.Cell
Table.Caption
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| variant | panel \| plain | panel | Neutral card shell or a bare horizontal scroll wrapper. |
| containerClassName | string | — | Classes on the responsive table wrapper. |
| Head.scope | "col" \| "row" \| "colgroup" \| "rowgroup" | — | Associates a native header cell with its data cells. |
| Cell.colSpan / rowSpan | number | — | Native cell spanning behavior. |
| Row.data-selected | "true" \| undefined | — | Applies the visual selected-row treatment. |
| native props | React.TableHTMLAttributes<HTMLTableElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

Table renders native table elements. Use `scope="col"` for column headers and `scope="row"` when a body header identifies its row. Provide a caption or accessible name that describes the data without repeating nearby headings. Preserve table semantics for structured data; use layout primitives for purely visual grids. Sorting, selection, and pagination controls need their own labels and state announcements—the Data Table recipe provides an engine-integrated pattern for those behaviors.

Source: https://zenos-ui.pages.dev/components/table/