Display

Table

A plain table that reads well: for a short, fixed set of rows.

Installation

npx sinaui add table

Examples

Basic

Each row starts with its own name, so screen readers say which scholar a cell belongs to. Numbers line up on the right.

Scholars of the Golden Age
NameKnown forWorked inDied (CE)
Al-KhwarizmiMathematicsBaghdad850
Al-KindiPhilosophyBaghdad873
Al-RaziMedicineRayy925
Ibn al-HaythamOpticsCairo1040
Al-BiruniAstronomyGhazni1048
<script lang="ts">
	import Table from '#lib/ui/Table.svelte';

	const scholars = [
		{ name: 'Al-Khwarizmi', field: 'Mathematics', city: 'Baghdad', died: 850 },
		{ name: 'Al-Kindi', field: 'Philosophy', city: 'Baghdad', died: 873 },
		{ name: 'Al-Razi', field: 'Medicine', city: 'Rayy', died: 925 },
		{ name: 'Ibn al-Haytham', field: 'Optics', city: 'Cairo', died: 1040 },
		{ name: 'Al-Biruni', field: 'Astronomy', city: 'Ghazni', died: 1048 }
	];
	const year = new Intl.NumberFormat('en', { useGrouping: false });
</script>

<Table caption="Scholars of the Golden Age">
	<thead>
		<tr>
			<th scope="col">Name</th>
			<th scope="col">Known for</th>
			<th scope="col">Worked in</th>
			<th scope="col" class="num">Died (CE)</th>
		</tr>
	</thead>
	<tbody>
		{#each scholars as s (s.name)}
			<tr>
				<th scope="row">{s.name}</th>
				<td>{s.field}</td>
				<td>{s.city}</td>
				<td class="num">{year.format(s.died)}</td>
			</tr>
		{/each}
	</tbody>
</Table>

With a total

A footer row for totals.

Your loans
WorkVolumesDays left
The Canon of Medicine540
Book of Optics730
Al-Jabr114
Tabula Rogeriana707
Total83
<script lang="ts">
	import Table from '#lib/ui/Table.svelte';

	const loans = [
		{ work: 'The Canon of Medicine', volumes: 5, days: 40 },
		{ work: 'Book of Optics', volumes: 7, days: 30 },
		{ work: 'Al-Jabr', volumes: 1, days: 14 },
		{ work: 'Tabula Rogeriana', volumes: 70, days: 7 }
	];
	const n = new Intl.NumberFormat('en');
	const total = loans.reduce((sum, l) => sum + l.volumes, 0);
</script>

<Table caption="Your loans">
	<thead>
		<tr>
			<th scope="col">Work</th>
			<th scope="col" class="num">Volumes</th>
			<th scope="col" class="num">Days left</th>
		</tr>
	</thead>
	<tbody>
		{#each loans as l (l.work)}
			<tr>
				<th scope="row">{l.work}</th>
				<td class="num">{n.format(l.volumes)}</td>
				<td class="num">{n.format(l.days)}</td>
			</tr>
		{/each}
	</tbody>
	<tfoot>
		<tr>
			<th scope="row">Total</th>
			<td class="num">{n.format(total)}</td>
			<td></td>
		</tr>
	</tfoot>
</Table>

Props

PropTypeDefault
captionstring (required)
hideCaptionbooleanfalse
children<thead>, <tbody>, <tfoot>

Give number cells class="num" to right-align them with even-width digits.

Accessibility

  • A real table: screen readers announce rows and columns and move by cell.
  • The caption names it; use scope="col" for column headings and scope="row" for the cell that names each row.
  • On narrow screens it scrolls sideways inside a focusable region, and the cut-off edge fades.
Introduction
Theming
Changelog
Button
Action button
Confirm button
Copy button
Hold to confirm
Split button
Calendar
Checkbox
Color picker
Combobox
Date picker
Date range picker
File drop
Form
Input
Mention input
Multi select
Number field
OTP input
Password input
Phone input
Radio cards
Radio group
Rich text editor
Search field
Segmented control
Select
Signature pad
Slider
Switch
Tag input
Upload
Wheel picker
Textarea
Time field
Toggle group
Toolbar
Alert dialog
Command palette
Context menu
Dialog
Drawer
Dropdown
Hover card
Popover
Tooltip
Announcement bar
Alert
Empty state
Meter
Progress
Rolling number
Skeleton
Spinner
Toast
Avatar
Avatar group
Badge
Card
Carousel
Chart
Chat
Code block
Data table
Folder
Kbd
Mind map
Resizable panels
Scroll area
Separator
Sortable
Table
Tag group
Virtual list
Audio player
Image
Image compare
Video
Visualizer
Breadcrumb
File tree
Menubar
Navigation menu
Pagination
Sidebar layout
Stepper
Tabs
Alarm clock
Clock
Dynamic island
Fluid orb
Hourglass
Stopwatch
Timer
AI chat
AI media
Auth
Board
Booking
Dashboard
File explorer
Messaging
Notifications
Settings
Team
Overview
Pricing
Agent chat
Calendar
Voice agent
Mail inbox
CMS
Blog
Marketing site
E-commerce
AI agents
SaaS landing page
SaaS app
Accordion
Dark theme
Light theme