Table

Show rows of data in columns, with sticky headers and columns, selectable rows and borders.

React

ProductCategoryPrice
LaptopElectronics$999.99
Coffee makerHome appliances$49.99
Desk chairFurniture$150.00
Total$1,199.98
Prices include tax.

A native <table> with the table recipe on each part. The tables in these docs are this component.

Usage

import { Table } from "@isbatak/react-ui/table"

export function TableDemo() {
  return (
    <Table.Root>
      <Table.Header>
        <Table.Row>
          <Table.ColumnHeader>Product</Table.ColumnHeader>
          <Table.ColumnHeader>Category</Table.ColumnHeader>
          <Table.ColumnHeader textAlign="end">Price</Table.ColumnHeader>
        </Table.Row>
      </Table.Header>
      <Table.Body>
        <Table.Row>
          <Table.Cell>Laptop</Table.Cell>
          <Table.Cell>Electronics</Table.Cell>
          <Table.Cell textAlign="end">$999.99</Table.Cell>
        </Table.Row>
        <Table.Row>
          <Table.Cell>Coffee maker</Table.Cell>
          <Table.Cell>Home appliances</Table.Cell>
          <Table.Cell textAlign="end">$49.99</Table.Cell>
        </Table.Row>
        <Table.Row>
          <Table.Cell>Desk chair</Table.Cell>
          <Table.Cell>Furniture</Table.Cell>
          <Table.Cell textAlign="end">$150.00</Table.Cell>
        </Table.Row>
      </Table.Body>
      <Table.Footer>
        <Table.Row>
          <Table.Cell colSpan={2}>Total</Table.Cell>
          <Table.Cell textAlign="end">$1,199.98</Table.Cell>
        </Table.Row>
      </Table.Footer>
      <Table.Caption>Prices include tax.</Table.Caption>
    </Table.Root>
  )
}
<Table.Root>
  <Table.Header>
    <Table.Row>
      <Table.ColumnHeader />
    </Table.Row>
  </Table.Header>
  <Table.Body>
    <Table.Row>
      <Table.Cell />
    </Table.Row>
  </Table.Body>
  <Table.Footer />
  <Table.Caption />
</Table.Root>

Examples

Sizes

Set size to sm, md or lg to change the text size and row height. The default is md.

SizeText
smExtra small text with tight rows
SizeText
mdSmall text, the default
SizeText
lgMedium text with roomy rows

Borders

Rows have a bottom border by default. Set showColumnBorder to add borders between columns, and showRowBorder={false} to remove the row borders.

RegionQ1Q2
Europe1,2041,388
Americas9801,102
RegionQ1Q2
Europe1,2041,388
Americas9801,102

Interactive

Set interactive to highlight rows on hover and show a pointer. Pass selected to Table.Row to mark a row as selected; it sets aria-selected and uses colorPalette.subtle.

InvoiceCustomerStatus
INV-001AcmePaid
INV-002GlobexPending
INV-003InitechOverdue

Sticky header and columns

Set stickyHeader to keep the header in view while the table scrolls, and highlightedHeader to give it a background. Pass sticky="start" or sticky="end" to Table.ColumnHeader and Table.Cell to pin a column; it fades into the rows it covers and follows the text direction. Put the table in a scroll container, and set --table-sticky-offset when the header should stop below something else, such as a site header.

NameTeamLocationRoleStatus
Ada LovelaceEngineeringLondonLeadActive
Grace HopperPlatformArlingtonPrincipalActive
Alan TuringResearchManchesterFellowAway
Katherine JohnsonAnalyticsHamptonSeniorActive
Linus TorvaldsKernelPortlandMaintainerActive
Margaret HamiltonFlight softwareBostonDirectorAway
Dennis RitchieLanguagesMurray HillStaffActive
Barbara LiskovSystemsCambridgeProfessorActive

Recipe

VariantValuesDefault
sizesm, md, lgmd
showRowBordertrue, falsetrue
showColumnBordertrue, false
interactivetrue
stickyHeadertrue
highlightedHeadertrue
VariableDefaultDescription
--table-border-colorcolors.borderThe row and column border color
--table-row-hover-bgcolors.bg.mutedThe background of a hovered interactive row
--table-row-selected-bgcolorPalette.subtleThe background of a selected row
--table-sticky-offset0How far from the top the sticky header stops