Tabs

Tabs switch between panels of content. Tabs holds which tab is selected, a Tab selects a panel and a TabPanel holds its content. It follows the WAI-ARIA tabs pattern: the element around the tabs is the tablist, the arrow keys Left and Right move to the previous and next tab and select it, Home and End go to the first and last tab, and only the selected tab is in the tab order. Put the tabs in their own wrapper, not next to the panels.

Default

Give a Tab and its TabPanel the same value, and set selected to the tab to start with. The panel fades in when its tab is selected.

A summary of the project.
svelte
svelte
<Tabs bind:selected>
	<Tab value="overview">Overview</Tab>
	<Tab value="activity">Activity</Tab>
	<Tab value="settings">Settings</Tab>

	<TabPanel value="overview">A summary of the project.</TabPanel>
	<TabPanel value="activity">The latest changes to the project.</TabPanel>
	<TabPanel value="settings">Options for the project.</TabPanel>
</Tabs>

Bound selection

Bind selected to read the active tab or to change it from elsewhere.

Selected tab: overview

A summary of the project.
svelte
svelte
<p>Selected tab: {bound}</p>
<Button onclick={() => (bound = "settings")}>Go to settings</Button>

<Tabs bind:selected={bound}>
	<Tab value="overview">Overview</Tab>
	<Tab value="settings">Settings</Tab>

	<TabPanel value="overview">A summary of the project.</TabPanel>
	<TabPanel value="settings">Options for the project.</TabPanel>
</Tabs>