---
title: "Table · Ark UI — StyleX Blocks"
description: "Tabular data with line, inset, and outline treatments across three densities."
url: "https://stylexblocks.com/components/ark-ui/table/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Table

Tabular data with line, inset, and outline treatments across three densities.

- Behavior engine: Ark UI
- Also available for: [Base UI](https://stylexblocks.com/components/base-ui/table.md), [UI SDK](https://stylexblocks.com/components/ui-sdk/table.md)
- Category: Display
- Variants: line, inset, outline
- Sizes: sm, md, lg
- HTML page: https://stylexblocks.com/components/ark-ui/table/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init
```

Then add the item as source you own:

```sh
npx stylexblocks add table
```

Equivalent: `npx shadcn add @stylexblocks/table`. Registry item JSON: https://stylexblocks.com/r/ark-ui/table.json

## Usage

```tsx
import { Table } from "#components/ui/ark-ui/table.tsx";

const members = [
  ["Ava Chen", "Design Engineer", "Active"],
  ["Noah Patel", "Frontend Developer", "Active"],
];

export function Example() {
  return (
    // variant/size resolve once on Root; every part inherits them via context
    <Table.Root variant="line" size="md">
      <Table.Header>
        <Table.Row>
          <Table.ColumnHeader>Name</Table.ColumnHeader>
          <Table.ColumnHeader>Role</Table.ColumnHeader>
          <Table.ColumnHeader>Status</Table.ColumnHeader>
        </Table.Row>
      </Table.Header>
      <Table.Body>
        {members.map(([name, role, status]) => (
          <Table.Row key={name}>
            <Table.Cell>{name}</Table.Cell>
            <Table.Cell>{role}</Table.Cell>
            <Table.Cell>{status}</Table.Cell>
          </Table.Row>
        ))}
      </Table.Body>
    </Table.Root>
  );
}

// composition works per part — e.g. link a cell's content:
// <Table.Cell asChild><a href="/members/ava">Ava Chen</a></Table.Cell>
```

## Source

`components/ui/ark-ui/table.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { createSlotRecipeContext } from "#lib/ark-ui/create-slot-recipe-context.tsx";
import { defineSlotRecipe, fromMap } from "#lib/recipe-props.ts";
import { colors } from '@stylexblocks/ui/tokens/colors.stylex.ts'
import { fontSizes } from '@stylexblocks/ui/tokens/font-sizes.stylex.ts'
import { fontWeights } from '@stylexblocks/ui/tokens/font-weights.stylex.ts'
import { lineHeights } from '@stylexblocks/ui/tokens/line-heights.stylex.ts'
import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'
import { sizes } from '@stylexblocks/ui/tokens/sizes.stylex.ts'
import { spacing } from '@stylexblocks/ui/tokens/spacing.stylex.ts'

const tableRoot = stylex.create({
  base: {
    fontVariantNumeric: 'lining-nums tabular-nums',
    borderCollapse: 'collapse',
    width: sizes.full,
    textAlign: 'start',
    verticalAlign: 'top',
  },
})

const tableRootSizes = stylex.create({
  sm: {
    '--table-cell-padding-x': spacing._1,
    '--control-height': sizes.controlSm,
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
  },
  md: {
    '--table-cell-padding-x': spacing._2,
    '--control-height': sizes.controlMd,
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
  },
  lg: {
    '--table-cell-padding-x': spacing._4,
    '--control-height': sizes.controlLg,
    fontSize: fontSizes.md,
    lineHeight: lineHeights.md,
  },
})

const tableRootVariants = stylex.create({
  inset: {
    marginInline: 'calc(0px - var(--table-cell-padding-x))',
    width:
      'calc(100% + var(--table-cell-padding-x) + var(--table-cell-padding-x))',
  },
  outline: {
    boxShadow: '0 0 0 1px var(--sui-colors-border)',
    overflow: 'hidden',
  },
})

const tableRow = stylex.create({
  base: {},
})

const tableRowVariants = stylex.create({
  line: {
    backgroundColor: 'transparent',
  },
  inset: {
    backgroundColor: 'transparent',
  },
  outline: {},
})

const tableRowStripeds = stylex.create({
  true: {},
})

const tableCell = stylex.create({
  base: {
    textAlign: 'start',
    alignItems: 'center',
  },
})

const tableCellSizes = stylex.create({
  sm: {
    paddingInline: 'var(--table-cell-padding-x)',
    paddingBlock: spacing._1,
  },
  md: {
    paddingInline: 'var(--table-cell-padding-x)',
    paddingBlock: spacing._2,
  },
  lg: {
    paddingInline: 'var(--table-cell-padding-x)',
    paddingBlock: spacing._3,
  },
})

const tableCellVariants = stylex.create({
  line: {
    borderBottomWidth: '1px',
  },
  inset: {
    borderBottomWidth: '1px',
  },
})

const tableCellShowColumnBorders = stylex.create({
  true: {},
})

const tableColumnHeader = stylex.create({
  base: {
    fontWeight: fontWeights.medium,
    textAlign: 'start',
    color: semanticColors.fg,
  },
})

const tableColumnHeaderSizes = stylex.create({
  sm: {
    paddingInline: 'var(--table-cell-padding-x)',
    paddingBlock: spacing._1,
  },
  md: {
    paddingInline: 'var(--table-cell-padding-x)',
    paddingBlock: spacing._2,
  },
  lg: {
    paddingInline: 'var(--table-cell-padding-x)',
    paddingBlock: spacing._3,
  },
})

const tableColumnHeaderVariants = stylex.create({
  line: {
    borderBottomWidth: '1px',
  },
  inset: {
    borderBottomWidth: '1px',
  },
  outline: {
    borderBottomWidth: '1px',
  },
})

const tableColumnHeaderShowColumnBorders = stylex.create({
  true: {},
})

const tableCaption = stylex.create({
  base: {
    fontWeight: fontWeights.medium,
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
  },
})

const tableFooter = stylex.create({
  base: {
    fontWeight: fontWeights.medium,
  },
})

const tableFooterVariants = stylex.create({
  outline: {
    borderTopWidth: '1px',
  },
})

const tableBody = stylex.create({
  base: {},
})

const tableBodyInteractives = stylex.create({
  true: {},
})

const tableHeader = stylex.create({
  base: {},
})

const tableHeaderVariants = stylex.create({
  outline: {
    backgroundColor: semanticColors.bgMuted,
  },
})

const tableHeaderStickyHeaders = stylex.create({
  true: {},
})

export type TableInteractive = keyof typeof tableBodyInteractives

export type TableStickyHeader = keyof typeof tableHeaderStickyHeaders

export type TableStriped = keyof typeof tableRowStripeds

export type TableShowColumnBorder = keyof typeof tableCellShowColumnBorders

export type TableVariant = keyof typeof tableRootVariants

export type TableSize = keyof typeof tableRootSizes

// defineSlotRecipe validates the shape at compile time: default values must
// exist in the axis maps, and slot keys must be `styles` or a declared axis
const tableSlotRecipe = defineSlotRecipe({
  slots: {
    root: {
      styles: tableRoot,
      sizes: tableRootSizes,
      variants: tableRootVariants,
    },
    header: { styles: tableHeader, variants: tableHeaderVariants },
    body: { styles: tableBody },
    row: { styles: tableRow, variants: tableRowVariants },
    columnHeader: {
      styles: tableColumnHeader,
      sizes: tableColumnHeaderSizes,
      variants: tableColumnHeaderVariants,
    },
    cell: { styles: tableCell, sizes: tableCellSizes, variants: tableCellVariants },
    footer: { styles: tableFooter, variants: tableFooterVariants },
    caption: { styles: tableCaption },
  },
  defaultVariants: { variant: "line", size: "md" },
});

/**
 * Table — recipe and component colocated in one file. `<Table.Root variant
 * size>` resolves the recipe once and every part inherits it through
 * context, rendering real `<table>` semantics; each part composes via
 * `asChild`. Sparse variant maps (root styles only inset/outline, header and
 * footer only outline) resolve through explicit resolvers.
 */
const { withProvider, withContext } = createSlotRecipeContext(tableSlotRecipe);

export const Table = {
  Root: withProvider(
    "table",
    (v) => [tableRoot.base, tableRootSizes[v.size], fromMap(tableRootVariants, v.variant)],
    "TableRoot",
  ),
  Header: withContext(
    "thead",
    (v) => [tableHeader.base, v.variant === "outline" && tableHeaderVariants.outline],
    "TableHeader",
  ),
  Body: withContext("tbody", "body", "TableBody"),
  Row: withContext("tr", "row", "TableRow"),
  ColumnHeader: withContext("th", "columnHeader", "TableColumnHeader"),
  Cell: withContext(
    "td",
    (v) => [tableCell.base, tableCellSizes[v.size], fromMap(tableCellVariants, v.variant)],
    "TableCell",
  ),
  Footer: withContext(
    "tfoot",
    (v) => [tableFooter.base, v.variant === "outline" && tableFooterVariants.outline],
    "TableFooter",
  ),
  Caption: withContext("caption", "caption", "TableCaption"),
};
```
