Skip to content

shadcn.io is an independent project built on shadcn/ui

Free

Basic Table for Svelte

A bordered table of people with Name, Email, Location, Status and Balance. John Doe is the first row, in New York.

UI library: Ark UI

A bordered table lists people. The columns are Name, Email, Location, Status and Balance. John Doe is first, in New York, Active, with a balance.

Use a plain table for a short list of records, such as users. A Data List fits the same pairs if each record is a label and a value. In Svelte, Ark UI does not sort the rows.

Preview

Preview width

Installation

MCP · Pro
Make your AI a shadcn expert
Your agent installs components, builds pages and restyles your app from one prompt, in Claude Code, Cursor or VS Code.
Part of Pro

Anatomy

Table anatomy: header, head, row, cell, footer, caption

Usage

<div class="w-full max-w-4xl rounded-md border bg-background"><Table><TableHeader><TableRow><TableHead>Name</TableHead><TableHead>Email</TableHead><TableHead>Location</TableHead><TableHead>Status</TableHead><TableHead class="text-end">Balance</TableHead></TableRow></TableHeader><TableBody>{#each users as user (user.email)}<TableRow><TableCell class="font-medium">{user.name}</TableCell><TableCell>{user.email}</TableCell><TableCell>{user.location}</TableCell><TableCell>{user.status}</TableCell><TableCell class="text-end">{user.balance}</TableCell></TableRow>{/each}</TableBody></Table></div>

FAQ

Which parts make up this table?

Table renders the <table>. TableHeader holds the label row, TableBody holds the records, and each person is a TableRow of TableCells. The demo maps the users array into four rows.

How is the balance column aligned?

text-end on the Balance TableHead and on each balance TableCell lines the amounts up on the trailing edge. Name, email, location and status stay at the start.

Why is the name medium weight?

font-medium on the name TableCell makes the person the row's label. Every cell inherits the table's text-sm.

What is the row key?

Each TableRow uses user.email as its key. The emails in this array are unique, so a row keeps its identity when the list renders again.

Where do the border and the scrolling come from?

The outer div is max-w-4xl rounded-md border bg-background. Table adds its own container with overflow-x-auto, and cells are whitespace-nowrap, so the five columns scroll sideways when the frame is narrow.

Do the rows have dividers and a hover state?

Yes. TableRow draws a bottom border and hover:bg-muted/50. TableHeader separates the labels, and the last body row drops its border.

API Reference

Table

No extra props in this demo. The rest is on the Table page.