Tour
A guided tour that helps users understand the interface.
Anatomy
const tour = useTour({ steps: [...] })
<Tour.Root tour={tour}>
<Tour.Backdrop />
<Tour.Spotlight />
<Tour.Positioner>
<Tour.Content>
<Tour.Arrow>
<Tour.ArrowTip />
</Tour.Arrow>
<Tour.Title />
<Tour.Description />
<Tour.ProgressText />
<Tour.CloseTrigger />
<Tour.Actions>
<Tour.ActionTrigger />
</Tour.Actions>
</Tour.Content>
</Tour.Positioner>
</Tour.Root>
Examples
Step Types
One tour with dialog steps for welcome and completion, tooltip steps anchored to elements, and floating steps for
fixed-position content.
Progress
Show how far along the user is with a progress bar at the bottom of the content.
Skip
Add a skip action so users can leave the tour at any step.
Keyboard Navigation
Set keyboardNavigation to move between steps with the arrow keys.
Events
Track progress with onStepChange and onStatusChange.
Wait for Click
Use effect with waitForEvent to wait for a user interaction before the next step.
Wait for Input
Wait for valid input before advancing.
Wait for Element
Wait for a dynamically rendered element to appear in the DOM before showing a step.
Async
Load data in effect, then call update() and show() to display the step.
Guides
Step Types
The StepType type defines the available step types:
tooltip: content positioned near the target element.dialog: a modal centered on screen, good for starting or ending the tour. Usually has notarget.floating: a floating element you can position anywhere on screen. Usually has notarget.wait: waits for a condition before moving to the next step.
const steps: TourStepDetails[] = [
{
id: 'step-1',
type: 'tooltip',
placement: 'top-start',
target: () => document.querySelector('#target-1'),
title: 'Tooltip Step',
description: 'This is a tooltip step',
},
{
id: 'step-2',
type: 'dialog',
title: 'Dialog Step',
description: 'This is a dialog step',
},
{
id: 'step-3',
type: 'floating',
placement: 'top-start',
title: 'Floating Step',
description: 'This is a floating step',
},
{
id: 'step-4',
type: 'wait',
title: 'Wait Step',
description: 'This is a wait step',
effect({ next }) {
// do something and go next
// you can also return a cleanup
},
},
]
Actions
Define footer actions for a step with the actions property.
const steps: TourStepDetails[] = [
{
id: 'step-1',
type: 'dialog',
title: 'Dialog Step',
description: 'This is a dialog step',
actions: [{ label: 'Show me a tour!', action: 'next' }],
},
]
Tooltip Placement
Set placement to position a tooltip step.
const steps: TourStepDetails[] = [
{
id: 'step-1',
type: 'tooltip',
placement: 'top-start',
// ...
},
]
Hide Arrow
Set arrow: false to hide the arrow. This only applies to tooltip steps.
const steps: TourStepDetails[] = [
{
id: 'step-1',
type: 'tooltip',
arrow: false,
},
]
Hide Backdrop
Set backdrop: false to hide the backdrop. This applies to every step type except wait.
const steps: TourStepDetails[] = [
{
id: 'step-1',
type: 'dialog',
backdrop: false,
},
]
Effects
A step's effect runs before the step opens. It receives:
next(): moves to the next step.show(): shows the current step.update(details: StepDetails): updates the current step, for example after fetching data.
const steps: TourStepDetails[] = [
{
id: 'step-1',
type: 'tooltip',
effect({ next, show, update }) {
fetchData().then((res) => {
// update the step details
update({ title: res.title })
// then show show the step
show()
})
return () => {
// cleanup fetch data
}
},
},
]
Wait
Wait steps hold the tour until a condition is met. Run your logic in effect, then call next().
Note: You cannot call
show()in a wait step.
const steps: TourStepDetails[] = [
{
id: 'step-1',
type: 'wait',
effect({ next }) {
const button = document.querySelector('#button')
const listener = () => next()
button.addEventListener('click', listener)
return () => button.removeEventListener('click', listener)
},
},
]
Styling
Set box-sizing to border-box so the tour can measure its target.
* {
box-sizing: border-box;
}
Give body a position of relative.
body {
position: relative;
}
API Reference
Props
Root
| Prop | Default | Type |
|---|---|---|
tour | UseTourReturn | |
hideMode | 'display-none' | HideModeHow to hide content when mounted but not present. - `'display-none'`: HTML `hidden` attribute. Effects stay alive. - `'activity'`: React 19 `<Activity mode="hidden">`. Effects pause. Requires React 19+. |
immediate | booleanWhether to synchronize the present change immediately or defer it to the next frame | |
lazyMount | false | booleanWhether to enable lazy mounting |
onEnterComplete | VoidFunctionFunction called when the animation ends in the open state | |
onExitComplete | VoidFunctionFunction called when the animation ends in the closed state | |
present | booleanWhether the node is present (controlled by the user) | |
skipAnimationOnMount | false | booleanWhether to allow the initial presence animation. |
unmountOnExit | false | booleanWhether to unmount on exit. |
ActionTrigger
Defines the <button> element.
| Attribute | Default | Type |
|---|---|---|
action | StepAction | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-tour-action-trigger] | <uid> |
[data-type] | "next" | "previous" | "close" | "skip" | "custom" |
[data-disabled] | Present when disabled |
Arrow
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| CSS Variable | Description |
|---|---|
--arrow-size | The size of the arrow |
--arrow-size-half | Half the size of the arrow |
--arrow-background | Use this variable to style the arrow background |
--arrow-offset | The offset position of the arrow |
ArrowTip
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Backdrop
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<TourBackdropState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-tour-backdrop] | <uid> |
[data-state] | "open" | "closed" |
[data-type] | The type of the item |
[data-instant] |
| CSS Variable | Description |
|---|---|
--tour-layer | The tour layer value for the Backdrop |
--layer-index | The index of the dismissable in the layer stack |
CloseTrigger
Defines the <button> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-tour-close-trigger] | <uid> |
[data-type] | The type of the item |
Content
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<TourContentState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-tour-content] | <uid> |
[data-state] | "open" | "closed" |
[data-type] | The type of the item |
[data-placement] | The placement of the content |
[data-side] | The side of the trigger that the content is positioned on |
[data-step] | |
[data-nested] | popover |
[data-has-nested] | popover |
| CSS Variable | Description |
|---|---|
--layer-index | The index of the dismissable in the layer stack |
--nested-layer-count | The number of nested tours |
Control
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Description
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-tour-description] | <uid> |
[data-placement] | The placement of the description |
[data-side] | The side of the trigger that the description is positioned on |
Positioner
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<TourPositionerState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-tour-positioner] | <uid> |
[data-type] | The type of the item |
[data-placement] | The placement of the positioner |
[data-side] | The side of the trigger that the positioner is positioned on |
[data-instant] |
| CSS Variable | Description |
|---|---|
--tour-layer | The tour layer value for the Positioner |
--reference-width | The width of the reference element |
--reference-height | The height of the root |
--available-width | The available width in viewport |
--available-height | The available height in viewport |
--x | The x position for transform |
--y | The y position for transform |
--transform-origin | The transform origin for animations |
ProgressText
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Spotlight
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<TourSpotlightState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-tour-spotlight] | <uid> |
[data-instant] |
| CSS Variable | Description |
|---|---|
--tour-layer | The tour layer value for the Spotlight |
--spotlight-x | The spotlight x value for the Spotlight |
--spotlight-y | The spotlight y value for the Spotlight |
--spotlight-width | The width of the Spotlight |
--spotlight-height | The height of the Spotlight |
Title
Defines the <h2> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-tour-title] | <uid> |
[data-placement] | The placement of the title |
[data-side] | The side of the trigger that the title is positioned on |
Context
API
| Property | Type |
|---|---|
open | booleanWhether the tour is open |
totalSteps | numberThe total number of steps |
stepIndex | numberThe index of the current step |
step | StepDetails | nullThe current step details |
hasNextStep | booleanWhether there is a next step |
hasPreviousStep | booleanWhether there is a previous step |
firstStep | booleanWhether the current step is the first step |
lastStep | booleanWhether the current step is the last step |
addStep | (step: StepDetails) => voidAdd a new step to the tour |
removeStep | (id: string) => voidRemove a step from the tour |
updateStep | (id: string, stepOverrides: Partial<StepDetails>) => voidUpdate a step in the tour with partial details |
setSteps | (steps: StepDetails[]) => voidSet the steps of the tour |
setStep | (id: string) => voidSet the current step of the tour |
start | (id?: string) => voidStart the tour at a specific step (or the first step if not provided) |
isValidStep | (id: string) => booleanCheck if a step is valid |
isCurrentStep | (id: string) => booleanCheck if a step is visible |
next | VoidFunctionMove to the next step |
previous | VoidFunctionMove to the previous step |
getProgressText | () => stringReturns the progress text |
getProgressPercent | () => numberReturns the progress percent |
getBackdropState | () => BackdropStateReturns the state of the backdrop |
getSpotlightState | () => SpotlightStateReturns the state of the spotlight |
getPositionerState | () => PositionerStateReturns the state of the positioner |
getContentState | () => ContentStateReturns the state of the content |