shadcn.io is an independent project built on shadcn/ui
On this page9 sections
A tour walks people through a page one step at a time, on a first visit, a redesigned screen or a new feature. A typical step dims the page, outlines one element and explains it in a small panel with Back and Next. UI SDK has no tour component, so this one is built on its popup and focus behaviors.
For a single hint on one control, use a Tooltip or a Popover. An announcement with nothing to point at belongs in a Dialog.
Installation
Anatomy

Usage
<script lang="ts">
import { Button } from "@/components/ui/button"
import {
Tour, TourContent, TourDescription, TourFooter, TourHeader,
TourNextStep, TourPreviousStep, TourProgressText, type TourStepType,
TourTitle, TourTrigger,
} from "@/components/ui/tour"
let installRef = $state<HTMLButtonElement | null>(null)
let usageRef = $state<HTMLDivElement | null>(null)
const steps = $derived.by<TourStepType[]>(() => [
{
actions: [{ action: "next", label: "Start tour" }],
description:
"This walkthrough stays inside the preview. Next steps highlight pieces of this mini app.",
id: "welcome",
title: "Welcome",
type: "dialog",
},
{
actions: [
{ action: "prev", label: "Back" },
{ action: "next", label: "Next" },
],
description: "Use the CLI or a manual install from this control.",
id: "install",
placement: "bottom",
target: () => installRef,
title: "Install",
type: "tooltip",
},
{
actions: [
{ action: "prev", label: "Back" },
{ action: "next", label: "Next" },
],
description:
"Usage notes live next to install so you can copy a snippet.",
id: "usage",
placement: "top",
target: () => usageRef,
title: "Usage",
type: "tooltip",
},
{
actions: [{ action: "dismiss", label: "Done" }],
description:
"The overlay, spotlight, and popover are clipped to this frame.",
id: "done",
title: "That’s it",
type: "dialog",
},
])
</script>
<Tour steps={steps}><div class="flex w-full max-w-lg flex-col overflow-hidden rounded-xl border bg-background shadow-sm"><header class="flex items-center justify-between gap-3 border-b px-3 py-2.5"><span class="font-semibold text-sm">Acme UI</span><div class="flex items-center gap-1"><Button {@attach (node) => { installRef = node as HTMLButtonElement; return () => { installRef = null } }} size="sm" type="button" variant="ghost">Install</Button><TourTrigger>{#snippet render({ props })}<Button {...props} size="sm">Start tour</Button>{/snippet}</TourTrigger></div></header><div class="grid gap-3 p-4 sm:grid-cols-2"><div class="rounded-lg border bg-muted/40 p-3"><p class="font-medium text-sm">Install</p><p class="mt-1 text-muted-foreground text-xs">Add the component with the CLI, then import it.</p></div><div class="rounded-lg border bg-muted/40 p-3" bind:this={usageRef}><p class="font-medium text-sm">Usage</p><p class="mt-1 text-muted-foreground text-xs">Compose steps, then call start() from a trigger.</p></div></div></div><TourContent><TourHeader><TourProgressText /><TourTitle /><TourDescription /></TourHeader><TourFooter><TourPreviousStep /><TourNextStep /></TourFooter></TourContent></Tour>
Accessibility
Each step is a dialog named by its title and described by its description. When the tour starts, focus moves to the step's first button, and when the step changes it stays on the button that moved it, or goes to the first one if that button is gone. The tour doesn't trap focus, so Tab can leave the step for the highlighted element and the rest of the page. The buttons that TourActions, TourPreviousStep and TourNextStep draw are named by the labels they show, and the close button in the corner is announced as Close. When the tour ends, focus goes back to the button that started it.
- Arrow Right
- Moves to the next step in the tour, while focus is in the step and not in a text field. In right-to-left text it moves to the previous step.
- Arrow Left
- Moves to the previous step in the tour, while focus is in the step and not in a text field. In right-to-left text it moves to the next step.
- EscEscape
- Closes the tour.
- Tab
- Moves focus through the step's buttons, then on to the page.
- Shift+Tab
- Moves focus back through the step's buttons, then on to the page.
- Enter
- Presses the focused button, such as Next, Back or Close.
- Space
- Presses the focused button, such as Next, Back or Close.
Demos
Async
The second step fetches a GitHub profile in its effect. The intro dialog stays up while the request runs, then update writes the name, public repo count and follower count into the step and show opens it on the profile card. A failed request shows an error the same way, while closing the tour mid-request aborts the fetch and leaves the tour closed.
Custom spacing
Two dialog steps in a TourContent whose --space variable is set to --spacing(2), half its default of --spacing(4). The variable is the panel's padding, and the footer's inset follows it, so the whole panel tightens. Set it at one size, or per breakpoint for a roomier panel on wide screens.
Events
Three boxes, a Start Tour button and an event log under them. onStepChange adds a line with the step's id each time the tour moves, and onStatusChange adds one when it starts and when it ends. Use these callbacks to remember who finished the tour or to count where people leave it.
Keyboard navigation
keyboardNavigation is set, and a line under the button names the keys: the right arrow moves on, the left arrow goes back and Escape closes. Both are on in every tour unless you set keyboardNavigation or closeOnEscape to false on Tour. The arrows respond while focus is in the step panel.
Progress
Four tooltip steps with a thin bar along the bottom of the panel, filled to getProgressPercent(): 25, 50, 75, then 100 percent. TourProgressText still prints 1 of 4 above the title. The bar is the demo's own element, reading the tour from useTourContext(), so copy it when a count alone feels too abstract for a longer tour.
Skip
The first two steps offer Skip beside Next, and Skip is an action whose action is dismiss, so it closes the tour from wherever someone is. The last step says Finish and dismisses the same way, with Back beside it. Offer a skip when the walkthrough is optional, so nobody has to sit through it to reach the page.
Step types
Two dialog steps, centered with no target, open and close the tour. Between them, a tooltip step points at the Target Element box, and a floating step set to bottom-end sits in that corner of the window without dimming the page or pointing at anything. Pick the type by what the step is about: the whole product, one control, or a passing note.
Wait for click
Add Item, Edit and Delete each get a step with no Next button. Its effect shows the step, waits with waitForEvent for a click on the highlighted button, then calls next. Use this when the lesson is the click itself, and since the tour doesn't trap focus, keyboard users can Tab to the button and press Enter.
Wait for element
Clicking Add Item appends a row, and the next step waits for it: its effect calls waitForElement for an element with data-item set to new and shows the step once the row exists. The previous step stays on screen in the meantime, and if no row appears within five seconds the step calls dismiss. Use this when the next target is created by the step before it.
Wait for input
A short form where the name step moves on once the field holds two characters, and the email step once the value looks like an address. Each listens with waitForEvent for input and checks a predicate, and the terms step outlines the checkbox row until the box is checked. Use it when going on with an empty or invalid value would skip the lesson.
FAQ
How do I build a product tour or onboarding walkthrough in Svelte?
Describe the tour as an array of steps, each with a unique id, a title, a description, a type and the actions its buttons run, and pass it to Tour as steps. Wrap the button that starts it in a TourTrigger, and add a TourContent holding the title, description and buttons, as the Usage section does.
A step of type tooltip also needs a target. To start the tour without a click, on a first visit for example, call handleStart from useTourContext() in a component rendered inside Tour.
How do I highlight a specific element in a Tour step?
Set the step's type to tooltip and give it a target: a function that returns the element, from a ref or a querySelector call. The tour scrolls the element into view, dims the rest of the page around a cut-out, outlines it, and places the panel on the side placement names, which is bottom unless you choose another.
The element stays clickable through the cut-out, and clicking it doesn't close the tour, which is what the Wait for click demo relies on.
What step types does the Tour support?
Four. A dialog step is centered on the page with no target, which suits a welcome or a goodbye. A tooltip step points at its target and outlines it on a dimmed page.
A floating step points at nothing and leaves the page undimmed, as in the Step types demo. Its placement names the corner or edge of the window it sits in, bottom-end unless you choose another, such as top-start or bottom.
The last, wait, shows no panel at all and isn't counted in the progress. Its effect runs until it calls next, which makes it a pause between steps while the page catches up.
How do I wait for the user to click a button before the next Tour step?
Leave out the step's actions and do the waiting in its effect, which receives show, next and the step's target. Call show() to open the step, wait for a click on the target with waitForEvent from components/ui/tour, then call next(). Return the cancel function it gives you, so leaving the step removes the listener.
The Wait for click demo does this three times. waitForEvent also takes a predicate, which Wait for input uses to move on only once a field holds a valid value.
How do I load data before showing a Tour step?
Start the request in the step's effect and call show() once it settles. Until then the previous step stays on screen, so nobody stares at an empty panel. Call update() before show() to give the step a title and description built from the response, as the Async demo does with a GitHub profile.
Return a cleanup function that aborts the request, which runs if someone closes the tour or goes to another step before it settles. Once the step is left, its show() and update() do nothing, so a late failure can't reopen a tour that was just closed. For any other failure, update the step with its own message and call show(), or it never appears.
How do I let users skip or close the Tour?
Add an action whose action is dismiss to each step, labeled Skip, Done or Finish, as the Skip demo does. An action set to skip closes the tour too, and reports skipped rather than dismissed to onStatusChange.
Escape and a click outside the step and its target close the tour as well. To keep it open until someone picks one of its buttons, set closeOnEscape and closeOnInteractOutside to false on Tour.
How do I know when a Tour step changes or the Tour ends?
Pass onStepChange and onStatusChange to Tour, as the Events demo does. onStepChange reports the step's id, index and progress each time the tour moves, and starting again after an earlier run first reports a null id while the old step is cleared. onStatusChange reports started, completed, dismissed, skipped or not-found.
Save completed or dismissed to remember that someone has seen the tour, and don't start it for them again.
Why does my Tour close instead of showing the next step?
The step's target returned nothing. When a step's element isn't in the page, the tour watches for it for three seconds, then ends with the status not-found rather than pointing at empty space. Check that the ref or selector matches an element that is rendered at that moment, not one inside a closed menu or a route that hasn't loaded.
When the element appears only after something happens, wait for it in the step's effect with waitForElement and call show() once it's there, as the Wait for element demo does. Give every step its own id as well, since the tour finds steps by it.
API Reference
Tour
stepsTourStepDetails[]
The steps, read when the tour mounts. Change them later with the tour's
setSteps, addStep, updateStep and removeStep. Two-way with bind:steps.
- Default
[]
onStepsChange?(details: { steps: TourStepDetails[] }) → void
- Type
(details: { steps: TourStepDetails[] }) → void- Parameters
details– { steps: TourStepDetails[] }- Returns
void
closeOnEscape?booleancloseOnInteractOutside?booleandir?"ltr" | "rtl"
The reading direction. Inherits the nearest DirectionProvider when unset.
- Type
"ltr" | "rtl"
ids?object
- Type
{ backdrop?: string; content?: string; description?: string; title?: string }
keyboardNavigation?booleanlazyMount?boolean
Mount the step's parts only once the tour first opens.
- Default
true
onFocusOutside?(event: TourOutsideEvent) → void
Called when focus moves outside it. Prevent its default to keep it open.
- Parameters
event– TourOutsideEvent- Returns
void
onInteractOutside?(event: TourOutsideEvent) → void
Called on any pointer or focus interaction outside it. Prevent its default to keep it open.
- Parameters
event– TourOutsideEvent- Returns
void
onPointerDownOutside?(event: TourOutsideEvent) → void
Called when a pointer goes down outside it. Prevent its default to keep it open.
- Parameters
event– TourOutsideEvent- Returns
void
onStatusChange?(details: TourStatusChangeDetails) → void
- Type
(details: TourStatusChangeDetails) → void- Parameters
details– { status: TourStatus; stepId: string | null; stepIndex: number }- Returns
void
onStepChange?(details: TourStepChangeDetails) → void
- Type
(details: TourStepChangeDetails) → void- Parameters
details– { complete: boolean; progress: number; stepId: string | null; stepIndex: number; totalSteps: number }- Returns
void
preventInteraction?booleanspotlightOffset?{ x: number; y: number }spotlightRadius?numberstepId?string | null
- Type
string | null
translations?object
- Type
{ close?: string; nextStep?: string; prevStep?: string; progressText?: (details: { current: number; total: number }) → string; skip?: string }
unmountOnExit?boolean
Unmount the step's parts once the tour closes; otherwise they stay, hidden.
- Default
true
TourTrigger
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
TourOverlay
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
TourPositioner
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
TourSpotlight
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
TourContent
<div> data-slot="scroll-area"
showCloseButton?boolean
Show close button at the top right corner.
- Default
true
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
data-at-end?string
Present while the view is at the end: the bottom, or the inline end when only the horizontal axis overflows.
data-at-start?string
Present while the view is at the start: the top, or the inline start when only the horizontal axis overflows. Also when nothing overflows.
data-at-x-end?string
Present while the view is at the inline end, within a pixel.
data-at-x-start?string
Present while the view is at the inline start, within a pixel.
data-at-y-end?string
Present while the view is at the bottom, within a pixel.
data-at-y-start?string
Present while the view is at the top, within a pixel.
data-hovering?string
Present while a mouse or pen is over the scroll area.
data-overflow-x?string
Present while the content is wider than the viewport.
data-overflow-y?string
Present while the content is taller than the viewport.
data-scrolling?string
Present while the user scrolls, and for a moment after. Keeping the end in view doesn't count.
data-sticking?string
Present while the view follows the end as content grows, with stickToEnd.
--fade-sizestring--scroll-area-corner-heightstring
The horizontal scrollbar's height while both show, so the vertical one stops short of it. 0px otherwise.
--scroll-area-corner-widthstring
The vertical scrollbar's width while both scrollbars show, so the horizontal one stops short of it. 0px otherwise.
--scroll-area-overflow-x-endstring
How far the content reaches past the inline end, in pixels.
--scroll-area-overflow-x-startstring
How far the content reaches past the inline start, in pixels, left in LTR and right in RTL.
--scroll-area-overflow-y-endstring
How far the content reaches below the view, in pixels.
--scroll-area-overflow-y-startstring
How far the content reaches above the view, in pixels. Grow a top fade or shadow with it. Not inherited, like the other overflow and progress variables, so scrolling never restyles the content. A child of the root that reads it takes it with --scroll-area-overflow-y-start: inherit.
--scroll-area-progress-xstring
How far along the inline axis the view is, from 0 to 1.
--scroll-area-progress-ystring
How far down the view is, from 0 at the top to 1 at the bottom. A reading progress bar can scale with it.
--spacestringTourBody
data-slot="tour-body"
scrollFade?boolean
Add a fade effect to the scroll area.
- Default
false
class?string
Merged with the part's classes.
TourHeader
<div> data-slot="tour-header"
description?string
The description of the step.
title?string
The title of the step.
class?string
Merged with the part's classes.
TourTitle
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
TourDescription
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
TourProgressText
<div> data-slot="tour-progress-text"
class?string
Merged with the part's classes.
TourClose
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
TourActionTrigger
actionobject
The step's action this button runs.
- Type
{ action?: | "next" | "prev" | "dismiss" | "skip" | ((actions: TourStepActionMap) → void); attrs?: Record<string, unknown>; label: string }
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
--spacestringTourFooter
<div> data-slot="tour-control"
class?string
Merged with the part's classes.
TourActions
<div> data-slot="tour-actions"
class?string
Merged with the part's classes.
TourPreviousStep
data-slot="tour-previous-step"
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
TourNextStep
data-slot="tour-next-step"
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>











