Tour
Show new people around: a spotlight on one part of the page and a short card explaining it, step by step, with Back, Next and Skip. Write it right in your HTML, or start it from code; let it run once and remember it is done.
In HTML
Mark the parts to show, then start the tour from a button. Keys: → next, ← back, Esc to end.
Revenue$4,210
Orders38
Returns2
<div class="border rounded bg-surface p-4 stack gap-4" id="tour-demo">
<div class="cluster gap-3 items-center justify-between">
<input class="form-control w-64" type="search" placeholder="Search" aria-label="Search"
data-momo-tour="welcome" data-momo-tour-order="1"
data-momo-tour-title="Find anything"
data-momo-tour-text="Search orders, customers and products from here.">
<button class="btn btn-brand" type="button"
data-momo-tour="welcome" data-momo-tour-order="2"
data-momo-tour-title="Create an order"
data-momo-tour-text="Phone orders and walk-ins go here."><i class="mi mi-plus"></i> New order</button>
</div>
<div class="grid sm:grid-cols-3 gap-3" data-momo-tour="welcome" data-momo-tour-order="3" data-momo-tour-title="Today at a glance" data-momo-tour-text="Revenue, orders and returns, updated as they happen.">
<div class="stat stat-sm"><span class="stat-label">Revenue</span><span class="stat-value">$4,210</span></div>
<div class="stat stat-sm"><span class="stat-label">Orders</span><span class="stat-value">38</span></div>
<div class="stat stat-sm"><span class="stat-label">Returns</span><span class="stat-value">2</span></div>
</div>
<div class="cluster justify-end">
<button class="btn btn-ghost btn-sm" type="button" data-momo-tour="welcome" data-momo-tour-order="4" data-momo-tour-title="Stuck?" data-momo-tour-text="Help is always one tap away."><i class="mi mi-circle-help"></i> Help</button>
</div>
</div>
<button class="btn mt-3" type="button" data-momo-tour-start="welcome"><i class="mi mi-sparkles"></i> Start the tour</button>Write a tour, step by step
- Mark the parts to show with
data-momo-tour="welcome"(one name per tour) and give each adata-momo-tour-titleand a shortdata-momo-tour-text. - Order them with
data-momo-tour-order="1","2"... (else they follow the page). - Start it from a button with
data-momo-tour-start="welcome", or from code on someone's first visit (below). - Keep it short. Three to five steps about things people need on day one, a sentence or two each. Parts that are hidden on this screen (a sidebar on a phone) are skipped by themselves.
From code, once per person
Give the steps as a list and once a name: the tour starts on the first visit and is remembered as done (in the browser) when it is finished or skipped. start({ force: true }) runs it again, from a Help menu, say. A step without a target is a card in the middle of the screen.
const welcome = Momo.tour([
{ target: '#search', title: 'Find anything', text: 'Search orders, customers and products.' },
{ target: '#new-order', title: 'Create an order', text: 'Phone orders and walk-ins go here.' },
{ title: "You're all set", text: 'Press ? any time to see the keyboard shortcuts.' }, // no target
], { once: 'welcome-v1' });
welcome.start(); // does nothing if it was done before
helpMenu.onclick = () => welcome.start({ force: true });
document.addEventListener('momo:tour-end', (e) => {
if (e.detail.completed) track('tour finished');
});<button class="btn" type="button" id="tour-code"><i class="mi mi-play"></i> Run the coded tour</button>
<script>
document.getElementById('tour-code').addEventListener('click', function () {
Momo.tour([
{ target: '#tour-demo input', title: 'Find anything', text: 'Search orders, customers and products.' },
{ target: '#tour-demo .btn-brand', title: 'Create an order', text: 'Phone orders and walk-ins go here.' },
{ title: "You're all set", text: 'That is the whole tour. Have fun!' },
], { doneLabel: 'Got it' }).start({ force: true });
});
</script>On a phone
The card docks to the bottom of the screen (or the top, when the part is low), out of the way of the spotlight, and takes the full width.
Accessible
- The card is a labelled dialog: screen readers hear the title, the text and "2 of 4". The focus moves into it and Tab stays there.
- → / ← step through, Esc ends it, and the focus goes back where it was.
- Each part scrolls into view before it is shown; with reduced motion nothing slides.
Reference
| Attribute / API | What it does |
|---|---|
data-momo-tour="name" | This part is a step of the tour "name" |
data-momo-tour-title, -text, -order | The card's title, its text, and the step's place |
data-momo-tour-start="name" | A button that starts it (data-momo-tour-once="key": only the first time; data-momo-tour-done="Got it": the last button's label) |
Momo.tour(steps, { once, doneLabel }) | Steps: { target, title, text | html }. Gives start({ force, at }), next(), back(), end(), reset() |
Events (on document) | momo:tour-step { index, step }, momo:tour-end { completed } |