Coachmark
One step of a tour, pointing at the control it explains.
On this page
A coachmark is one step of a tour: a small card of ink that points at a control and says what it does. It is a popover, so the browser holds it in the top layer and moves focus into it, and CSS anchor positioning places it against the element that opened it, with an arrow that points there. A beacon, a dot of ink that sends out a ring now and then, marks the place on the page and is the button that opens it. A tour opens several in turn, with the tour behavior.
Coachmark
<div class="toolbar" role="toolbar" aria-label="Deployments"> <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Search"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="7" cy="7" r="4.5" /><path d="M10.182 10.182L14 14" /> </svg> </button> <span class="relative inline-flex"> <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Filter"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4.5365 3L11.4635 3A1 1 0 0 1 12.2548 4.6114L9.4587 8.2299A1 1 0 0 0 9.25 8.8413L9.25 11.323A1 1 0 0 1 8.6214 12.2514L7.875 12.55A0.8203 0.8203 0 0 1 6.75 11.7883L6.75 8.8413A1 1 0 0 0 6.5413 8.2299L3.7452 4.6114A1 1 0 0 1 4.5365 3Z" /> </svg> </button> <button type="button" class="coachmark-beacon absolute top(-3) right(-3)" popovertarget="tip-filter" aria-label="What is new in Filter"></button> <div id="tip-filter" popover class="coachmark coachmark-top" role="dialog" aria-labelledby="tip-filter-title"> <p class="coachmark-count">New</p> <h2 class="coachmark-title" id="tip-filter-title">Filter by author</h2> <p class="coachmark-text"> Narrow the deployments to the ones you shipped, or to anyone on the team. </p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm" popovertarget="tip-filter" popovertargetaction="hide" autofocus> Got it </button> </div> </div> </span> <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Share"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="3.6667" cy="8" r="1.6667" /><circle cx="12" cy="3.3333" r="1.6667" /><circle cx="12" cy="12.6667" r="1.6667" /><path d="M5.12 7.1867L10.5467 4.1467" /><path d="M5.12 8.8133L10.5467 11.8533" /> </svg> </button></div>import SearchIcon from '@master/icons-react/native/16/soft/search'import FilterIcon from '@master/icons-react/native/16/soft/filter'import ShareIcon from '@master/icons-react/native/16/soft/share'<div className="toolbar" role="toolbar" aria-label="Deployments"> <button type="button" className="btn btn-quiet btn-sm btn-square" aria-label="Search"> <SearchIcon className="icon" /> </button> <span className="relative inline-flex"> <button type="button" className="btn btn-quiet btn-sm btn-square" aria-label="Filter"> <FilterIcon className="icon" /> </button> <button type="button" className="coachmark-beacon absolute top(-3) right(-3)" popoverTarget="tip-filter" aria-label="What is new in Filter"></button> <div id="tip-filter" popover="" className="coachmark coachmark-top" role="dialog" aria-labelledby="tip-filter-title"> <p className="coachmark-count">New</p> <h2 className="coachmark-title" id="tip-filter-title">Filter by author</h2> <p className="coachmark-text"> Narrow the deployments to the ones you shipped, or to anyone on the team. </p> <div className="coachmark-actions"> <button type="button" className="btn btn-sm" popoverTarget="tip-filter" popoverTargetAction="hide" autoFocus> Got it </button> </div> </div> </span> <button type="button" className="btn btn-quiet btn-sm btn-square" aria-label="Share"> <ShareIcon className="icon" /> </button></div><script> import SearchIcon from '@master/icons-svelte/native/16/soft/search' import FilterIcon from '@master/icons-svelte/native/16/soft/filter' import ShareIcon from '@master/icons-svelte/native/16/soft/share'</script><div class="toolbar" role="toolbar" aria-label="Deployments"> <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Search"> <SearchIcon class="icon" /> </button> <span class="relative inline-flex"> <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Filter"> <FilterIcon class="icon" /> </button> <button type="button" class="coachmark-beacon absolute top(-3) right(-3)" popovertarget="tip-filter" aria-label="What is new in Filter"></button> <div id="tip-filter" popover class="coachmark coachmark-top" role="dialog" aria-labelledby="tip-filter-title"> <p class="coachmark-count">New</p> <h2 class="coachmark-title" id="tip-filter-title">Filter by author</h2> <p class="coachmark-text"> Narrow the deployments to the ones you shipped, or to anyone on the team. </p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm" popovertarget="tip-filter" popovertargetaction="hide" autofocus> Got it </button> </div> </div> </span> <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Share"> <ShareIcon class="icon" /> </button></div><script setup>import SearchIcon from '@master/icons-vue/native/16/soft/search'import FilterIcon from '@master/icons-vue/native/16/soft/filter'import ShareIcon from '@master/icons-vue/native/16/soft/share'</script><template> <div class="toolbar" role="toolbar" aria-label="Deployments"> <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Search"> <SearchIcon class="icon" /> </button> <span class="relative inline-flex"> <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Filter"> <FilterIcon class="icon" /> </button> <button type="button" class="coachmark-beacon absolute top(-3) right(-3)" popovertarget="tip-filter" aria-label="What is new in Filter"></button> <div id="tip-filter" popover class="coachmark coachmark-top" role="dialog" aria-labelledby="tip-filter-title"> <p class="coachmark-count">New</p> <h2 class="coachmark-title" id="tip-filter-title">Filter by author</h2> <p class="coachmark-text"> Narrow the deployments to the ones you shipped, or to anyone on the team. </p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm" popovertarget="tip-filter" popovertargetaction="hide" autofocus> Got it </button> </div> </div> </span> <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Share"> <ShareIcon class="icon" /> </button> </div></template>The card is ink on moonstone and pearl on obsidian, the inverse surface of sheet-inverse laid flat, so it stands apart from the sheets of ordinary popovers and from the page under it, and its arrow joins it without a seam. A default button on it reads as the action; a quiet one takes the card's ink, and a tint of it under the pointer.
#Anatomy
Each part is optional except the title.
| Class | Holds |
|---|---|
coachmark-count | Where the step stands in the tour, such as 2 of 4, or a word such as New, in a quieter ink |
coachmark-title | The heading of the step; give it an id and label the coachmark with it |
coachmark-text | One or two sentences that say what the control does |
coachmark-actions | Small buttons along the foot. The first of several stands at the start, such as Skip; the others line up at the end, such as Back and Next |
The actions sit 12px from the card's edges, so a small button's corner nests in the card's: the card's corner is the button's corner plus that inset.
#Placement
A coachmark opens centered under the element that opened it, with the arrow's point 6px from that element, and flips above when there is no room below. coachmark-top prefers the space above, for a control near the foot of the screen or a beacon on a control's top corner, as in the first example.
The arrow points at the element right before the coachmark in the markup, so put the coachmark right after its beacon or the control it explains; in a tour, it points at the tour's spotlight, which stands over the step's target. While the coachmark is open, that element is named as an anchor, and the arrow follows its middle: it stays on it when an edge of the viewport pushes the card aside, keeps clear of the card's rounded corners, and moves to the other edge of the card when the card flips. One coachmark is open at a time, as in a tour.
#Beacon
coachmark-beacon is a 10px dot on a button, with a rim of the surface it stands on and a target of 24px, 44px on a touch screen. It opens its coachmark with popovertarget and needs an aria-label that says what it opens. The page places it: on the top corner of the control it marks, with absolute utilities inside a relative wrapper, or beside it in a row.
Its ring asks to be noticed. It rests as a halo while the beacon is under the pointer or has focus, while its coachmark is open, and with reduced motion. Remove the beacon once the reader has seen its step.
#A tour
A tour is a few coachmarks opened one after another, each against the control it explains. Hold its steps in a coachmark-tour, in the order they are taken, each with popover="manual", so a click on the page, such as trying the control a step points at, does not end the tour. A step names its target with a selector in data-target; without one, it points at the element right before it in the markup. Its buttons say what they do in their value: next, back, skip, and done on the last step.
The tour behavior does the rest. A button with command="--start" and commandfor naming the tour starts it; the behavior opens each step against its target with showPopover({ source }), so the browser anchors the card there and CSS places it, and moves focus into it, to Next or Done. A coachmark-spotlight in the tour is opened over the target first: the step's arrow points at it, wherever the step stands in the markup.
A tour
<div class="coachmark-tour flex items-center gap-sm" id="deploys-tour"> <button type="button" class="btn btn-sm" commandfor="deploys-tour" command="--start"> Take the tour </button> <div class="toolbar" role="toolbar" aria-label="Deployments"> <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-search" aria-label="Search"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="7" cy="7" r="4.5" /><path d="M10.182 10.182L14 14" /> </svg> </button> <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-filter" aria-label="Filter"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4.5365 3L11.4635 3A1 1 0 0 1 12.2548 4.6114L9.4587 8.2299A1 1 0 0 0 9.25 8.8413L9.25 11.323A1 1 0 0 1 8.6214 12.2514L7.875 12.55A0.8203 0.8203 0 0 1 6.75 11.7883L6.75 8.8413A1 1 0 0 0 6.5413 8.2299L3.7452 4.6114A1 1 0 0 1 4.5365 3Z" /> </svg> </button> <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-share" aria-label="Share"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="3.6667" cy="8" r="1.6667" /><circle cx="12" cy="3.3333" r="1.6667" /><circle cx="12" cy="12.6667" r="1.6667" /><path d="M5.12 7.1867L10.5467 4.1467" /><path d="M5.12 8.8133L10.5467 11.8533" /> </svg> </button> </div> <div class="coachmark-spotlight" popover="manual"></div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-search-title" data-target="#deploys-search"> <p class="coachmark-count">1 of 3</p> <h2 class="coachmark-title" id="deploys-search-title">Search every deployment</h2> <p class="coachmark-text">Find one by its branch, its commit or the person who shipped it.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" class="btn btn-sm" value="next">Next</button> </div> </div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-filter-title" data-target="#deploys-filter"> <p class="coachmark-count">2 of 3</p> <h2 class="coachmark-title" id="deploys-filter-title">Filter the list</h2> <p class="coachmark-text">Keep only the deployments of one branch, one author or one status.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" class="btn btn-sm" value="next">Next</button> </div> </div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-share-title" data-target="#deploys-share"> <p class="coachmark-count">3 of 3</p> <h2 class="coachmark-title" id="deploys-share-title">Share a deployment</h2> <p class="coachmark-text">Copy a link to it, open for anyone on the team.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" class="btn btn-sm" value="done">Done</button> </div> </div></div><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'import SearchIcon from '@master/icons-react/native/16/soft/search'import FilterIcon from '@master/icons-react/native/16/soft/filter'import ShareIcon from '@master/icons-react/native/16/soft/share'export function Example() { const root = useRef<HTMLDivElement>(null) useEffect(() => attach(root.current!), []) return ( <div ref={root} className="coachmark-tour flex items-center gap-sm" id="deploys-tour"> <button type="button" className="btn btn-sm" {...{ commandfor: 'deploys-tour', command: '--start' }}> Take the tour </button> <div className="toolbar" role="toolbar" aria-label="Deployments"> <button type="button" className="btn btn-quiet btn-sm btn-square" id="deploys-search" aria-label="Search"> <SearchIcon className="icon" /> </button> <button type="button" className="btn btn-quiet btn-sm btn-square" id="deploys-filter" aria-label="Filter"> <FilterIcon className="icon" /> </button> <button type="button" className="btn btn-quiet btn-sm btn-square" id="deploys-share" aria-label="Share"> <ShareIcon className="icon" /> </button> </div> <div className="coachmark-spotlight" popover="manual"></div> <div className="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-search-title" data-target="#deploys-search"> <p className="coachmark-count">1 of 3</p> <h2 className="coachmark-title" id="deploys-search-title">Search every deployment</h2> <p className="coachmark-text"> Find one by its branch, its commit or the person who shipped it. </p> <div className="coachmark-actions"> <button type="button" className="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" className="btn btn-sm" value="next">Next</button> </div> </div> <div className="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-filter-title" data-target="#deploys-filter"> <p className="coachmark-count">2 of 3</p> <h2 className="coachmark-title" id="deploys-filter-title">Filter the list</h2> <p className="coachmark-text"> Keep only the deployments of one branch, one author or one status. </p> <div className="coachmark-actions"> <button type="button" className="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" className="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" className="btn btn-sm" value="next">Next</button> </div> </div> <div className="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-share-title" data-target="#deploys-share"> <p className="coachmark-count">3 of 3</p> <h2 className="coachmark-title" id="deploys-share-title">Share a deployment</h2> <p className="coachmark-text">Copy a link to it, open for anyone on the team.</p> <div className="coachmark-actions"> <button type="button" className="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" className="btn btn-sm" value="done">Done</button> </div> </div> </div> )}<script> import { attach } from '@master/ui/behaviors' import SearchIcon from '@master/icons-svelte/native/16/soft/search' import FilterIcon from '@master/icons-svelte/native/16/soft/filter' import ShareIcon from '@master/icons-svelte/native/16/soft/share'</script><div class="coachmark-tour flex items-center gap-sm" id="deploys-tour" {@attach attach}> <button type="button" class="btn btn-sm" commandfor="deploys-tour" command="--start"> Take the tour </button> <div class="toolbar" role="toolbar" aria-label="Deployments"> <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-search" aria-label="Search"> <SearchIcon class="icon" /> </button> <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-filter" aria-label="Filter"> <FilterIcon class="icon" /> </button> <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-share" aria-label="Share"> <ShareIcon class="icon" /> </button> </div> <div class="coachmark-spotlight" popover="manual"></div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-search-title" data-target="#deploys-search"> <p class="coachmark-count">1 of 3</p> <h2 class="coachmark-title" id="deploys-search-title">Search every deployment</h2> <p class="coachmark-text">Find one by its branch, its commit or the person who shipped it.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" class="btn btn-sm" value="next">Next</button> </div> </div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-filter-title" data-target="#deploys-filter"> <p class="coachmark-count">2 of 3</p> <h2 class="coachmark-title" id="deploys-filter-title">Filter the list</h2> <p class="coachmark-text">Keep only the deployments of one branch, one author or one status.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" class="btn btn-sm" value="next">Next</button> </div> </div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-share-title" data-target="#deploys-share"> <p class="coachmark-count">3 of 3</p> <h2 class="coachmark-title" id="deploys-share-title">Share a deployment</h2> <p class="coachmark-text">Copy a link to it, open for anyone on the team.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" class="btn btn-sm" value="done">Done</button> </div> </div></div><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'import SearchIcon from '@master/icons-vue/native/16/soft/search'import FilterIcon from '@master/icons-vue/native/16/soft/filter'import ShareIcon from '@master/icons-vue/native/16/soft/share'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template> <div ref="root" class="coachmark-tour flex items-center gap-sm" id="deploys-tour"> <button type="button" class="btn btn-sm" commandfor="deploys-tour" command="--start"> Take the tour </button> <div class="toolbar" role="toolbar" aria-label="Deployments"> <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-search" aria-label="Search"> <SearchIcon class="icon" /> </button> <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-filter" aria-label="Filter"> <FilterIcon class="icon" /> </button> <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-share" aria-label="Share"> <ShareIcon class="icon" /> </button> </div> <div class="coachmark-spotlight" popover="manual"></div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-search-title" data-target="#deploys-search"> <p class="coachmark-count">1 of 3</p> <h2 class="coachmark-title" id="deploys-search-title">Search every deployment</h2> <p class="coachmark-text">Find one by its branch, its commit or the person who shipped it.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" class="btn btn-sm" value="next">Next</button> </div> </div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-filter-title" data-target="#deploys-filter"> <p class="coachmark-count">2 of 3</p> <h2 class="coachmark-title" id="deploys-filter-title">Filter the list</h2> <p class="coachmark-text"> Keep only the deployments of one branch, one author or one status. </p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" class="btn btn-sm" value="next">Next</button> </div> </div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-share-title" data-target="#deploys-share"> <p class="coachmark-count">3 of 3</p> <h2 class="coachmark-title" id="deploys-share-title">Share a deployment</h2> <p class="coachmark-text">Copy a link to it, open for anyone on the team.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" class="btn btn-sm" value="done">Done</button> </div> </div> </div></template>The tour may hold the region it explains, as here, or only its steps and its spotlight: a step finds its target anywhere in the document. Closed, the steps and the spotlight take no room, so the tour can be the row it stands in.
A single coachmark opened by its beacon needs none of this. It is popover="auto": the browser closes it on an outside click and on Esc, and returns focus to the beacon, with no script at all.
#Steps that wait
A step can wait for the reader, and for its target.
- An action. A step with
data-advancenames an event on its target, such asclick, that moves the tour on. Give it no Next: it asks the reader to do the thing itself, and the tour goes on once the page has answered. Skip and Esc still leave. - A target that comes later. When a step's target is not in the page, or is not rendered, the step waits for it and opens as soon as it appears: a field that a button reveals, a row that is still loading. A target that has not appeared after three seconds, or the
waitgiven to the behavior, is passed over, and past the last step the tour is complete. It does not stop on a card that points at nothing, and a step that cannot be shown should hold nothing the reader cannot find without it.
Steps that wait
<div class="coachmark-tour flex flex-col items-center gap-md" id="projects-tour"> <div class="flex items-center gap-sm"> <button type="button" class="btn btn-sm" commandfor="projects-tour" command="--start"> Take the tour </button> <button type="button" class="btn btn-sm btn-primary" id="projects-new">New project</button> </div> <input class="input w(240)" id="projects-name" placeholder="Project name" aria-label="Project name" hidden> <div class="coachmark-spotlight" popover="manual"></div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="projects-new-title" data-target="#projects-new" data-advance="click"> <p class="coachmark-count">1 of 2</p> <h2 class="coachmark-title" id="projects-new-title">Start a project</h2> <p class="coachmark-text">Press New project. The tour goes on once its form is open.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button> </div> </div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="projects-name-title" data-target="#projects-name"> <p class="coachmark-count">2 of 2</p> <h2 class="coachmark-title" id="projects-name-title">Name it</h2> <p class="coachmark-text"> Use the name your team already calls it by. You can change it later. </p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" class="btn btn-sm" value="done">Done</button> </div> </div></div><script>document.getElementById('projects-new').addEventListener('click', function () { setTimeout(function () { document.getElementById('projects-name').hidden = false }, 400)})</script><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>#Spotlight
coachmark-spotlight-dim dims the page around the step's target with the scrim of a dialog and leaves the target lit, 4px around it, with the corner of a control plus that inset. The scrim is a ring of shadow as wide as the screen, drawn by the spotlight where anchor positioning holds it over the target, so it follows the target as the page scrolls. It fades in as the tour starts and out as it ends; from one step to the next the lit place moves at once.
The scrim is paint, not a wall: the page under it still answers the pointer and the keys, so the reader can try what a step points at, and the tour stays out of the way of anything else they do. Use it for a first tour of a screen, where the eye needs to be led; leave it off for a tip about one new control.
Spotlight
<div class="coachmark-tour flex flex-col items-center gap-md" id="release-tour"> <button type="button" class="btn btn-sm" commandfor="release-tour" command="--start"> Take the tour </button> <div class="card flex-row items-center gap-md p-md w(300)"> <div class="flex flex-col grow(1)"> <span class="text-sm fg-text-strong">atlas.dev</span> <span class="text-xs fg-text-muted" id="release-status">Ready, 2 minutes ago</span> </div> <button type="button" class="btn btn-sm btn-primary" id="release-deploy">Deploy</button> </div> <div class="coachmark-spotlight coachmark-spotlight-dim" popover="manual"></div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="release-status-title" data-target="#release-status"> <p class="coachmark-count">1 of 2</p> <h2 class="coachmark-title" id="release-status-title">See where it stands</h2> <p class="coachmark-text">Each project says whether its last build is ready and when it ran.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" class="btn btn-sm" value="next">Next</button> </div> </div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="release-deploy-title" data-target="#release-deploy"> <p class="coachmark-count">2 of 2</p> <h2 class="coachmark-title" id="release-deploy-title">Ship it</h2> <p class="coachmark-text">Deploy sends the ready build to production.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" class="btn btn-sm" value="done">Done</button> </div> </div></div><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'export function Example() { const root = useRef<HTMLDivElement>(null) useEffect(() => attach(root.current!), []) return ( <div ref={root} className="coachmark-tour flex flex-col items-center gap-md" id="release-tour"> <button type="button" className="btn btn-sm" {...{ commandfor: 'release-tour', command: '--start' }}> Take the tour </button> <div className="card flex-row items-center gap-md p-md w(300)"> <div className="flex flex-col grow(1)"> <span className="text-sm fg-text-strong">atlas.dev</span> <span className="text-xs fg-text-muted" id="release-status">Ready, 2 minutes ago</span> </div> <button type="button" className="btn btn-sm btn-primary" id="release-deploy">Deploy</button> </div> <div className="coachmark-spotlight coachmark-spotlight-dim" popover="manual"></div> <div className="coachmark" popover="manual" role="dialog" aria-labelledby="release-status-title" data-target="#release-status"> <p className="coachmark-count">1 of 2</p> <h2 className="coachmark-title" id="release-status-title">See where it stands</h2> <p className="coachmark-text"> Each project says whether its last build is ready and when it ran. </p> <div className="coachmark-actions"> <button type="button" className="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" className="btn btn-sm" value="next">Next</button> </div> </div> <div className="coachmark" popover="manual" role="dialog" aria-labelledby="release-deploy-title" data-target="#release-deploy"> <p className="coachmark-count">2 of 2</p> <h2 className="coachmark-title" id="release-deploy-title">Ship it</h2> <p className="coachmark-text">Deploy sends the ready build to production.</p> <div className="coachmark-actions"> <button type="button" className="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" className="btn btn-sm" value="done">Done</button> </div> </div> </div> )}<script> import { attach } from '@master/ui/behaviors'</script><div class="coachmark-tour flex flex-col items-center gap-md" id="release-tour" {@attach attach}> <button type="button" class="btn btn-sm" commandfor="release-tour" command="--start"> Take the tour </button> <div class="card flex-row items-center gap-md p-md w(300)"> <div class="flex flex-col grow(1)"> <span class="text-sm fg-text-strong">atlas.dev</span> <span class="text-xs fg-text-muted" id="release-status">Ready, 2 minutes ago</span> </div> <button type="button" class="btn btn-sm btn-primary" id="release-deploy">Deploy</button> </div> <div class="coachmark-spotlight coachmark-spotlight-dim" popover="manual"></div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="release-status-title" data-target="#release-status"> <p class="coachmark-count">1 of 2</p> <h2 class="coachmark-title" id="release-status-title">See where it stands</h2> <p class="coachmark-text">Each project says whether its last build is ready and when it ran.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" class="btn btn-sm" value="next">Next</button> </div> </div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="release-deploy-title" data-target="#release-deploy"> <p class="coachmark-count">2 of 2</p> <h2 class="coachmark-title" id="release-deploy-title">Ship it</h2> <p class="coachmark-text">Deploy sends the ready build to production.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" class="btn btn-sm" value="done">Done</button> </div> </div></div><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template> <div ref="root" class="coachmark-tour flex flex-col items-center gap-md" id="release-tour"> <button type="button" class="btn btn-sm" commandfor="release-tour" command="--start"> Take the tour </button> <div class="card flex-row items-center gap-md p-md w(300)"> <div class="flex flex-col grow(1)"> <span class="text-sm fg-text-strong">atlas.dev</span> <span class="text-xs fg-text-muted" id="release-status">Ready, 2 minutes ago</span> </div> <button type="button" class="btn btn-sm btn-primary" id="release-deploy">Deploy</button> </div> <div class="coachmark-spotlight coachmark-spotlight-dim" popover="manual"></div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="release-status-title" data-target="#release-status"> <p class="coachmark-count">1 of 2</p> <h2 class="coachmark-title" id="release-status-title">See where it stands</h2> <p class="coachmark-text"> Each project says whether its last build is ready and when it ran. </p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" class="btn btn-sm" value="next">Next</button> </div> </div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="release-deploy-title" data-target="#release-deploy"> <p class="coachmark-count">2 of 2</p> <h2 class="coachmark-title" id="release-deploy-title">Ship it</h2> <p class="coachmark-text">Deploy sends the ready build to production.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" class="btn btn-sm" value="done">Done</button> </div> </div> </div></template>In forced colors, where shadows are not drawn, an outline in the system's highlight color marks the target instead.
#The behavior
tour takes the root, the element with the coachmark-tour class, and returns the function that detaches it. attach() from @master/ui/behaviors finds every tour on the page.
import { tour } from '@master/ui/behaviors/tour.js'const root = document.querySelector('#deploys-tour')const deploys = tour(root)deploys.value = 0 // starts the tour, as the button doesroot.addEventListener('end', (event) => { if (event.detail.completed) localStorage.setItem('deploys-tour', 'seen')})- The value is the index of the step the tour is on, from 0, or
nullwhile it is not running. Set it to open a step, or tonullto end the tour; that dispatches nothing. - Events. The root dispatches a bubbling
changeeach time the tour moves to another step, with the index indetail.value. When the reader ends the tour, it dispatcheschangewithnull, thenend, whosedetail.completedis true when they went through to the last step, and false when they left before it, with Skip, Esc or anything else that closed the step. - Focus moves into each step as it opens: to the action with
autofocus, else to Next or Done, else to the step itself. When the tour ends, focus goes back to where it was when the tour started, unless the reader has since moved it into the page. - Options.
target(step, index)finds a step's target, for a page that holds the targets itself;waitis how long a step waits for its target, in milliseconds, 3000 by default. - Invoker commands. Where the browser has no
commandandcommandfor, the behavior hears the start button's click itself.
Without the behavior, nothing starts the tour; the steps stay closed and the page is whole without them. Remember that a reader has finished a tour, from the end event, and do not start it on their own again: offer it from a button they can find later.
#Keyboard
| Keys | Action |
|---|---|
| Enter, Space | On the beacon: open or close its coachmark. On a step of a tour: Next, Back, Skip or Done, as the button says in its value. An action inside with autofocus takes focus as a coachmark opens; a step without one takes focus itself |
| Tab | Move between the actions in the coachmark, and from it back to the page after the beacon. A step does not keep focus: the page stays usable while it is open |
| Escape | Close a coachmark opened with popover="auto" and return focus to the beacon. In a tour, with focus in the step: end the tour, skipped, and return focus to where it was when the tour started |
#Accessibility
- Give the coachmark
role="dialog"and label it with its title througharia-labelledby. It is not modal: the page stays usable around it, and in a tour, under the spotlight too. - Put
autofocuson the main action of a coachmark opened by its beacon, so focus moves into the card as it opens and a keyboard can go on with Enter. A tour's steps take focus from the behavior. - Every step can be left: a Skip or Done action, Esc, and for a single coachmark a click elsewhere.
- Start a tour from something the reader does, such as a button, never as the page loads: it is help, and it should not take focus from the task they came for.
- Say nothing in a tour that cannot be found without it: a reader who skips it, or a step that is passed over, must not miss anything.
- Placed right after its beacon in the markup, the coachmark is next in the tab order after it, wherever the card is drawn.
#React, Svelte and Vue
The tour component writes one step for each item of its data, each with its title, its text, its count and the actions it needs, and passes the index of the open step in and out, with the end of the tour as onEnd. A step's target is a selector, an element, a ref or a function that finds it. Copy it into the project with npx master-ui add tour; React, Svelte and Vue says how the components are built and used.
#Browser support
The coachmark is placed with CSS anchor positioning: position-area and position-try-fallbacks for the card, and anchor() between the card and the element it points at for the arrow and for a tour's spotlight. In a browser without anchor positioning it still opens and closes, centered in the viewport where the browser places any popover, and has no arrow; the spotlight dims nothing, since it could not leave the target lit. The source option of showPopover() gives a tour's step its anchor; without it, a step opens without one. The start button uses invoker commands, which the behavior stands in for where they are missing. The fade and the short slide use @starting-style; without it the card and the scrim appear and leave at once.
The card enters with a fade and slides 4px toward its anchor, and leaves with a shorter fade. It does not scale as other popovers do: a scaled card would hold its arrow inside it, out of reach of the element the arrow points at.
#Classes
| Class | Description |
|---|---|
coachmark | The card of ink, on an element with the popover attribute and role="dialog", labelled by its title; without the popover attribute it is never shown. It opens centered under the element that opened it, flips above when there is no room, and is 18rem wide. Its arrow points at the element right before it in the markup, so put it right after its beacon or the control it explains |
coachmark-top | Prefers the space above, for a control near the foot of the screen or a beacon on a control's top cornerApply with coachmark |
coachmark-count | A short line over the title in a quieter ink: where the step stands in the tour (2 of 4), or a word such as New |
coachmark-title | The heading of the step, which labels the coachmark |
coachmark-text | One or two sentences that say what the control does |
coachmark-actions | A row of small buttons along the foot, 12px from the card's edges: the first of several stands at the start (Skip), the others at the end (Back, Next). A default button reads as the action on ink, and a quiet one takes the card's ink |
coachmark-tour | Holds the steps of a tour, each a coachmark with popover="manual", in the order they are taken, and its spotlight. The tour behavior attaches to it; give it an id for the button that starts it. It draws nothing, and keeps the name of what its arrows point at to itself |
coachmark-spotlight | An empty popover the tour opens over each step's target, before the step: it covers the target and 4px around it, and the open step's arrow points at it wherever the step stands in the markup. By itself it draws nothing and lets the pointer through |
coachmark-spotlight-dim | Dims the page around the target with the scrim of a dialog, and leaves the target lit. The page under the scrim stays usable. In forced colors an outline of the system's highlight marks the target insteadApply with coachmark-spotlight |
coachmark-beacon | A 10px dot of ink that marks where a step is and opens it with popovertarget. It sends out a ring now and then, which rests as a halo while it is under the pointer, has focus or its coachmark is open, and under reduced motion. Its target is 24px, and 44px on a touch screen. The page places it, usually on the top corner of the control it marks |
#Custom properties
| Property | Default | Description |
|---|---|---|
--coachmark-width | 18rem | The card's width, never wider than the viewport less a rem |
--coachmark-inset | 12px | Space between the actions and the card's edges; the text has 4px more. The card's corner is a small button's corner plus this inset |
--coachmark-arrow | 7px | How far the arrow's point stands out from the card |
--anchored-gap | calc(var(--coachmark-arrow) + 6px) | Space between the card and the element that opened it; the arrow's point stands 6px from that element |
--coachmark-beacon-size | .625rem | The beacon dot's diameterSet on coachmark-beacon |
--coachmark-spotlight-inset | 4px | How far the spotlight reaches past its target on every sideSet on coachmark-spotlight |
--coachmark-spotlight-radius | var(--radius-control) | The corner of the target it lights; the spotlight's corner is this plus the insetSet on coachmark-spotlight |