Onboarding
Two independent, fully optional components for guiding new
users - neither requires the other. Both run on a native
<dialog> (showModal()), so
focus trapping, restoring focus, and closing with
Esc all come for free, with no code of your own.
1. Which one to pick
| Component | When | Defining content |
|---|---|---|
.onboarding-dialog |
First entry into the panel - a short "what is this product" before the user sees the interface. | data-onboarding-* OR MoliqueOnboarding.start() |
.tour-dialog |
The user is already looking at the interface - you need to show them where a specific feature lives. | data-tour on real elements OR MoliqueTour.start() |
Chaining both into one flow
Both APIs return a Promise, resolved once the
dialog closes (Skip, Escape, or completing the last step) -
so you can start the Tour right after the slides:
MoliqueOnboarding.start(slides).then(() => MoliqueTour.start(steps));
2. Onboarding Slides
Full-screen welcome slides: an icon or image + title +
description, with Next/Previous/Skip buttons and progress
dots. In declarative mode they show automatically once per
browser (localStorage) - the integrator doesn't
write a single line of JS.
<!-- Declarative variant (zero JS) -->
<div data-onboarding hidden>
<div data-onboarding-slide
data-onboarding-icon="ph-hand-waving"
data-onboarding-title="Welcome to the panel"
data-onboarding-desc="A short description of the first step."></div>
<div data-onboarding-slide
data-onboarding-image="img/onboarding/orders.png"
data-onboarding-image-alt="Screenshot of the order list"
data-onboarding-title="Orders"
data-onboarding-desc="This is where you manage orders."></div>
</div>
<!-- JS variant (dynamic content) -->
<script>
MoliqueOnboarding.start([
{ icon: 'ph-hand-waving', title: 'Welcome to the panel', description: '…' },
{ image: 'orders.png', imageAlt: '…', title: 'Orders', description: '…' },
], {
onSkip: () => {},
onComplete: () => {},
});
</script>
| Class / attribute | What it does |
|---|---|
.onboarding-dialog |
The native <dialog> built by JS - you never write it by hand. |
.onboarding-card |
The slide card. Width via --onboarding-card-width (440px by default), set on :root - the card is built by JS, so there is no markup to put a style="" on. The variable deliberately does not reach the mobile branch, where the card goes full-screen anyway. |
data-onboarding |
Wraps the slides. Optionally data-onboarding-key="name" - a custom localStorage key (defaults to the page path). |
data-onboarding-slide |
One slide. Order = DOM order. Attributes: data-onboarding-icon (an icon-sprite fragment, e.g. ph-hand-waving) OR data-onboarding-image + data-onboarding-image-alt (mutually exclusive), data-onboarding-title, data-onboarding-desc. |
MoliqueOnboarding.start(slides, options) |
slides: an array of objects as above. options.onSkip / options.onComplete. Returns a Promise. |
3. Spotlight Tour
A sequence of steps over real interface elements: the rest
of the screen dims, the highlighted element stays visible
but not clickable - showModal()
makes the whole document outside the dialog genuinely
inert (a browser spec behavior, not a
pointer-events trick). Only the tooltip's own
Next/Previous/Skip buttons control navigation.
<!-- Declarative variant (zero JS) - directly on real elements -->
<div class="card" data-tour
data-tour-title="New orders"
data-tour-desc="This shows the number of orders waiting to be handled.">
…
</div>
<button class="btn-outline-primary" data-tour
data-tour-title="Settings"
data-tour-desc="Configure notifications and integrations here.">
Settings
</button>
<!-- JS variant (dynamic targets) -->
<script>
MoliqueTour.start([
{ target: '#stat-orders', title: 'New orders', description: '…' },
{ target: document.querySelector('.settings-btn'), title: 'Settings', description: '…' },
]);
</script>
| Class / attribute | What it does |
|---|---|
.tour-dialog |
The native <dialog> built by JS. |
.tour-spotlight |
The "hole" in the dimming - position/size computed from the target's getBoundingClientRect() on every step (the classic box-shadow: 0 0 0 9999px technique, not an SVG mask). |
.tour-tooltip |
The title/description bubble, positioned via native CSS Anchor Positioning (an anchor-name set from JS on the target + a 5-way @position-try fallback chain, so it never overflows the viewport). Width via --tour-tooltip-width (320px by default) - the viewport clamp stays in place whatever you set it to. |
data-tour |
Marks a real element as a tour step. Optionally data-tour-group="name" (defaults to "default") - several independent tours on one page. |
data-tour-title / data-tour-desc |
The tooltip content for that step. Step order = DOM order (the same rule as data-gallery groups in Lightbox) - there's no separate numbered-index attribute. |
MoliqueTour.start(steps, options) |
steps: an array of { target, title, description } (target - a selector OR a live element). options.onStepChange / onSkip / onComplete. Returns a Promise. |
4. Gotchas and deliberate limitations
1 Elements added to the page AFTER it loads
The declarative scan ([data-tour] /
[data-onboarding]) happens ONCE, when the
module loads - just like Lightbox, no
MutationObserver. A panel rendered later
(a spinner, hydration) needs
MoliqueTour.start() /
MoliqueOnboarding.start() from JS instead
of attributes alone.
2 No directional caret on the tooltip
A deliberate scope cut for v1: CSS has no reliable way
today to tell, from CSS alone, which
@position-try variant actually won, so the
tooltip doesn't draw a "pointer" tail. Proximity and
the tooltip's own shadow keep the relationship to the
highlighted element readable.
3 Showing it again after it's saved to localStorage
Declarative mode for both components remembers that
it's been seen in localStorage (default
key: the page path) and won't show again. To give the
user a "Show the intro again" button, call
MoliqueOnboarding.start(slides) /
MoliqueTour.start(steps) directly from
JS - that call bypasses the localStorage
check.
4 Many steps: dots give way to the counter
Nothing caps the number of slides or steps, and the dot
row grew with it - a long enough sequence pushed the
"Next" button out of the card. The failure was silent:
the button stayed in the DOM, clickable and in the tab
order, and the card is overflow: hidden, so
not even a scrollbar showed up. Since v1.7.30 the footer
wraps (flex-wrap), the dots are the only
part allowed to shrink, and the navigation never gives
way. Past a threshold (8 onboarding slides, 6 tour
steps) the dots disappear entirely and the visible
"Step N of M" counter takes over - the same one that
used to be screen-reader-only.