Theme
Customize appearance
Components
Table
Display structured rows and columns with semantic HTML.
View component source ↗Preview
A minimal example to get started.
| Project | Status |
|---|---|
| Design system | Active |
| Website | Draft |
Installation
Install this component and its dependencies in a project initialized with shadcn.
pnpm dlx shadcn@latest add https://ui.hyunjoon.net/r/table.jsonUsage
This is the basic example. Use the Code tab above for the selected example. Adjust import aliases to match your project.
import {
Table,
TableHeader,
TableRow,
TableHead,
TableBody,
TableCell,
TableCaption,
} from "@/components/ui/table";
export default function Example() {
return (
<Table>
<TableCaption>Recent projects in your workspace.</TableCaption>
<TableHeader>
<TableRow>
<TableHead>Project</TableHead>
<TableHead>Status</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<TableRow>
<TableCell>Design system</TableCell>
<TableCell>Active</TableCell>
</TableRow>
<TableRow>
<TableCell>Website</TableCell>
<TableCell>Draft</TableCell>
</TableRow>
</TableBody>
</Table>
);
}
API reference
Derived from the installed component types. Native DOM props are also supported where applicable. A dash means no explicit default is documented. Some props depend on the selected mode.
Table
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLTableElement> | undefinedReact.Ref<HTMLTableElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
defaultChecked | boolean | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLTableElement> | undefinedReact.FocusEventHandler<HTMLTableElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLTableElement> | undefinedReact.FocusEventHandler<HTMLTableElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLTableElement, Element> | undefinedReact.ChangeEventHandler<HTMLTableElement, Element> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLTableElement> | undefinedReact.KeyboardEventHandler<HTMLTableElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLTableElement> | undefinedReact.MouseEventHandler<HTMLTableElement> | undefined | — | Called when the element is activated. |
TableHeader
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLTableSectionElement> | undefinedReact.Ref<HTMLTableSectionElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
defaultChecked | boolean | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLTableSectionElement> | undefinedReact.FocusEventHandler<HTMLTableSectionElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLTableSectionElement> | undefinedReact.FocusEventHandler<HTMLTableSectionElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLTableSectionElement, Element> | undefinedReact.ChangeEventHandler<HTMLTableSectionElement, Element> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLTableSectionElement> | undefinedReact.KeyboardEventHandler<HTMLTableSectionElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLTableSectionElement> | undefinedReact.MouseEventHandler<HTMLTableSectionElement> | undefined | — | Called when the element is activated. |
TableBody
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLTableSectionElement> | undefinedReact.Ref<HTMLTableSectionElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
defaultChecked | boolean | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLTableSectionElement> | undefinedReact.FocusEventHandler<HTMLTableSectionElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLTableSectionElement> | undefinedReact.FocusEventHandler<HTMLTableSectionElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLTableSectionElement, Element> | undefinedReact.ChangeEventHandler<HTMLTableSectionElement, Element> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLTableSectionElement> | undefinedReact.KeyboardEventHandler<HTMLTableSectionElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLTableSectionElement> | undefinedReact.MouseEventHandler<HTMLTableSectionElement> | undefined | — | Called when the element is activated. |
TableFooter
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLTableSectionElement> | undefinedReact.Ref<HTMLTableSectionElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
defaultChecked | boolean | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLTableSectionElement> | undefinedReact.FocusEventHandler<HTMLTableSectionElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLTableSectionElement> | undefinedReact.FocusEventHandler<HTMLTableSectionElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLTableSectionElement, Element> | undefinedReact.ChangeEventHandler<HTMLTableSectionElement, Element> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLTableSectionElement> | undefinedReact.KeyboardEventHandler<HTMLTableSectionElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLTableSectionElement> | undefinedReact.MouseEventHandler<HTMLTableSectionElement> | undefined | — | Called when the element is activated. |
TableHead
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLTableHeaderCellElement> | undefinedReact.Ref<HTMLTableHeaderCellElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
defaultChecked | boolean | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLTableHeaderCellElement> | undefinedReact.FocusEventHandler<HTMLTableHeaderCellElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLTableHeaderCellElement> | undefinedReact.FocusEventHandler<HTMLTableHeaderCellElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLTableHeaderCellElement, Element> | undefinedReact.ChangeEventHandler<HTMLTableHeaderCellElement, Element> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLTableHeaderCellElement> | undefinedReact.KeyboardEventHandler<HTMLTableHeaderCellElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLTableHeaderCellElement> | undefinedReact.MouseEventHandler<HTMLTableHeaderCellElement> | undefined | — | Called when the element is activated. |
TableRow
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLTableRowElement> | undefinedReact.Ref<HTMLTableRowElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
defaultChecked | boolean | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLTableRowElement> | undefinedReact.FocusEventHandler<HTMLTableRowElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLTableRowElement> | undefinedReact.FocusEventHandler<HTMLTableRowElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLTableRowElement, Element> | undefinedReact.ChangeEventHandler<HTMLTableRowElement, Element> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLTableRowElement> | undefinedReact.KeyboardEventHandler<HTMLTableRowElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLTableRowElement> | undefinedReact.MouseEventHandler<HTMLTableRowElement> | undefined | — | Called when the element is activated. |
TableCell
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLTableDataCellElement> | undefinedReact.Ref<HTMLTableDataCellElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
defaultChecked | boolean | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLTableDataCellElement> | undefinedReact.FocusEventHandler<HTMLTableDataCellElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLTableDataCellElement> | undefinedReact.FocusEventHandler<HTMLTableDataCellElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLTableDataCellElement, Element> | undefinedReact.ChangeEventHandler<HTMLTableDataCellElement, Element> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLTableDataCellElement> | undefinedReact.KeyboardEventHandler<HTMLTableDataCellElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLTableDataCellElement> | undefinedReact.MouseEventHandler<HTMLTableDataCellElement> | undefined | — | Called when the element is activated. |
TableCaption
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLElement> | undefinedReact.Ref<HTMLElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
defaultChecked | boolean | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLElement> | undefinedReact.FocusEventHandler<HTMLElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLElement> | undefinedReact.FocusEventHandler<HTMLElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLElement, Element> | undefinedReact.ChangeEventHandler<HTMLElement, Element> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLElement> | undefinedReact.KeyboardEventHandler<HTMLElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLElement> | undefinedReact.MouseEventHandler<HTMLElement> | undefined | — | Called when the element is activated. |
Usage notes
Give columns meaningful headings and add a caption for context. Use Data Table when you need a typed data-driven composition.