Start with a form and fieldsets
Wrap a form in form-fieldset-progress. Each
outermost fieldset becomes a step, named by its
legend. The component adds the navigation
buttons and progress indicator; no configuration attributes
are needed.
Before setup succeeds—or if JavaScript cannot load—the complete native form and Submit stay visible and usable. Don’t pre-hide later fieldsets: authored hidden fieldsets are excluded from ordinary steps.
Fill out Contact details and choose Next to reach Delivery address. Next checks the current section’s fields before advancing. Back returns to the previous section without validating it. Changing sections focuses the first available field. On Delivery address, the form’s submit button replaces Next. These demos show a submission result without sending form data.
Progress shows the current section’s position: Contact details is 1 of 2, so the bar is half full. Delivery address is 2 of 2, so the bar is full. Inactive steps are hidden, not disabled; their values remain in the form.
Code
<form-fieldset-progress>
<form action="/apply" method="post">
<fieldset>
<legend>Contact details</legend>
<label>Your name
<input name="name" required
autocomplete="name" />
</label>
<label>Email
<input name="email" type="email" required
autocomplete="email" />
</label>
</fieldset>
<fieldset>
<legend>Delivery address</legend>
<label>City
<input name="city" required
autocomplete="address-level2" />
</label>
<fieldset class="radio-group">
<legend>Delivery preference</legend>
<label><input name="delivery" type="radio"
value="standard" checked /> Standard</label>
<label><input name="delivery" type="radio"
value="express" /> Express</label>
</fieldset>
<label>Delivery notes (optional)
<textarea name="notes"></textarea>
</label>
</fieldset>
<button type="submit" name="action" value="apply">
Send application
</button>
</form>
</form-fieldset-progress>
Live example
Use a single fieldset
With one fieldset, the component shows the submit button immediately. Back and Next are hidden because there is no other section to visit. Progress and its label are also hidden.
Code
<form-fieldset-progress>
<form action="/subscribe" method="post">
<fieldset>
<legend>Newsletter</legend>
<label>Email
<input name="email" type="email" required />
</label>
</fieldset>
<button type="submit">Subscribe</button>
</form>
</form-fieldset-progress>
Live example
Customize the labels
Use your application’s wording
previous-label and
next-label change the button text.
progress-label changes the text beside
progress. Here, {current} is the current
section number, {total} is the number of
sections, and {legend} is the current
section’s legend.
Code
<form-fieldset-progress
previous-label="Previous"
next-label="Continue"
progress-label="Section {current} of {total}: {legend}">
<form action="/example" method="post">
<fieldset><legend>Contact</legend>
<label>Name <input name="name" /></label>
</fieldset>
<fieldset><legend>Delivery notes</legend>
<label>Notes <textarea name="notes"></textarea></label>
</fieldset>
<button type="submit">Send</button>
</form>
</form-fieldset-progress>
Live example
Include section names in the buttons
In a button label, {legend} is the
destination section’s name. Because these visible labels
already name the destination, the buttons use that text
as their accessible names without adding an
aria-label.
Code
<form-fieldset-progress
previous-label="Back to {legend}"
next-label="Continue to {legend}">
<form action="/example" method="post">
<fieldset><legend>Contact</legend>
<label>Name <input name="name" /></label>
</fieldset>
<fieldset><legend>Delivery notes</legend>
<label>Notes <textarea name="notes"></textarea></label>
</fieldset>
<button type="submit">Send</button>
</form>
</form-fieldset-progress>
Live example
For several forms, share the labels once and override only the wording that differs.
Place your own navigation controls
The *-ref attributes identify existing elements
by ID instead of generating them. This example places
progress above the form and buttons below it.
previous-ref identifies Back,
next-ref identifies Next, and
progress-ref and
progress-label-ref
identify progress and its label.
Each button outside the form uses
form="english-application" to associate it with
that form. The component updates these controls’ labels and
visibility just as it does for generated controls. Keep
navigation, progress, and its label outside the step
fieldsets, and don’t associate them with another form.
Author enhancement-only controls with hidden.
The component reveals each control when it is useful after
setup succeeds, and restores its authored visibility on
disconnect or setup failure. Leave Submit visible so the
form works without JavaScript. Hide controls themselves, not
an ancestor that also contains the native form.
Code
<form-fieldset-progress
previous-ref="english-back"
next-ref="english-next"
progress-ref="english-progress"
progress-label-ref="english-status">
<div class="custom-progress">
<label id="english-status"
for="english-progress" hidden>Application sections</label>
<progress id="english-progress"
value="1" max="3" hidden></progress>
</div>
<form id="english-application"
action="/volunteer" method="post">
<fieldset><legend>Contact</legend>
<label>Email
<input name="email" type="email" required />
</label>
</fieldset>
<fieldset><legend>Availability</legend>
<label>Hours available each week
<input name="hours" type="number"
min="1" max="40" required />
</label>
</fieldset>
<fieldset><legend>Experience</legend>
<label>Relevant experience
<textarea name="experience"></textarea>
</label>
</fieldset>
</form>
<nav class="custom-actions"
aria-label="Application sections">
<button id="english-back" type="button"
form="english-application" hidden>Back</button>
<button id="english-next" type="button"
form="english-application" hidden>Next</button>
<button type="submit"
form="english-application">Send application</button>
</nav>
</form-fieldset-progress>
Live example
Translate labels, maintain button icons
This example combines the label templates and ID references
above. The legends, submit button, and navigation templates
are in French. Each navigation button uses a
data-fieldset-progress-label span so the
component updates the text without replacing its arrow.
Code
<form-fieldset-progress
previous-ref="custom-back"
next-ref="custom-next"
progress-ref="custom-progress"
progress-label-ref="custom-status"
previous-label="Retour : {legend}"
next-label="Continuer : {legend}"
progress-label="Étape {current}/{total} : {legend}"
previous-aria-label="{label}, étape {current}"
next-aria-label="{label}, étape {current}">
<form action="/inscription" method="post">
<fieldset><legend>Coordonnées</legend>
<label>Votre nom
<input name="name" autocomplete="name" required />
</label>
</fieldset>
<fieldset><legend>Commentaires</legend>
<label>Votre message <textarea name="message"></textarea></label>
</fieldset>
<nav class="authored-navigation" aria-label="Sections du formulaire">
<label id="custom-status"
for="custom-progress" hidden>Progression</label>
<button id="custom-back" type="button" hidden>
<span aria-hidden="true">←</span>
<span data-fieldset-progress-label>Retour</span>
</button>
<progress id="custom-progress" value="1" max="2" hidden></progress>
<button id="custom-next" type="button" hidden>
<span data-fieldset-progress-label>Continuer</span>
<span aria-hidden="true">→</span>
</button>
<button type="submit">Envoyer</button>
</nav>
</form>
</form-fieldset-progress>
Live example
Add a review screen
Generate a summary of the answers
review-panel adds a final fieldset after
the authored sections. Its summary pairs field labels
with the current answers. Selects show option labels;
checkbox and radio groups show the selected choices. The
review counts as a section in progress, and Submit
appears there instead of Next.
Complete Contact and Delivery, then continue to Check your answers. Use Back to change an answer and return: the summary updates each time you enter review. Native validation runs before entering review and again on submission. Passwords, hidden inputs, and disabled controls are omitted.
Code
<form-fieldset-progress review-panel
review-label="Check your answers">
<form action="/delivery" method="post">
<fieldset><legend>Contact</legend>
<label>Name <input name="name" required /></label>
</fieldset>
<fieldset><legend>Delivery</legend>
<label for="review-country">Country</label>
<select id="review-country" name="country">
<option value="uk">United Kingdom</option>
<option value="ca">Canada</option>
</select>
<fieldset class="radio-group"><legend>Updates</legend>
<label><input type="checkbox" name="updates"
value="email" checked /> Email</label>
<label><input type="checkbox" name="updates"
value="sms" /> SMS</label>
</fieldset>
<label>Notes <textarea name="notes"></textarea></label>
<label>Attachments <input type="file" name="files" multiple /></label>
</fieldset>
<button type="submit">Send</button>
</form>
</form-fieldset-progress>
Live example
Supply a read-only review fieldset
Use review-ref instead of
review-panel to identify an outermost
fieldset in the same form. Give it a legend and
hidden; the component makes it the final
screen and reveals it there. An existing direct
dl receives the summary; otherwise one is
created. Keep the review read-only, without form
controls or links. Your legend supplies its title. It
needs a nonempty direct legend, no nested fieldsets,
editable content, or hidden ancestor. See the
review reference
for inclusion and labeling rules.
Code
<form-fieldset-progress review-ref="answers">
<form action="/example" method="post">
<fieldset><legend>Contact</legend>
<label>Name <input name="name" required /></label>
</fieldset>
<fieldset id="answers" hidden>
<legend>Confirm your details</legend>
<p>Check these answers before sending.</p>
<dl></dl>
</fieldset>
<button type="submit">Send</button>
</form>
</form-fieldset-progress>
Live example
review-label sets the generated title.
review-empty-label,
review-checked-label, and
review-unchecked-label translate “Not
provided,” “Selected,” and “Not selected.” These messages
are plain text. Without JavaScript, the generated screen
does not exist and the authored hidden review remains
hidden; Submit still works.
Listen for section changes
form-fieldset-progress:change fires after the
active section changes. Its detail includes
previousIndex, stepIndex,
stepCount, and the active
fieldset element. Indices start at zero.
Enter a name and choose Next, then Back. The output below shows the latest event, using the fieldset’s ID to represent the element. A failed validation does not switch this form’s section or emit a change event.
Code
<form-fieldset-progress id="events">
<form action="/example" method="post">
<fieldset id="event-contact">
<legend>Contact</legend>
<label>Name <input name="name" required /></label>
</fieldset>
<fieldset id="event-notes">
<legend>Delivery notes</legend>
<label>Notes <textarea name="notes"></textarea></label>
</fieldset>
<button type="submit">Send</button>
</form>
</form-fieldset-progress>
<pre id="section-event">No section change yet.</pre>
<script type="module">
const element = document.querySelector('#events');
const output = document.querySelector('#section-event');
element.addEventListener('form-fieldset-progress:change',
({ detail }) => {
output.textContent = JSON.stringify({
previousIndex: detail.previousIndex,
stepIndex: detail.stepIndex,
stepCount: detail.stepCount,
fieldset: detail.fieldset.id
}, null, 2);
});
</script>
Live example
Latest change event
No section change yet.
You can also animate section changes
form-fieldset-progress:beforechange fires after
navigation checks, before the section changes. Unlike
change, it can be canceled. This example’s
script uses that event and the
View Transition API
to slide between sections while keeping navigation in place.
Animation is supplied by the demo script, not a component
attribute.
Use Next and Back to see the slide direction change. Uncheck the animation option for immediate navigation. The example also uses immediate navigation when the browser does not support View Transitions or requests reduced motion. The code below shows excerpts from the complete animation script and demo styles.
Code
<label id="animation-option" hidden>
<input id="enable-transitions" type="checkbox" checked />
Animate section changes when motion is allowed
</label>
<form-fieldset-progress id="animated">
<form action="/delivery" method="post">
<div class="transition-pages">
<fieldset><legend>Contact</legend>
<label>Email
<input name="email" type="email" required />
</label>
</fieldset>
<fieldset><legend>Delivery</legend>
<label>City <input name="city" required /></label>
</fieldset>
<fieldset><legend>Delivery notes</legend>
<label>Notes <textarea name="notes"></textarea></label>
</fieldset>
</div>
<button type="submit">Send</button>
</form>
</form-fieldset-progress>
<!-- This example adds animation in a separate script. -->
<script type="module" src="./transitions.js"></script>
Live example
Form reset is supported too
An authored type="reset" button restores the
form controls’ default values and returns to the first
section. Enter a name, advance to Delivery notes, and choose
Start over to try it.
With no control reference attributes, the component moves this button before Back in the footer. With any control reference attribute, Reset stays where it was authored. The component does not create a Reset button.
Code
<form-fieldset-progress>
<form action="/example" method="post">
<fieldset><legend>Contact</legend>
<label>Name
<input name="name" autocomplete="name" required />
</label>
</fieldset>
<fieldset><legend>Delivery notes</legend>
<label>Notes <textarea name="notes"></textarea></label>
</fieldset>
<button type="submit">Send</button>
<button type="reset">Start over</button>
</form>
</form-fieldset-progress>
Live example
You can disable per-section validation
I highly recommend keeping per-section validation
enabled.
If you really want to turn it off,
no-validation removes the checks on forward
navigation, but does not turn off native submit validation.
Even with this feature disabled, when a field is found to be invalid on submit, the component will display the correct panel automatically so the user can see the issue.
In this example, Next reaches Delivery notes even with an empty Name field. Choosing Send profile then reveals the first section so the browser can report the required field.
Code
<form-fieldset-progress no-validation>
<form action="/profile" method="post">
<fieldset>
<legend>Profile</legend>
<label>Name <input name="name" required /></label>
</fieldset>
<fieldset><legend>Delivery notes</legend>
<label>Notes <textarea name="notes"></textarea></label>
</fieldset>
<button type="submit">Send profile</button>
</form>
</form-fieldset-progress>
Live example
Pair the navigation colors
Back, Next, and Reset use ButtonText on
ButtonFace by default. To give Next a custom
fill, set its foreground and background together. The accent
property colors native progress only; the visible section
label also tells you where you are. Submit keeps your
authored styles. Buttons keep the browser’s focus ring and
automatic forced-color adjustment.
Code
<style>
.paired-controls {
--fieldset-progress-accent: #173f63;
--fieldset-progress-next-background: #173f63;
--fieldset-progress-next-color: #fff;
}
</style>
<form-fieldset-progress class="paired-controls">
<form action="/apply" method="post">
<fieldset><legend>Contact</legend>
<label>Your name
<input name="name" autocomplete="name" required />
</label>
</fieldset>
<fieldset><legend>Delivery notes</legend>
<label>Notes <textarea name="notes"></textarea></label>
</fieldset>
<button type="submit">Send application</button>
<button type="reset">Start over</button>
</form>
</form-fieldset-progress>
Live example
Refresh after repairing configuration
If setup fails, the component restores the native form and
emits form-fieldset-progress:error. Correct the
configuration, then call refresh() to restart
at the first section without clearing entered values.
Structure changes also need refresh(); they
aren’t observed automatically.
This example has a missing Next reference. Repair configuration removes it and retries setup. The lifecycle reference explains restoration and editing managed markup.
Code
<form-fieldset-progress id="failure" next-ref="missing">
<form action="/example" method="post">
<fieldset><legend>First section</legend>
<p>This remains visible when setup fails.</p>
</fieldset>
<fieldset><legend>Second section</legend>
<p>So does this section.</p>
</fieldset>
<button type="submit">Send example</button>
</form>
</form-fieldset-progress>
<script type="module">
// After reporting the setup error:
const element = document.querySelector('#failure');
element.removeAttribute('next-ref');
element.refresh();
</script>
Live example
See the form without JavaScript
This embedded example loads no component script. Both fieldsets and the submit button remain visible; Back, Next, and progress are not generated.
Code
<!-- no-script.html omits the component script. -->
<dialog id="native-form" open aria-label="Native form example">
<h1>Native form fallback</h1>
<form-fieldset-progress>
<form method="dialog">
<fieldset><legend>Contact</legend>
<label for="fallback-name">Name</label>
<input id="fallback-name" name="name" autocomplete="name" required />
</fieldset>
<fieldset><legend>Delivery notes</legend>
<label>Notes <textarea name="notes"></textarea></label>
</fieldset>
<button type="submit">Send</button>
</form>
</form-fieldset-progress>
</dialog>