UI.MD

Table

A responsive data table with sortable columns, per-column alignment, numeric formatting, and content-sized columns by default. Align by content type: text left, magnitudes right (numeric), identifier numbers (IDs/SKUs) left, row actions in a dedicated trailing Actions column, and icon-only data right or center. Defaults to auto-layout: columns size to their content, visual rhythm comes from consistent cell padding. Opt into layout="fixed" when you need predictable widths.

Installation

$
npx shadcn@latest add https://ui.mattdowney.com/r/table.json

Usage

import {
  Table, TableHeader, TableBody, TableHead, TableRow, TableCell,
} from "@/components/ui/table"

Examples

Default

ProductPriceSalesRevenue
Super Life$29847$24,563
Super Work$29623$18,067
Super Budget$191,204$22,876
Super Goals$19956$18,164

Compact

One type step down with tightened cells. Use for dense reference and spec tables where scan speed matters more than reading comfort.

ProductPriceSalesRevenue
Super Life$29847$24,563
Super Work$29623$18,067
Super Budget$191,204$22,876
Super Goals$19956$18,164

Sortable

Click any column header to sort. Click again to reverse direction.

Building AI-Powered Business ToolsPublishedMar 15, 20262,847
The Case for Variable FontsPublishedMar 8, 20261,923
Design Systems That ScaleDraftMar 1, 20260
Typography on the Modern WebPublishedFeb 22, 20263,102
From Figma to CodePublishedFeb 15, 20261,456

Row Actions

Keep the primary action and More trigger visible. Secondary state and destructive actions stay in the menu; deletion opens a confirmation dialog.

IdeaSignalActions
Keep mandatory design rules in the agent's instructionsHigh
Make a knowledge base searchable and actionableHigh
Show intent through small hover-timing detailsMedium

Striped

ProductStatusPriceSalesRevenue
Super LifeActive$29847$24,563
Super WorkActive$29623$18,067
Super BudgetActive$191,204$22,876
Super GoalsDraft$190$0
Super ReadsActive$24412$9,888
Super NotesActive$19738$14,022

With Selected Row

ProductPriceSalesRevenue
Super Life$29847$24,563
Super Work$29623$18,067
Super Budget$191,204$22,876
Super Goals$19956$18,164

API Reference

PropTypeDefaultDescription
layoutTable"auto" | "fixed""auto"Column-sizing strategy: auto sizes columns to their content, fixed honors declared widths and fills the container.
firstColumnWidthTablestring | null"280px"Width of the first column, only applied when layout="fixed"; pass null to disable.
lastColumnWidthTablestring | null"160px"Width of the last column, only applied when layout="fixed"; pass null to disable.
columnCountTablenumber-Overrides the auto-detected column count for fixed layout when children aren't a simple Header > Row > Head tree.
stripedTablebooleanfalseApplies an alternating background to body rows.
densityTable"default" | "compact""default"Row density. compact steps body type down one size and tightens cell padding for dense reference tables.
stickyHeaderTablebooleanfalseFreezes the header row so it stays visible while the body scrolls. Needs a scrolling ancestor with a bounded height; pair with ScrollFade fade="bottom" so a top skim does not fade the frozen header.
surfaceTable"card" | "bare""card"Container chrome. card paints the table's own surface (radius, border, background, shadow). Use bare when the table already sits inside a Card, so you don't nest one card in another.
sortableTableHeadbooleanfalseRenders the header content as a sort button with a direction glyph.
sortedTableHead"asc" | "desc" | falsefalseCurrent sort direction for the column; drives the glyph and aria-sort.
onSortTableHead() => void-Called when a sortable header is clicked.
alignTableHead, TableCell"left" | "center" | "right""left"Column alignment; defaults to "right" when numeric is set.
numericTableHead, TableCellbooleanfalseRight-aligns with tabular-nums for magnitude columns (prices, counts); leave off for identifier numbers like IDs and SKUs.
widthTableHead"label" | "value" | "fill" | "auto" | string-Column width strategy. "label" and "value" apply the proportional spec-table widths (a leading label column, a trailing metric column) under layout="fixed"; "fill" absorbs all remaining space, "auto" shrinks to content, or any explicit CSS width such as "120px" or "20%".