data-wizard
Multi-step form wizard with per-step validation, conditional steps, and progress tracking. Add data-wizard to a form to split fieldsets into navigable steps.
Overview
The data-wizard attribute transforms a standard form with multiple fieldsets into a multi-step wizard. Each <fieldset data-wizard-step> becomes a navigable step with per-step validation, conditional visibility, and progress tracking. This page is an attribute-focused API reference.
For full walkthroughs and pattern examples, see the Wizard Pattern page.
How It Works
Add data-wizard to a <form> containing multiple <fieldset data-wizard-step> elements. The init script:
- Discovers all
[data-wizard-step]fieldsets within the form - Shows the first step and hides the rest with
data-wizard-active/data-wizard-hidden - Wires up
data-wizard-prevanddata-wizard-nextbuttons for navigation - Validates the current step's fields before advancing (native constraint validation)
- Evaluates
data-wizard-ifconditions to skip inapplicable steps - Updates
<progress>and externalnav.stepsif connected - Sets
data-wizard-enhancedon the form to prevent double-binding
The submit button is only enabled on the final step. On earlier steps, clicking Next validates the current step before proceeding.
Attributes
| Attribute | Element | Description |
|---|---|---|
data-wizard |
<form> |
Enables wizard behavior on the form. |
data-wizard-step |
<fieldset> |
Marks a fieldset as a wizard step. |
data-wizard-progress |
<progress> |
Auto-updated progress bar. Value reflects current step / total steps. |
data-wizard-nav |
<nav> |
Container for navigation buttons. The wizard manages button visibility. |
data-wizard-prev |
<button> |
Go to previous step. Hidden on the first step. |
data-wizard-next |
<button> |
Go to next step (validates current step first). Hidden on the last step. |
data-wizard-if |
<fieldset> |
Conditional step. Formats: "name:value", "name:!value", "name", "!name". |
data-wizard-optional |
<fieldset> |
Step can be skipped without validation. |
data-wizard-steps |
<form> |
CSS selector for an external nav.steps element to sync as progress nav. |
data-wizard-enhanced |
<form> |
Auto-set after init. Do not set manually. |
data-wizard-active / data-wizard-hidden |
<fieldset> |
Auto-set to mark the visible step and hide inactive steps. |
data-wizard-current / data-wizard-total |
<form> |
Auto-set with current step index (1-based) and total visible steps. |
data-wizard-last |
<form> |
Auto-set when on the final step. |
Progress Bar
Add a <progress data-wizard-progress> element inside the form. The wizard sets its value and max attributes automatically as the user navigates.
Conditional Steps
Use data-wizard-if on a fieldset to make it conditional. The step is only included in the wizard flow when the condition matches. Skipped steps do not count toward the total and their validation is bypassed. Four condition formats are supported:
name:value— show when field equals valuename:!value— show when field does not equal valuename— show when field has any truthy value!name— show when field is empty or unchecked
External Steps Navigation
Use data-wizard-steps on the form with a CSS selector pointing to an external nav.steps element. The wizard synchronizes the nav's list items with the current step, applying aria-current="step" to the active item. The nav can be placed anywhere on the page.
Events
| Event | Detail | Description |
|---|---|---|
wizard:stepchange |
{ from, to } |
Fired on step navigation. Indices are 0-based. |
wizard:complete |
— | Fired when the form is submitted from the final step. |
wizard:reset |
— | Fired when the wizard is reset to the first step. |
JavaScript API
The wizard adds navigation methods directly to the form element:
form.wizardNext()— advance to next step (validates current step first)form.wizardPrev()— go back to previous step (no validation)form.wizardGoTo(index)— jump to step by 0-based indexform.wizardReset()— reset to first step and clear progress
Styling
Step visibility is controlled via data-wizard-active and data-wizard-hidden attributes. Nav buttons are automatically shown or hidden based on step position.
All behavior is gated on data-wizard-enhanced. Without JavaScript, all fieldsets are visible and the form submits normally — progressive enhancement.
Accessibility
- A live region announces the current step (e.g., "Step 2 of 3") when navigating
- External
nav.stepsusesaria-current="step"on the active step - Hidden steps are removed from tab order so keyboard users only interact with the active step
- Per-step validation prevents advancing past incomplete steps with immediate feedback
- The
<progress>element provides a native accessible progress indicator - Back is hidden on the first step; Submit is only visible on the final step
- Without JavaScript, all fieldsets are visible and the form submits as one page
See Also
Wizard Pattern — full walkthroughs, layout examples, and step-by-step tutorials.