---
title: "Tour · Ark UI — StyleX Blocks"
description: "A guided walkthrough that spotlights elements one step at a time with an anchored card."
url: "https://stylexblocks.com/components/ark-ui/tour/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Tour

A guided walkthrough that spotlights elements one step at a time with an anchored card.

- Behavior engine: Ark UI
- Also available for: [Base UI](https://stylexblocks.com/components/base-ui/tour.md), [UI SDK](https://stylexblocks.com/components/ui-sdk/tour.md)
- Category: Feedback
- Sizes: sm, md, lg
- HTML page: https://stylexblocks.com/components/ark-ui/tour/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init
```

Then add the item as source you own:

```sh
npx stylexblocks add tour
```

Equivalent: `npx shadcn add @stylexblocks/tour`. Registry item JSON: https://stylexblocks.com/r/ark-ui/tour.json

## Usage

```tsx
import { Tour, useTour } from "#components/ui/ark-ui/tour.tsx";
import { Button } from "#components/ui/ark-ui/button.tsx";

const steps = [
  {
    id: "search",
    target: () => document.querySelector<HTMLElement>("#search"),
    title: "Find anything",
    description: "Search projects, people, and settings from one place.",
    placement: "bottom-start",
    arrow: true,
    actions: [{ label: "Next", action: "next" }],
  },
  {
    id: "settings",
    target: () => document.querySelector<HTMLElement>("#settings"),
    title: "Make it yours",
    description: "Theme, notifications, and members live here.",
    actions: [
      { label: "Back", action: "prev" },
      { label: "Finish", action: "dismiss" },
    ],
  },
];

export function Example() {
  // The machine scrolls each target into view, spotlights it, and anchors
  // the card next to it. Title/Description fill in from the current step.
  const tour = useTour({ steps });
  return (
    <>
      <Button onClick={() => tour.start()}>Start tour</Button>
      <Tour.Root tour={tour} size="md" lazyMount unmountOnExit>
        <Tour.Portal>
          <Tour.Backdrop />
          <Tour.Spotlight />
          <Tour.Positioner>
            <Tour.Content>
              <Tour.Arrow>
                <Tour.ArrowTip />
              </Tour.Arrow>
              <Tour.Header>
                <Tour.Title />
                <Tour.Description />
              </Tour.Header>
              <Tour.Footer>
                <Tour.ProgressText />
                <Tour.Control>
                  <Tour.Actions>
                    {(actions) =>
                      actions.map((action) => (
                        <Tour.ActionTrigger key={action.label} action={action} asChild>
                          <Button size="xs">{action.label}</Button>
                        </Tour.ActionTrigger>
                      ))
                    }
                  </Tour.Actions>
                </Tour.Control>
              </Tour.Footer>
              <Tour.CloseTrigger>×</Tour.CloseTrigger>
            </Tour.Content>
          </Tour.Positioner>
        </Tour.Portal>
      </Tour.Root>
    </>
  );
}
```

## Source

`components/ui/ark-ui/tour.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { useEffect, useState } from "react";
import { Portal } from "@ark-ui/react/portal";
import { Tour as ArkTour, useTour, useTourContext } from "@ark-ui/react/tour";
import { createSlotRecipeContext } from "#lib/ark-ui/create-slot-recipe-context.tsx";
import { defineSlotRecipe } from "#lib/recipe-props.ts";
import { colorPalette } from '@stylexblocks/ui/color-palette.stylex.ts'
import { durations } from '@stylexblocks/ui/tokens/durations.stylex.ts'
import { fontSizes } from '@stylexblocks/ui/tokens/font-sizes.stylex.ts'
import { fontWeights } from '@stylexblocks/ui/tokens/font-weights.stylex.ts'
import { lineHeights } from '@stylexblocks/ui/tokens/line-heights.stylex.ts'
import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'
import { semanticRadii } from '@stylexblocks/ui/semantic-tokens/radii.stylex.ts'
import { semanticShadows } from '@stylexblocks/ui/semantic-tokens/shadows.stylex.ts'
import { sizes } from '@stylexblocks/ui/tokens/sizes.stylex.ts'
import { spacing } from '@stylexblocks/ui/tokens/spacing.stylex.ts'
import { zIndices } from '@stylexblocks/ui/tokens/z-indices.stylex.ts'

// Every layer stacks on one base: backdrop (+0), spotlight (+1), card (+2).
// The engines set `--tour-layer` per part.
const tourZIndex = `calc(var(--tour-z-index) + var(--tour-layer, 0))`

const tourBackdrop = stylex.create({
  base: {
    '--tour-z-index': zIndices.modal,
    '--tour-layer': 0,
    zIndex: tourZIndex,
    backgroundColor: semanticColors.bgBackdrop,
    // the spotlight hole glides between steps, but tracks scroll and resize
    // instantly (engines flag those updates with data-instant)
    transitionProperty: 'clip-path',
    transitionDuration: {
      default: durations.moderate,
      ':is([data-instant])': '0ms',
    },
    transitionTimingFunction: 'cubic-bezier(0.4, 0, 0.2, 1)',
    animationName: {
      default: null,
      ':is([data-open], [data-state="open"])': 'fade-in',
      ':is([data-closed], [data-state="closed"])': 'fade-out',
    },
    animationDuration: {
      default: null,
      ':is([data-open], [data-state="open"])': durations.moderate,
      ':is([data-closed], [data-state="closed"])': durations.faster,
    },
  },
})

const tourSpotlight = stylex.create({
  base: {
    '--tour-z-index': zIndices.modal,
    '--tour-layer': 1,
    zIndex: tourZIndex,
    boxShadow: `0 0 0 2px ${colorPalette.focusRing}`,
    transitionProperty: 'left, top, width, height',
    transitionDuration: {
      default: durations.moderate,
      ':is([data-instant])': '0ms',
    },
    transitionTimingFunction: 'cubic-bezier(0.4, 0, 0.2, 1)',
  },
})

const tourPositioner = stylex.create({
  base: {
    '--tour-z-index': zIndices.modal,
    '--tour-layer': 2,
    zIndex: tourZIndex,
    // a step without a target is a centered dialog
    position: {
      default: null,
      ':is([data-type="dialog"])': 'fixed',
    },
    inset: {
      default: null,
      ':is([data-type="dialog"])': 0,
    },
    display: {
      default: null,
      ':is([data-type="dialog"])': 'flex',
    },
    alignItems: {
      default: null,
      ':is([data-type="dialog"])': 'center',
    },
    justifyContent: {
      default: null,
      ':is([data-type="dialog"])': 'center',
    },
  },
})

const tourContent = stylex.create({
  base: {
    position: 'relative',
    display: 'flex',
    flexDirection: 'column',
    gap: spacing._3,
    width: 'var(--tour-size)',
    maxWidth: 'calc(100vw - 2rem)',
    padding: 'var(--tour-padding)',
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    '--tour-size': sizes.xs,
    '--tour-radius': semanticRadii.panel,
    '--tour-bg': semanticColors.bgPanel,
    backgroundColor: 'var(--tour-bg)',
    borderRadius: 'var(--tour-radius)',
    boxShadow: semanticShadows.overlay,
    outline: 'none',
    transformOrigin: 'var(--transform-origin)',
    animationName: {
      default: null,
      ':is([data-open], [data-state="open"])': 'scale-in, fade-in',
      ':is([data-closed], [data-state="closed"])': 'scale-out, fade-out',
    },
    animationDuration: {
      default: null,
      ':is([data-open], [data-state="open"])': durations.fast,
      ':is([data-closed], [data-state="closed"])': durations.faster,
    },
  },
})

const tourContentSizes = stylex.create({
  sm: {
    '--tour-padding': spacing._3,
    '--tour-size': sizes.xs,
  },
  md: {
    '--tour-padding': spacing._4,
    '--tour-size': sizes.xs,
  },
  lg: {
    '--tour-padding': spacing._5,
    '--tour-size': sizes.sm,
  },
})

const tourHeader = stylex.create({
  base: {
    display: 'flex',
    flexDirection: 'column',
    gap: spacing._1,
    paddingInlineEnd: spacing._6,
  },
})

const tourTitle = stylex.create({
  base: {
    margin: 0,
    fontSize: fontSizes.md,
    lineHeight: lineHeights.md,
    fontWeight: fontWeights.semibold,
    color: semanticColors.fg,
  },
})

const tourDescription = stylex.create({
  base: {
    margin: 0,
    color: semanticColors.fgMuted,
  },
})

const tourProgressText = stylex.create({
  base: {
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
    fontVariantNumeric: 'tabular-nums',
    color: semanticColors.fgMuted,
  },
})

const tourFooter = stylex.create({
  base: {
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'space-between',
    gap: spacing._3,
    paddingTop: spacing._1,
  },
})

const tourControl = stylex.create({
  base: {
    display: 'flex',
    alignItems: 'center',
    gap: spacing._2,
    marginInlineStart: 'auto',
  },
})

const tourCloseTrigger = stylex.create({
  base: {
    position: 'absolute',
    top: spacing._2_5,
    insetInlineEnd: spacing._2_5,
    display: 'inline-flex',
    alignItems: 'center',
    justifyContent: 'center',
    width: sizes._6,
    height: sizes._6,
    padding: 0,
    borderWidth: 0,
    borderRadius: semanticRadii.control,
    color: semanticColors.fgMuted,
    backgroundColor: {
      default: 'transparent',
      ':hover': semanticColors.bgMuted,
    },
    cursor: 'pointer',
    outlineWidth: {
      default: null,
      ':focus-visible': '2px',
    },
    outlineOffset: {
      default: null,
      ':focus-visible': '1px',
    },
    outlineStyle: {
      default: null,
      ':focus-visible': 'solid',
    },
    outlineColor: {
      default: null,
      ':focus-visible': colorPalette.focusRing,
    },
  },
})

const tourArrow = stylex.create({
  base: {
    '--arrow-size': sizes._3,
    '--arrow-background': 'var(--tour-bg)',
  },
})

const tourArrowTip = stylex.create({
  base: {
    backgroundColor: 'var(--arrow-background)',
  },
})

export type TourSize = keyof typeof tourContentSizes

// defineSlotRecipe validates the shape at compile time: default values must
// exist in the axis maps, and slot keys must be `styles` or a declared axis
const tourRecipe = defineSlotRecipe({
  slots: {
    backdrop: { styles: tourBackdrop },
    spotlight: { styles: tourSpotlight },
    positioner: { styles: tourPositioner },
    content: { styles: tourContent, sizes: tourContentSizes },
    header: { styles: tourHeader },
    title: { styles: tourTitle },
    description: { styles: tourDescription },
    progressText: { styles: tourProgressText },
    footer: { styles: tourFooter },
    control: { styles: tourControl },
    closeTrigger: { styles: tourCloseTrigger },
    arrow: { styles: tourArrow },
    arrowTip: { styles: tourArrowTip },
  },
  defaultVariants: { size: "md" },
});

const { withRootProvider, withContext } = createSlotRecipeContext(tourRecipe);

// Ark positions the backdrop `absolute` with `inset: 0` and cuts the
// spotlight hole with a clip-path in document coordinates, so the backdrop
// must span the whole document, not just the first viewport.
const backdropHeight = stylex.create({
  document: (height: string) => ({ height }),
});

function useDocumentHeight(active: boolean) {
  const [height, setHeight] = useState<number | null>(null);
  useEffect(() => {
    if (!active) return;
    const update = () => setHeight(document.documentElement.scrollHeight);
    update();
    const observer = new ResizeObserver(update);
    observer.observe(document.body);
    window.addEventListener("resize", update);
    return () => {
      observer.disconnect();
      window.removeEventListener("resize", update);
    };
  }, [active]);
  return height;
}

const StyledBackdrop = withContext(ArkTour.Backdrop, "backdrop", "TourBackdrop");

function Backdrop({ style, ...props }: React.ComponentProps<typeof StyledBackdrop>) {
  const tour = useTourContext();
  const height = useDocumentHeight(tour.open);
  return (
    <StyledBackdrop
      {...props}
      // dynamic StyleX styles carry inline values the static prop type omits
      style={
        [height != null && backdropHeight.document(`${height}px`), style] as never
      }
    />
  );
}
Backdrop.displayName = "TourBackdrop";

/**
 * Tour — Ark's tour machine wearing the tour slot recipe. Create the
 * machine with `useTour({ steps })` and pass it to `<Tour.Root tour size>`;
 * the machine scrolls each step's target into view, cuts a spotlight hole
 * in the backdrop, anchors the card next to the target (targetless steps
 * render as a centered dialog), moves focus into the card, and handles
 * Escape, outside clicks, and ←/→ between steps. Steps declare their own
 * `actions` (`next`, `prev`, `dismiss`, `skip`); render them with
 * `Tour.Actions` + `Tour.ActionTrigger` (compose a Button via `asChild`).
 * Render the layers inside `Tour.Portal`.
 */
export const Tour = {
  Root: withRootProvider(ArkTour.Root, "TourRoot"),
  Context: ArkTour.Context,
  Portal,
  Backdrop,
  Spotlight: withContext(ArkTour.Spotlight, "spotlight", "TourSpotlight"),
  Positioner: withContext(ArkTour.Positioner, "positioner", "TourPositioner"),
  Content: withContext(ArkTour.Content, "content", "TourContent"),
  Arrow: withContext(ArkTour.Arrow, "arrow", "TourArrow"),
  ArrowTip: withContext(ArkTour.ArrowTip, "arrowTip", "TourArrowTip"),
  Header: withContext("div", "header", "TourHeader"),
  Title: withContext(ArkTour.Title, "title", "TourTitle"),
  Description: withContext(ArkTour.Description, "description", "TourDescription"),
  ProgressText: withContext(ArkTour.ProgressText, "progressText", "TourProgressText"),
  Footer: withContext("div", "footer", "TourFooter"),
  Control: withContext(ArkTour.Control, "control", "TourControl"),
  CloseTrigger: withContext(ArkTour.CloseTrigger, "closeTrigger", "TourCloseTrigger"),
  Actions: ArkTour.Actions,
  ActionTrigger: ArkTour.ActionTrigger,
};

export { useTour };
```
