Data Display

Table

Composable table semantics, density, and sorting.

import { Table } from '@lostgradient/cinder';
tablegrid
01

Overview

Reference usage

Full data table with header, body, and optional footer for structured tabular content.

See the tabular family boundaries for when to choose Table versus DataTable or DataGrid. Table is the nearest choice when you need custom native-table markup; use DataTable for runtime columns/rows and DataGrid for interactive grid semantics.

Usage

Table is a compound component. Import the parent and compose its leaves via the namespace API: Table.Header, Table.HeaderCell, Table.Body, Table.Row, and Table.Cell.

svelte
<script lang="ts">
  import { Table } from '@lostgradient/cinder';

  const people = [
    { name: 'Ada Lovelace', role: 'Mathematician', commits: 142 },
    { name: 'Grace Hopper', role: 'Computer Scientist', commits: 98 },
  ];
</script>

<Table caption="Recent contributors">
  <Table.Header>
    <Table.Row>
      <Table.HeaderCell label="Name">Name</Table.HeaderCell>
      <Table.HeaderCell label="Role">Role</Table.HeaderCell>
      <Table.HeaderCell label="Commits" align="right">Commits</Table.HeaderCell>
    </Table.Row>
  </Table.Header>
  <Table.Body>
    {#each people as person (person.name)}
      <Table.Row>
        <Table.Cell>{person.name}</Table.Cell>
        <Table.Cell>{person.role}</Table.Cell>
        <Table.Cell align="right">{person.commits}</Table.Cell>
      </Table.Row>
    {/each}
  </Table.Body>
</Table>

A table scrolls by default. The Table root stays a native <table>; Cinder generates a focusable .cinder-table-scroll wrapper that owns the frame (the border, the radius and the clip) and the horizontal overflow, with a visible scrollbar and a fade at the inline end, so the page never scrolls sideways. The frame is the GroupedList's surface: the raised fill, no visible border, the surface radius, and a 16px inset on each row's first and last cells. The wrapper's width is always its container's, never its table's, so a table in a grid or flex column scrolls inside its frame rather than widening the column. Use scrollContainerProps to label, style, or override attributes on that generated wrapper. When stickyHeader is set, the generated wrapper is the sticky header's scroll container; set a bounded block size on scrollContainerProps when the table should scroll vertically inside that wrapper.

Set current on the row that belongs to an open review or detail pane. Current rows use an 18% tint of --cinder-accent-solid in both table and stacked card layouts, including on hover. An open DataTable row shares this tint.

Theme column headers

Use the --cinder-table-header-* tokens on an ancestor to style the column headings independently of the body. The header background paints over the table’s existing header surface, so a sticky header keeps its backdrop when you use a translucent color. Use the padding tokens for the table’s density. The selection cell keeps padding sized for its checkbox. Table header tokens

Tables with controls

A table whose cells hold controls (a select, a switch, a checkbox, a button) stacks instead of scrolling. Set controls on every cell in a column of controls, and controls="fit" for a control that keeps its own size. Below stackBelow (640px), measured on the table's own container, each row becomes a card with the name and its muted detail on the first line and the controls full width at 44px beneath.

svelte
<Table caption="Tool access">
  <Table.Header>
    <Table.Row>
      <Table.HeaderCell label="Tool">Tool</Table.HeaderCell>
      <Table.HeaderCell label="Risk">Risk</Table.HeaderCell>
      <Table.HeaderCell label="On">On</Table.HeaderCell>
      <Table.HeaderCell label="Asks">Asks</Table.HeaderCell>
    </Table.Row>
  </Table.Header>
  <Table.Body>
    {#each tools as tool (tool.id)}
      <Table.Row>
        <Table.Cell as="th">{tool.name}</Table.Cell>
        <Table.Cell>{tool.risk}</Table.Cell>
        <Table.Cell controls="fit"><Checkbox aria-label={`Allow ${tool.name}`} /></Table.Cell>
        <Table.Cell controls>
          <Select id={`asks-${tool.id}`} label={`${tool.name} asks`} options={asks} />
        </Table.Cell>
      </Table.Row>
    {/each}
  </Table.Body>
</Table>

Stacked on the first paint

CSS chooses whether a table stacks, by a size container query on the table's own container, so the HTML a server renders is already the stacked form on a phone, with no script. Every body cell carries its column's label in that HTML, from its header cell's label, so every Table.HeaderCell takes a required label: usually its own text, '' for a column with no name. It is required on every table, because a header cell cannot tell whether its table can stack, and a table may gain fit later. A fit table's card title and empty-cell marks and its table roles are in the server HTML too. A stacked sortable fit table sorts from one control above its cards. The server renders that control before the header cells that list its options, so set sortable on a fit Table with a sortable header cell: the server HTML then holds the control's row, CSS shows it only in the card form, and hydration fills in its options without moving the rows. DataTable sets it from its columns, and a sortable header cell in a fit Table without it warns in development. Script still adds what CSS can't do after hydration: the sort control's options, the sort buttons held out of the tab order, and the title tooltip. A loading row of skeletons takes the stack roles of the row it stands in for, so its lines match when the data arrives. A stackBelow other than the defaults and 640px brings its rules in a small inline <style>, so a page's content security policy must allow inline styles for it.

Telling whether a cell is a stacked title

A fit Table's server HTML marks one cell of each row with data-cinder-stack-title, the cell that is the row's card title if the table stacks: CSS needs the mark on a phone's first paint, and a server cannot know the width, so a wide table carries the marks too. The mark alone does not say the cell is acting as a title. Once script runs, a table that stacks into flat rows carries data-cinder-stack-card on its <table> (and data-cinder-stacked for either stacked form), written from the width of the table's own container, and a wide table carries neither. A cell is a stacked card title when both are there:

ts
const isStackedTitle = (cell: Element) =>
  cell.hasAttribute('data-cinder-stack-title') &&
  cell.closest('table')?.hasAttribute('data-cinder-stack-card') === true;

The table's attributes follow the container as it resizes, so no consumer has to measure the header. They are a hook for scripts and tests, never for layout: before script runs, only the server HTML's marks and the container query decide what is drawn.

The form a table may take

A table's own :has() selectors would restyle every row each time a cell is added to it, about 500 ms for a 150-row event log, so Table writes the form it may take on itself once script runs: data-cinder-stack-form is card for a fit table with no control that fills its cell, control for a fit table with one and for any other table with a controls cell, and none for a table that never stacks. It follows cells as they come and go. The stacking rules read it, and fall back to the same :has() conditions on a table that has no such attribute yet: the server's HTML, and a page that never runs script. Do not set it yourself.

Tables that fit

A records table whose values can be very long (a storage key, a URL, a model identifier) sets fit. The table fills its container with a fixed layout, so a value never widens it: a truncate cell ends its text with an ellipsis at its column's width and keeps the whole value in a tooltip a focus or a hover opens, and every other cell wraps. To size a column whose content never wraps (a status badge, a date, a short identifier with its copy button) by that content, set sizing on its header cell, as the next section shows; <col> widths still set an exact share where one is known. When the columns need more room than a phone has, set a min-inline-size on the table: below that floor the table scrolls inside its frame because of its column count, never because of a value.

svelte
<Table caption="Stored values" fit style="min-inline-size: 24rem">
  <colgroup>
    <col style="width: 75%" />
    <col style="width: 25%" />
  </colgroup>
  <Table.Header>
    <Table.Row>
      <Table.HeaderCell label="Key">Key</Table.HeaderCell>
      <Table.HeaderCell label="Size" align="right">Size</Table.HeaderCell>
    </Table.Row>
  </Table.Header>
  <Table.Body>
    {#each values as value (value.key)}
      <Table.Row>
        <Table.Cell truncate>{value.key}</Table.Cell>
        <Table.Cell align="right">{value.size}</Table.Cell>
      </Table.Row>
    {/each}
  </Table.Body>
</Table>

Below stackBelow a fit table stacks into flat rows. They draw no fill and no frame, so each row starts on the content's leading edge, the same edge as the heading above it, and keeps a small gap at its trailing edge for a control. The hover, open and current tint and a linked row's focus ring reach 12px past the row's start, so the tint never starts at the title's first glyph. The scroll box makes room for that 12px outside the content edge, so nothing clips it.

Short columns sized to their content

By default the columns of a fit table share its width equally, so a one-word status column is as wide as a sentence beside it. Set sizing on each header cell to size the columns by what they hold. A sizing="content" column, for a status word, a badge, an identifier or a count, is as wide as its widest header or cell, never wider than half the table, and its cells never wrap: a value longer than half the table ends in an ellipsis, with the whole value in a tooltip. A cut cell's text and the cell clip with a margin (16px on the text, 10px on the cell), so a link or a button inside, such as a copy button after a value, keeps its touch reach on every side while the text still ends in an ellipsis at its box. A sizing="fill" column, for prose, takes the width the content columns leave and wraps there. Its text runs the full width of the column: a cell holds one finding, not running text, so the prose measure doesn't apply. No width is guessed in advance, so the layout stays right when a badge or a sentence changes length, and the table still never scrolls sideways. DataTable takes the same sizing on a column definition.

svelte
<Table caption="Connection checks" fit>
  <Table.Header>
    <Table.Row>
      <Table.HeaderCell label="Check" sizing="content">Check</Table.HeaderCell>
      <Table.HeaderCell label="Result" sizing="content">Result</Table.HeaderCell>
      <Table.HeaderCell label="What it found" sizing="fill">What it found</Table.HeaderCell>
    </Table.Row>
  </Table.Header>
  <Table.Body>
    {#each checks as check (check.check)}
      <Table.Row>
        <Table.Cell as="th">{check.check}</Table.Cell>
        <Table.Cell><Badge>{check.result}</Badge></Table.Cell>
        <Table.Cell>{check.found}</Table.Cell>
      </Table.Row>
    {/each}
  </Table.Body>
</Table>

The leaves are also named exports of @lostgradient/cinder.

Responsive columns

Set hideBelow on a Table.HeaderCell to hide the header and its body cells when the table container is narrower than 40rem (sm), 56rem (md) or 72rem (lg). The query measures the scroll box, so opening a drawer can hide columns even on a wide viewport. With scrolling disabled, the query measures the table's outer wrapper.

Use showOnly="stacked" for a field that appears only in a stacked row, with its header's label. Use showOnly="table" for a column that appears only in the table form. Table stacks at the same breakpoints as before, and hideBelow leaves stacked fields visible. Cells that span columns keep their existing visibility. DataTable accepts both props on its column definitions.

Stacked card titles and selection

Set labelStackedTitle on a fit Table to show the column's label above each stacked card title. It defaults to false. A selectable card puts the row checkbox at the trailing edge of the title line, with a 44px touch target. The column header's select-all checkbox is hidden in the card layout.

Live preview

Scrollable table

Recent contributors
Name
Role
Commits
Ada Lovelace Mathematician and analytical engine collaborator 142
Grace Hopper Computer scientist, compiler builder, and systems educator 98
Alan Turing Cryptanalyst, logician, and theoretical computer scientist 76

02

When to use

Use when
  • Comparing records in consistent columns.
  • Sharing header sort with sort.
  • Sizing columns to their contents with sizing.
  • Keeping clipped links and buttons reachable by touch.
  • Stacking on first paint using CSS and header labels.
  • Hiding by container width (hideBelow) or form (showOnly) without changing the stacking breakpoint.
  • Opting in to stacked title labels with labelStackedTitle.
  • Selecting stacked cards with a trailing touch target.
Avoid when
  • Rendering a responsive card grid — use grid-list instead.
  • Listing key-value attributes of one entity — use description-list instead.
03

Examples

Scrollable table

Hand-composed cells inside the public horizontal scroll wrapper for dense tables.

Empty table

A table with no body rows still renders the header and caption.

Selectable rows

Table with a select-all checkbox in the header and per-row selection. One row is explicitly disabled from selection.

Sticky sortable header

Sortable columns with stickyHeader={true}. Scroll the table body to verify the focus ring on the sort button is not clipped by the sticky thead.

Table with controls

A table whose cells hold a checkbox and a select. It never scrolls: below 640px of its own width each row becomes a card with the name and its risk on top (the identifier and description, passed as `detail`, are dropped) and the controls at 44px beneath. Asks is disabled while a tool is off.

04

Props

Props for table
Name
Type
Default
Description
sort bindable { /** Column key currently sorted by. */ column: string; /** Direction of the active sort. */ direction: SortDirection; } Bound sort state. When the user activates a sortable header, this prop is updated to reflect the new column / direction. Pass undefined initially when no column is sorted; the component will never write back undefined itself (sort always toggles to a column).
caption text Accessible caption rendered as a <caption> element. It names the table for assistive technology but is visually hidden: the heading above the table already says what it is, and the table draws no title row of its own.
stickyHeader boolean false When true, the header sticks to the top of the scrolling container.
density 'comfortable' | 'condensed' | 'spacious' 'comfortable' Vertical padding density for header and body cells. Defaults to 'comfortable'.
selectable boolean false Enables the leading selection column on the entire table. When true: - The single TableRow inside TableHeader renders a leading <th> with a select-all checkbox sourced from the header's props. - Every TableRow inside TableBody renders a leading selection cell. Selection is strictly controlled — the consumer owns all selection state.
scrollable boolean true Wraps the table in a .cinder-table-scroll box that owns the frame (the border, the radius and the clip) and scrolls sideways when the columns do not fit, with a visible scrollbar and a fade at the inline end. The page never scrolls sideways. Pass false for a table that must lay out as a bare <table>. When combined with stickyHeader, the generated wrapper is the sticky header's scroll container. Set a bounded block size on scrollContainerProps when the table should scroll vertically inside that wrapper.
frameless boolean false Draw no outline, radius or fill around the table, for a queue or list that sits on the page. Rows keep their hairlines.
framed boolean false Keeps the table's own frame inside a Card. Inside a Card a table is frameless by default (the card is the frame; a box inside a box reads as clutter); set this to draw the frame anyway. It changes nothing for a table outside a Card.
fit boolean false Fits the table to its container's width so a long value never makes it scroll sideways. The columns share the width equally (a fixed table layout) unless a header cell sets sizing: a sizing="content" column (a status word, a badge, an identifier, a count) is as wide as its widest value, at most half the table, and does not wrap, and a sizing="fill" column (prose) takes the width the content columns leave. A truncate cell ends its text with an ellipsis at its column's width with the full text in a tooltip, and any other cell wraps its text. A cut cell's text and the cell clip with a margin (16px on the text, 10px on the cell), so a link or a button inside keeps its touch reach on every side while the text still ends in an ellipsis at its box. Leave it off for a table whose columns should keep their natural widths and scroll when they do not fit. A fit table also stacks below stackBelow, as a list of flat rows: the as="th" cell (or the first cell with text) is the title, a cell with stack="end" sits at its inline end, a cell with stack="status" starts the second line, and every other cell is a line of its column's header text and its value. A table with a controls cell that fills its cell keeps the control layout instead.
labelStackedTitle boolean false Shows the column label above each stacked card title.
sortable boolean false Set on a fit table with a sortable header cell. A stacked fit table sorts from one control above its rows, and the server renders that control's row before the header cells it lists, so this prop is how the server knows to keep its place: the first paint already has the row, and hydration fills in its options without moving the rows (COR-2771). DataTable sets it from its columns. A sortable header cell in a fit table without it warns in development.
scrollContainerProps Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' > & { /** Additional class names merged with `.cinder-table-scroll`. */ class?: string; } Attributes forwarded to the generated .cinder-table-scroll wrapper when scrollable is true. The wrapper is focusable by default so keyboard users can scroll read-only wide tables. When the table has a caption, or when aria-label or aria-labelledby is provided here, the wrapper becomes a named region; pass role or tabindex here to override those defaults.
stackBelow text '640px' Width of the table's own container below which a table whose cells hold controls, or a fit table, stacks. With controls, each body row becomes a card: the name and its muted detail on the first line, the controls full width at 44px beneath. A fit table stacks into flat rows (see fit). A table that is neither fit nor holds a controls cell never stacks; it scrolls. The width is the table's own container's (.cinder-table-container, around the scroll box), not the window's, so a table in a narrow column stacks in a wide window. CSS chooses the form, by a size container query, so the server's HTML is already the stacked form on a phone: each body cell carries its column's label (Table.HeaderCell's label), and a fit table's card marks and table roles are in that HTML too. A simple CSS length such as '640px'; the default lengths and '640px' are in Cinder's stylesheet, and any other length brings the same rules in a small <style> beside the table, keyed to that length, so a page's content security policy must allow inline styles for it. false keeps the table layout at every width. A fit table that stacks as flat rows (no cell holds a control that fills it) stacks only below '26rem' (416px) by default, because flat rows read well in a narrow column; the control layout keeps 640px.
children required snippet TableHeader, TableBody, etc.