# Carousel & guided tour

SvCarousel (sliding track with arrows, dot indicators, autoplay that pauses on hover, and swipe) and SvTour (a guided product tour that spotlights each target element and steps through Back / Next / Done - arrow keys navigate, Escape skips). Both portalled + themeable.

Uses `@svgrid/grid` (MIT). Category: Layout. Live demo: https://svgrid.com/demos/342-carousel-tour/

Install: `npm i @svgrid/grid` (Svelte 5).

## About this example

SvCarousel and SvTour in Svelte 5. The carousel is a sliding track with arrows, dot indicators, autoplay that pauses on hover and swipe support, sized by a slide count; the tour spotlights each target element in turn and steps through Back, Next and Done, with arrow keys to navigate and Escape to skip. Both portal and follow the theme.

SvCarousel (slideshow with arrows, dots, autoplay + swipe) and SvTour (a guided product tour that spotlights elements and steps through them).

## Imports, features and API used

- Imports: `@svgrid/grid`

## Frequently asked questions

### How is autoplay controlled?

autoplay takes the interval in milliseconds and 0 turns it off; the carousel pauses while hovered or focused and resumes after.

### How do I define tour steps?

Each step names a target element selector plus a title and text; the tour scrolls the target into view, dims the page around it and positions the card next to it.

### Can the tour be resumed later?

Yes. Bind the open flag and the current step; storing the step lets you reopen the tour where the user left off.

## Related documentation

- [SvCarousel](https://svgrid.com/docs/help/ui-components/sv-carousel.md)
- [SvTour](https://svgrid.com/docs/help/ui-components/sv-tour.md)

## Related articles

- [Saved Views - Persist Grid Layout and Filters](https://svgrid.com/blog/saved-views-persist-layout/) - Give users named, switchable snapshots of column order, sorting, filters, and grouping - persisted to localStorage or a server adapter - using SvGrid's createNamedViews API.
- [Avoiding Layout Thrash in Custom Grid Cells](https://svgrid.com/blog/avoiding-layout-thrash-custom-cells/) - Layout thrash from interleaved DOM reads and writes is the most common cause of scroll jank in grids with custom cells - here is how to find it and design your way out of it.
- [Column Resizing and Reordering - Let Users Shape the Grid](https://svgrid.com/blog/column-resizing-and-reordering/) - How to wire drag-to-resize and drag-to-reorder in SvGrid, then persist the layout to localStorage so it survives page reloads.

## Source code (342-carousel-tour.svelte)

```svelte
<script lang="ts">
  /**
   * SvCarousel (slideshow with arrows, dots, autoplay + swipe) and SvTour (a
   * guided product tour that spotlights elements and steps through them).
   */
  import { SvCarousel, SvTour, SvButton, type TourStep } from '@svgrid/grid'

  const slides = [
    { title: 'Fast by default', body: 'Virtualized to a million rows.', from: '#2563eb', to: '#7c3aed' },
    { title: 'Themeable', body: '16 presets, light + dark, RTL.', from: '#0891b2', to: '#16a34a' },
    { title: 'Headless-first', body: 'Every editor has a rune-based core.', from: '#d97706', to: '#dc2626' },
    { title: 'AI-native', body: 'MCP server + Studio codegen.', from: '#7c3aed', to: '#2563eb' },
  ]
  let autoplay = $state(true)

  let tourOpen = $state(false)
  const steps: TourStep[] = [
    { target: '#tour-carousel', title: 'A carousel', content: 'Swipe, use the arrows, or let it autoplay. It pauses on hover.' },
    { target: '#tour-autoplay', title: 'Autoplay', content: 'Toggle autoplay on or off here.' },
    { target: '#tour-start', title: 'Start a tour', content: 'This whole walkthrough is a single <SvTour> component.' },
    { title: "That's it", content: 'Tours are great for onboarding new users to a data app.' },
  ]
</script>

<div class="wrap">
  <header>
    <h2>Carousel &amp; tour</h2>
    <p>A slideshow and a guided product tour - both portalled, themeable, keyboard-friendly.</p>
  </header>

  <div id="tour-carousel" class="carousel-box">
    <SvCarousel count={slides.length} autoplay={autoplay ? 3500 : 0}>
      {#snippet slide(i)}
        {@const s = slides[i]}
        <div class="slide" style:background={`linear-gradient(135deg, ${s.from}, ${s.to})`}>
          <div class="slide__title">{s.title}</div>
          <div class="slide__body">{s.body}</div>
        </div>
      {/snippet}
    </SvCarousel>
  </div>

  <div class="bar">
    <label id="tour-autoplay" class="chk"><input type="checkbox" bind:checked={autoplay} /> Autoplay</label>
    <span id="tour-start"><SvButton onclick={() => (tourOpen = true)}>Start tour</SvButton></span>
  </div>
</div>

<SvTour bind:open={tourOpen} {steps} />

<style>
  .wrap { padding: 20px; max-width: 720px; display: flex; flex-direction: column; gap: 16px; }
  header h2 { margin: 0 0 4px; font-size: 20px; font-weight: 700; }
  header p { margin: 0; color: var(--sg-muted, #64748b); font-size: 13.5px; }
  .carousel-box { border: 1px solid var(--sg-border, #e2e8f0); border-radius: 12px; overflow: hidden; }
  .slide { height: 240px; display: flex; flex-direction: column; justify-content: flex-end; gap: 4px; padding: 24px; color: #fff; }
  .slide__title { font-size: 24px; font-weight: 750; }
  .slide__body { font-size: 14px; opacity: 0.92; }
  .bar { display: flex; align-items: center; gap: 16px; }
  .chk { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--sg-muted, #64748b); }
</style>
```

[View this example on GitHub](https://github.com/sv-grid/sv-grid/blob/main/examples/src/demos/342-carousel-tour.svelte)
