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.js controller — auto-initializes on form[data-wizard], handles step navigation, validation, and progress
  • nav.steps integration — auto-syncs step indicator state; auto-populates from legends when empty
  • Conditional steps (data-wizard-if) — show/hide steps based on user input, with AND/OR compound expressions
  • Optional steps (data-wizard-optional) — skip without validation
  • Summary/review step (data-wizard-summary) — auto-populate a review step with field values
  • Auto-injected navigation — Back/Next/Submit buttons created automatically when nav is omitted
  • Programmatic API — wizardNext(), wizardPrev(), wizardGoTo(), wizardReset()
  • Custom events — wizard:step-change, wizard:complete, wizard:reset
  • Visual patterns — numbered step indicators, tab navigation, and progress bars
  • Accessibility — aria-current="step", live regions, roving tabindex 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-summary <fieldset> Summary/review step — auto-populated with field values
data-wizard-field="name" any element Inside summary step, displays the named field's value
data-wizard-steps="#id" <form> Points to a nav.steps element for auto-sync (auto-populates from legends if empty)

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)
data-wizard-if="a:x && b:y" AND — show when all conditions are true
data-wizard-if="a:x || a:y" OR — show when any condition is true

AND (&&) has higher precedence than OR (||).

Summary / Review Step

Add data-wizard-summary to a step fieldset to create a review step. The wizard populates it with form values each time the step becomes active.

Manual Mode

Place elements with data-wizard-field="fieldName" to control exactly which values appear and where:

Auto Mode

If no data-wizard-field elements are present, a <dl> is auto-generated from all non-empty fields across visible steps. Labels are detected from <label> associations.

Auto-Injected Navigation

If no [data-wizard-nav] element exists in the form, the wizard automatically injects a Back / Next / Submit navigation bar. This allows minimal wizard markup:

Auto-Populated Step List

When a nav.steps element contains an empty <ol>, the wizard auto-populates <li> items from each step's <legend> text. This eliminates the need to duplicate step names between fieldset legends and the navigation list.

Keyboard Navigation

The step indicator (nav.steps) uses the roving tabindex pattern for keyboard access:

  • Arrow Right / Arrow Down — move focus to next step item
  • Arrow Left / Arrow Up — move focus to previous step item
  • Home — move focus to first step item
  • End — move focus to last step item
  • Enter / Space — activate completed step items to navigate back

Only the current step item is in the tab order (tabindex="0"). All other items have tabindex="-1" and are reachable only via arrow keys.

API & Events

Access the wizard programmatically via methods attached to the form element:

Custom Events

Event Detail Fires when
wizard:step-change { 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 sessionStorage or 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" with aria-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