Tour

A guided tour that helps users understand the interface.

Loading...

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 no target.
  • floating: a floating element you can position anywhere on screen. Usually has no target.
  • 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

PropDefaultType
tour
UseTourReturn

hideMode'display-none'
HideMode

How 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
boolean

Whether to synchronize the present change immediately or defer it to the next frame

lazyMountfalse
boolean

Whether to enable lazy mounting

onEnterComplete
VoidFunction

Function called when the animation ends in the open state

onExitComplete
VoidFunction

Function called when the animation ends in the closed state

present
boolean

Whether the node is present (controlled by the user)

skipAnimationOnMountfalse
boolean

Whether to allow the initial presence animation.

unmountOnExitfalse
boolean

Whether to unmount on exit.

ActionTrigger

Defines the <button> element.

AttributeDefaultType
action
StepAction

asChild
boolean

Use 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.

AttributeDescription
[data-tour-action-trigger]<uid>
[data-type]"next" | "previous" | "close" | "skip" | "custom"
[data-disabled]Present when disabled

Arrow

Defines the <div> element.

AttributeDefaultType
asChild
boolean

Use 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 VariableDescription
--arrow-sizeThe size of the arrow
--arrow-size-halfHalf the size of the arrow
--arrow-backgroundUse this variable to style the arrow background
--arrow-offsetThe offset position of the arrow

ArrowTip

Defines the <div> element.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[data-tour-backdrop]<uid>
[data-state]"open" | "closed"
[data-type]The type of the item
[data-instant]
CSS VariableDescription
--tour-layerThe tour layer value for the Backdrop
--layer-indexThe index of the dismissable in the layer stack

CloseTrigger

Defines the <button> element.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[data-tour-close-trigger]<uid>
[data-type]The type of the item

Content

Defines the <div> element.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[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 VariableDescription
--layer-indexThe index of the dismissable in the layer stack
--nested-layer-countThe number of nested tours

Control

Defines the <div> element.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[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.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[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 VariableDescription
--tour-layerThe tour layer value for the Positioner
--reference-widthThe width of the reference element
--reference-heightThe height of the root
--available-widthThe available width in viewport
--available-heightThe available height in viewport
--xThe x position for transform
--yThe y position for transform
--transform-originThe transform origin for animations

ProgressText

Defines the <div> element.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[data-tour-spotlight]<uid>
[data-instant]
CSS VariableDescription
--tour-layerThe tour layer value for the Spotlight
--spotlight-xThe spotlight x value for the Spotlight
--spotlight-yThe spotlight y value for the Spotlight
--spotlight-widthThe width of the Spotlight
--spotlight-heightThe height of the Spotlight

Title

Defines the <h2> element.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[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

PropertyType
open
boolean

Whether the tour is open

totalSteps
number

The total number of steps

stepIndex
number

The index of the current step

step
StepDetails | null

The current step details

hasNextStep
boolean

Whether there is a next step

hasPreviousStep
boolean

Whether there is a previous step

firstStep
boolean

Whether the current step is the first step

lastStep
boolean

Whether the current step is the last step

addStep
(step: StepDetails) => void

Add a new step to the tour

removeStep
(id: string) => void

Remove a step from the tour

updateStep
(id: string, stepOverrides: Partial<StepDetails>) => void

Update a step in the tour with partial details

setSteps
(steps: StepDetails[]) => void

Set the steps of the tour

setStep
(id: string) => void

Set the current step of the tour

start
(id?: string) => void

Start the tour at a specific step (or the first step if not provided)

isValidStep
(id: string) => boolean

Check if a step is valid

isCurrentStep
(id: string) => boolean

Check if a step is visible

next
VoidFunction

Move to the next step

previous
VoidFunction

Move to the previous step

getProgressText
() => string

Returns the progress text

getProgressPercent
() => number

Returns the progress percent

getBackdropState
() => BackdropState

Returns the state of the backdrop

getSpotlightState
() => SpotlightState

Returns the state of the spotlight

getPositionerState
() => PositionerState

Returns the state of the positioner

getContentState
() => ContentState

Returns the state of the content