Table
A component for displaying tabular data with rows and columns.
Anatomy
<script>
import { Table } from "@saas-ui/svelte/components/table";
</script>
<Table.Root>
<Table.Header>
<Table.Row>
<Table.ColumnHeader>Name</Table.ColumnHeader>
<Table.ColumnHeader>Email</Table.ColumnHeader>
</Table.Row>
</Table.Header>
<Table.Body>
<Table.Row>
<Table.Cell>John Doe</Table.Cell>
<Table.Cell>john@example.com</Table.Cell>
</Table.Row>
</Table.Body>
</Table.Root>Examples
Action Bar Accessibility
ActionBar for bulk actions.
<Table.Root size="sm">
<Table.Header>
<Table.Row>
<Table.ColumnHeader class="w-6">
<Checkbox.Root
class="relative top-1"
aria-label="Select all rows"
checked={indeterminate
? "indeterminate"
: selection.length === items.length}
onCheckedChange={() => {
if (selection.length === items.length) {
selection = [];
} else {
selection = items.map((item) => item.name);
}
}}
/>
</Table.ColumnHeader>
<Table.ColumnHeader>Product</Table.ColumnHeader>
<Table.ColumnHeader>Category</Table.ColumnHeader>
<Table.ColumnHeader>Price</Table.ColumnHeader>
</Table.Row>
</Table.Header>
<Table.Body>
{#each items as item (item.id)}
<Table.Row
class={selection.includes(item.name) ? "bg-bg-subtle" : ""}
data-selected={selection.includes(item.name)
? ""
: undefined}
>
<Table.Cell>
<Checkbox.Root
class="relative top-1"
aria-label="Select row"
checked={selection.includes(item.name)}
onCheckedChange={(details) => {
selection = details.checked
? [...selection, item.name]
: selection.filter(
(name) => name !== item.name,
);
}}
/>
</Table.Cell>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.category}</Table.Cell>
<Table.Cell>${item.price}</Table.Cell>
</Table.Row>
{/each}
</Table.Body>
</Table.Root>
<ActionBar open={hasSelection}>
<ActionBarSelectionTrigger>
{selection.length} selected
</ActionBarSelectionTrigger>
<ActionBarSeparator />
<Button variant="outline" size="sm">
Delete <Kbd>⌫</Kbd>
</Button>
<Button variant="outline" size="sm">
Share <Kbd>T</Kbd>
</Button>
</ActionBar> Basic Accessibility
<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>
{#each items as item (item.id)}
<Table.Row>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.category}</Table.Cell>
<Table.Cell textAlign="end">{item.price}</Table.Cell>
</Table.Row>
{/each}
</Table.Body>
</Table.Root> Column Border Accessibility
showColumnBorder prop to show column borders.
<Table.Root size="sm" showColumnBorder>
<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>
{#each items as item (item.id)}
<Table.Row>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.category}</Table.Cell>
<Table.Cell textAlign="end">{item.price}</Table.Cell>
</Table.Row>
{/each}
</Table.Body>
</Table.Root> Column Group Accessibility
Table.ColumnGroup to control column widths.
<Table.Root size="sm" variant="outline">
<Table.ColumnGroup>
<Table.Column htmlWidth="50%" />
<Table.Column htmlWidth="40%" />
<Table.Column />
</Table.ColumnGroup>
<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>
{#each items as item (item.id)}
<Table.Row>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.category}</Table.Cell>
<Table.Cell textAlign="end">{item.price}</Table.Cell>
</Table.Row>
{/each}
</Table.Body>
</Table.Root> Interactive Accessibility
interactive prop to enable row hover effects.
<Table.Root size="sm" interactive>
<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>
{#each items as item (item.id)}
<Table.Row>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.category}</Table.Cell>
<Table.Cell textAlign="end">{item.price}</Table.Cell>
</Table.Row>
{/each}
</Table.Body>
</Table.Root> Overflow Accessibility
Table.ScrollArea for horizontal overflow.
<Table.ScrollArea borderWidth="1px" maxW="36rem" rounded="md">
<Table.Root size="sm" variant="outline" showOuterBorder={false}>
<Table.Header>
<Table.Row>
<Table.ColumnHeader minW="400px">Product</Table.ColumnHeader>
<Table.ColumnHeader minW="400px"
>Category</Table.ColumnHeader>
<Table.ColumnHeader minW="200px" textAlign="end"
>Price</Table.ColumnHeader>
</Table.Row>
</Table.Header>
<Table.Body>
{#each items as item (item.id)}
<Table.Row>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.category}</Table.Cell>
<Table.Cell textAlign="end">{item.price}</Table.Cell>
</Table.Row>
{/each}
</Table.Body>
</Table.Root>
</Table.ScrollArea> Pagination Accessibility
Pagination component.
<VStack gap={5} class="w-full">
<Heading as="h2" size="lg">Products</Heading>
<Table.Root size="sm" variant="outline" striped>
<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>
{#each items as item (item.id)}
<Table.Row>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.category}</Table.Cell>
<Table.Cell textAlign="end">{item.price}</Table.Cell>
</Table.Row>
{/each}
</Table.Body>
</Table.Root>
<Pagination count={25} pageSize={5} size="sm" />
</VStack> Sizes Accessibility
size prop to change the size of the table.
<VStack gap={10}>
{#each tableSizes as size}
<Table.Root {size}>
<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>
{#each items as item (item.id)}
<Table.Row>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.category}</Table.Cell>
<Table.Cell textAlign="end">{item.price}</Table.Cell>
</Table.Row>
{/each}
</Table.Body>
</Table.Root>
{/each}
</VStack> Sticky Header Accessibility
stickyHeader prop to make the header sticky.
<Table.ScrollArea borderWidth="1px" height="160px" rounded="md">
<Table.Root
size="sm"
variant="outline"
showOuterBorder={false}
stickyHeader>
<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>
{#each items as item (item.id)}
<Table.Row>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.category}</Table.Cell>
<Table.Cell textAlign="end">{item.price}</Table.Cell>
</Table.Row>
{/each}
</Table.Body>
</Table.Root>
</Table.ScrollArea> Striped Accessibility
striped prop to add zebra-stripe pattern.
<Table.Root size="sm" striped>
<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>
{#each items as item (item.id)}
<Table.Row>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.category}</Table.Cell>
<Table.Cell textAlign="end">{item.price}</Table.Cell>
</Table.Row>
{/each}
</Table.Body>
</Table.Root> Variants Accessibility
variant prop to change the visual style.
<VStack gap={10}>
{#each tableVariants as variant}
<Table.Root size="sm" {variant}>
<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>
{#each items as item (item.id)}
<Table.Row>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.category}</Table.Cell>
<Table.Cell textAlign="end">{item.price}</Table.Cell>
</Table.Row>
{/each}
</Table.Body>
</Table.Root>
{/each}
</VStack>Props
Table.Root
The main table container.
| Prop | Type | Default | Description |
|---|---|---|---|
size | "sm" | "md" | "lg" | "md" | The size of the table. |
variant | "line" | "outline" | "line" | The visual variant of the table. |
interactive | boolean | false | Enable row hover highlighting. |
stickyHeader | boolean | false | Make the header sticky. |
striped | boolean | false | Add zebra-stripe pattern to rows. |
showColumnBorder | boolean | false | Show borders between columns. |
showOuterBorder | boolean | true | Whether to show the outer border. Set to false when embedded in ScrollArea. |
class | string | undefined | Additional CSS classes to apply. |
children | Snippet | undefined | Table content. |
Table.Header
The table header section (thead).
| Prop | Type | Default | Description |
|---|---|---|---|
class | string | undefined | Additional CSS classes to apply. |
children | Snippet | undefined | Header content. |
Table.Body
The table body section (tbody).
| Prop | Type | Default | Description |
|---|---|---|---|
class | string | undefined | Additional CSS classes to apply. |
children | Snippet | undefined | Body content. |
Table.Footer
The table footer section (tfoot).
| Prop | Type | Default | Description |
|---|---|---|---|
class | string | undefined | Additional CSS classes to apply. |
children | Snippet | undefined | Footer content. |
Table.Row
A table row (tr).
| Prop | Type | Default | Description |
|---|---|---|---|
class | string | undefined | Additional CSS classes to apply. |
children | Snippet | undefined | Row content. |
Table.ColumnHeader
A table column header cell (th).
| Prop | Type | Default | Description |
|---|---|---|---|
textAlign | "start" | "center" | "end" | "start" | Text alignment for the column. |
minW | string | undefined | Minimum width of the column. |
w | string | undefined | Width of the column. |
class | string | undefined | Additional CSS classes to apply. |
children | Snippet | undefined | Header cell content. |
Table.Cell
A table data cell (td).
| Prop | Type | Default | Description |
|---|---|---|---|
textAlign | "start" | "center" | "end" | "start" | Text alignment for the cell. |
class | string | undefined | Additional CSS classes to apply. |
children | Snippet | undefined | Cell content. |
Table.Caption
A table caption element.
| Prop | Type | Default | Description |
|---|---|---|---|
placement | "top" | "bottom" | "bottom" | Placement of the caption. |
class | string | undefined | Additional CSS classes to apply. |
children | Snippet | undefined | Caption content. |
Table.ScrollArea
A scrollable container for the table.
| Prop | Type | Default | Description |
|---|---|---|---|
maxW | string | undefined | Maximum width of the scroll area. |
height | string | undefined | Height of the scroll area. |
borderWidth | string | undefined | Border width for the scroll area. |
rounded | string | undefined | Border radius for the scroll area. |
class | string | undefined | Additional CSS classes to apply. |
children | Snippet | undefined | Scroll area content. |
Table.ColumnGroup
A column group element (colgroup) for defining column widths.
| Prop | Type | Default | Description |
|---|---|---|---|
class | string | undefined | Additional CSS classes to apply. |
children | Snippet | undefined | Column definitions. |
Table.Column
A column element (col) for defining individual column properties.
| Prop | Type | Default | Description |
|---|---|---|---|
htmlWidth | string | undefined | Width of the column (use htmlWidth for HTML table columns). |
class | string | undefined | Additional CSS classes to apply. |