Wizard
Multi-step form patterns with numbered steps, tab navigation, and progress bar indicators. Guide users through complex forms with clear progress feedback.
Overview
Wizard patterns break complex forms into manageable steps, reducing cognitive load and improving completion rates. VB includes wizard.js, a production-ready controller that transforms standard HTML forms into multi-step wizards with progressive enhancement — forms still work without JavaScript.
Key features:
wizard.jscontroller — auto-initializes onform[data-wizard], handles step navigation, validation, and progressnav.stepsintegration — auto-syncs step indicator state as the user navigates- Conditional steps (
data-wizard-if) — show/hide steps based on user input - Optional steps (
data-wizard-optional) — skip without validation - Programmatic API —
wizardNext(),wizardPrev(),wizardGoTo(),wizardReset() - Custom events —
wizard:stepchange,wizard:complete,wizard:reset - Visual patterns — numbered step indicators, tab navigation, and progress bars
- Accessibility —
aria-current="step", live regions, keyboard navigation
Numbered Steps
A horizontal step indicator with numbered circles connected by lines. Completed steps show checkmarks and can be clicked to navigate back. The current step is highlighted with the interactive color.
Step Indicator
The step indicator uses nav.steps from VB core — no custom CSS needed. See the Steps pattern for all variants and CSS variables.
Tab Navigation
A tab-style navigation where each step is represented as a tab. Completed tabs can be clicked to jump back to previous sections. Future tabs are visually disabled until their prerequisites are met.
Tab Navigation Styles
Progress Bar
A horizontal progress bar showing completion percentage with step dots below. Includes text showing "Step X of Y" and the current step name. Great for checkout flows and linear processes.
Progress Bar Styles
wizard.js Controller
VB includes wizard.js, a lightweight controller that enhances form[data-wizard] elements with step navigation, validation, conditional steps, and progress tracking. It works as a standard form without JavaScript (progressive enhancement).
Basic Setup
Add data-wizard to a form. Each <fieldset data-wizard-step> becomes a step. The controller auto-initializes on DOMContentLoaded.
Conditional Steps
Use data-wizard-if to show a step only when a form field matches a value. The step is hidden when the condition is not met and the progress bar adjusts automatically.
Optional Steps
Use data-wizard-optional to mark a step that can be skipped. The "Next" button advances without requiring validation on optional steps.
nav.steps Integration
When a nav.steps element is found inside the form (or referenced via data-wizard-steps="#id"), wizard.js automatically syncs step states — setting data-completed on past steps, aria-current="step" on the current step, and hiding <li> elements for conditional steps that don't apply.
Markup Reference
| Attribute | Element | Purpose |
|---|---|---|
data-wizard |
<form> |
Enables the wizard controller on the form |
data-wizard-step |
<fieldset> |
Marks a fieldset as a wizard step |
data-wizard-progress |
<progress> |
Auto-updated progress bar |
data-wizard-nav |
<nav> |
Navigation container (shows/hides prev/next/submit buttons) |
data-wizard-prev |
<button> |
Go to previous step |
data-wizard-next |
<button> |
Go to next step (validates current step first) |
data-wizard-if="..." |
<fieldset> |
Conditional step — shown only when condition is met |
data-wizard-optional |
<fieldset> |
Step can be skipped without validation |
data-wizard-steps="#id" |
<form> |
Points to a nav.steps element for auto-sync |
Condition Syntax
The data-wizard-if attribute supports these patterns:
| Pattern | Meaning |
|---|---|
data-wizard-if="fieldName:value" |
Show when field equals value |
data-wizard-if="fieldName:!value" |
Show when field does NOT equal value |
data-wizard-if="fieldName" |
Show when field is truthy (has value / is checked) |
data-wizard-if="!fieldName" |
Show when field is falsy (empty / unchecked) |
API & Events
Access the wizard programmatically via methods attached to the form element:
Custom Events
| Event | Detail | Fires when |
|---|---|---|
wizard:stepchange |
{ from, to } |
User navigates to a different step |
wizard:complete |
none | Form is submitted on the last step |
wizard:reset |
none | Wizard is reset to the first step |
Configuration
Key configuration options for wizard patterns:
| Property | Purpose | Values |
|---|---|---|
data-size="sm|lg" |
Size of step indicator circles | sm (1.5rem), default (2rem), lg (2.5rem) |
data-labels="below" |
Position labels below circles | On nav.steps |
--progress-height |
Height of progress bar track | 0.5rem, 0.75rem, 1rem |
--progress-fill |
Progress bar fill color | var(--color-interactive), var(--color-success) |
aria-current="step" |
Marks current step for screen readers | Apply to active step element |
aria-valuenow |
Current progress percentage | 0 to 100 |
Usage Notes
Step Validation
- Validate each step before allowing progression to the next
- Show inline validation errors using
<output class="error"> - Disable the "Next" button until required fields are valid
- Consider allowing users to skip optional steps
Saving Progress
- Auto-save form data to prevent loss on accidental navigation
- Use
sessionStorageor server-side persistence - Show a "saved" indicator when data is preserved
- Allow users to resume incomplete forms
Accessibility
- Use
aria-current="step"on the active step for screen readers - Add
role="progressbar"witharia-valuenow,aria-valuemin,aria-valuemax - Completed steps should have descriptive
aria-label(e.g., "Go back to Account step (completed)") - Announce step changes to screen readers with live regions
- Use
aria-disabled="true"on future steps that cannot be accessed - Ensure keyboard navigation works for clickable completed steps
Navigation Best Practices
- Always allow users to go back to previous steps
- Preserve form data when navigating between steps
- Disable future steps until prerequisites are complete
- Show a summary/review step before final submission
- Provide a "Save and exit" option for long forms
Related
Steps
Step indicator CSS pattern with variants and customization
Registration
Multi-step registration forms
Contact
Contact and inquiry forms
Form Field
Form field element with validation
Icon
Icon component for step indicators