---
title: "Table"
description: "A semantic table with a caption and responsive overflow."
---

Interactive preview: https://ui.coderocket.app/docs/components/table

## Usage

Get this component from a [saved library export](/docs/export) or the [connected CLI](/docs/agents). The imports below refer to local files installed in your app.

Import `styles/components.css`, then `styles/theme.css` once. Wrap your app in `ThemeScope` from `components/ui/utils` so typography, focus and overlays share the theme. The [installation guide](/docs/export) covers runtime dependencies and React/Next.js setup.

```tsx
import { Table } from './components/ui/table';

<Table caption="Team members" columns={["Name","Role"]} rows={[["Alex Morgan","Owner"],["Sam Taylor","Developer"]]}/>
```

## Design system

This component consumes your semantic colors, spacing, typography and shape tokens. Import the compiled styles and your theme once as described in [Export](/docs/export).

## Behavior and accessibility

- Provide meaningful labels for interactive controls.
- Connect action callbacks to your application logic.
- Verify keyboard navigation and contrast in your application.

Status: **experimental** during early access. Sample previews do not send emails, process payments or upload files to a service.

## Source and props

This is the exported source, using the same implementation as the editor.

```tsx
"use client";
/* eslint-disable jsx-a11y/no-noninteractive-tabindex -- The named overflow region needs a tab stop for keyboard scrolling. */
import type { ReactNode } from "react";
export function Table({
  caption,
  columns,
  rows,
  loading = false,
  loadingMessage = "Loading records…",
  emptyMessage = "No records yet.",
  getRowKey,
}: {
  caption: string;
  columns: string[];
  rows: ReactNode[][];
  loading?: boolean;
  loadingMessage?: ReactNode;
  emptyMessage?: ReactNode;
  getRowKey?: (row: ReactNode[], index: number) => string | number;
}) {
  return (
    <div
      className="cr-table-scroll"
      role="region"
      aria-label={caption}
      tabIndex={0}
    >
      <table className="cr-table" aria-busy={loading || undefined}>
        <caption>{caption}</caption>
        <thead>
          <tr>
            {columns.map((column, index) => (
              <th key={index} scope="col">
                {column}
              </th>
            ))}
          </tr>
        </thead>
        <tbody>
          {!loading &&
            rows.map((row, index) => (
              <tr key={getRowKey?.(row, index) ?? index}>
                {row.map((value, column) => (
                  <td key={column}>{value}</td>
                ))}
              </tr>
            ))}
          {(loading || !rows.length) && (
            <tr>
              <td colSpan={Math.max(1, columns.length)}>
                {loading ? loadingMessage : emptyMessage}
              </td>
            </tr>
          )}
        </tbody>
      </table>
    </div>
  );
}
```
