Sub topic 11
Making forms and step changes accessible
This chapter assumes you can write semantic HTML form markup, know basic TypeScript, and have read the earlier chapters on field anatomy, error messages, and navigation. It covers what to add so keyboard and screen reader users can complete a multi-step form as easily as mouse users.
Why multi-step forms break accessibility
A single-page form on a normal page works with assistive technology almost by default. The browser loads a page, the screen reader announces the title, and focus starts at the top.
A multi-step form usually changes content in place without a page load. Three problems follow:
- The user presses "Next" and the button disappears. Focus is lost, often reset to the top of the document.
- A screen reader announces nothing, so the user does not know the step changed.
- Errors appear visually, but nothing tells the user they exist or where they are.
Your job is to replace the cues a page load gives for free. You do this with correct markup, explicit focus management, and a small number of announcements.
Field-level foundations
Every control needs an accessible name, a way to find its hint and error, and a machine-readable purpose. The anatomy chapter covered these. This table summarizes what each attribute does for assistive technology.
| Feature | What it does | Common mistake |
|---|---|---|
| `label` with `for` | Gives the control its name and enlarges the click target | Using `placeholder` as the only label, which disappears on input |
| `autocomplete` token | Lets the browser and assistive tools fill known data, such as `email` or `given-name` | Leaving it off or inventing token names |
| `aria-describedby` | Reads the hint and error after the label | Pointing to an id that does not exist |
| `aria-invalid="true"` | Announces the field as invalid | Setting it before the user has had a chance to answer |
| `fieldset` and `legend` | Names a group, such as radio buttons or an address block | Using a `div` with a bold heading instead |
Radio buttons and checkbox groups need special care. A screen reader reads the legend before each option, so "Delivery method, Ship to me" makes sense and a bare "Ship to me" does not.
<fieldset>
<legend>Delivery method</legend>
<div>
<input type="radio" id="delivery-ship" name="delivery" value="ship">
<label for="delivery-ship">Ship to me</label>
</div>
<div>
<input type="radio" id="delivery-pickup" name="delivery" value="pickup">
<label for="delivery-pickup">Pick up in store</label>
</div>
</fieldset>Do not mark a field invalid before the user has touched it. Use the touched and dirty state from the state chapter to decide when aria-invalid and the error text appear.
Presenting errors so they are found
Inline errors alone are not enough. A screen reader user who presses "Next" and stays on the same step gets no signal that anything failed. Use two layers.
- An error summary at the top of the step, listing every problem, with each item linking to its field.
- An inline message next to each field, connected through
aria-describedby.
When validation fails on "Next" or "Submit", render the summary and move focus to it. Focus is the announcement: the screen reader reads the summary heading and the user can move through the links.
<div id="error-summary" tabindex="-1" hidden>
<h2>There is a problem</h2>
<ul></ul>
</div>function showErrorSummary(errors: Record<string, string>): void {
const summary = document.getElementById("error-summary");
const list = summary?.querySelector("ul");
if (!summary || !list) return;
list.replaceChildren();
for (const [name, message] of Object.entries(errors)) {
const item = document.createElement("li");
const link = document.createElement("a");
link.href = `#${name}`;
link.textContent = message;
link.addEventListener("click", (event) => {
event.preventDefault();
document.getElementById(name)?.focus();
});
item.append(link);
list.append(item);
}
summary.hidden = false;
summary.focus();
}The click handler matters. A plain #email link scrolls to the field but does not always move keyboard focus into it. This code assumes each field's id equals its name, as in the earlier examples.
Do not put role="alert" on every inline error. When several fields fail at once, the screen reader announces them all, interrupting itself. Reserve live announcements for single, unexpected messages.
Error text must not depend on color alone. Pair the red styling with the words "Error:" or an icon with a text alternative. Keep the message wording from the error-messaging chapter: say what is wrong and how to fix it.
Managing focus and context on step changes
When the step changes, three things should happen together:
- The old step is hidden, using the
hiddenattribute so it also leaves the accessibility tree. - Focus moves to the heading of the new step.
- The document title updates to include the step number.
Focusing the heading makes the screen reader read it, which tells the user where they are. A heading is not focusable by default, so give it tabindex="-1". That makes it focusable by script but keeps it out of the normal tab order.
function showStep(stepId: string, index: number, total: number): void {
document.querySelectorAll<HTMLElement>("[data-step]").forEach((section) => {
section.hidden = section.dataset.step !== stepId;
});
const section = document.querySelector<HTMLElement>(`[data-step="${stepId}"]`);
const heading = section?.querySelector<HTMLElement>("h2");
if (!section || !heading) return;
document.title = `Step ${index + 1} of ${total}: ${heading.textContent} - Sign up`;
heading.tabIndex = -1;
heading.focus();
}Call this function from your reducer's subscriber after the step value changes. Do not call it on the first render, or you will steal focus from the page's own start.
Include "Step 2 of 3" in the visible heading text or in visually hidden text inside it. Then the screen reader reads the position without extra work.
Progress indicators
Build the progress indicator as an ordered list inside a nav with a label. Mark the current step with aria-current="step". Add hidden text for completed steps, because a green check mark means nothing to a screen reader.
<nav aria-label="Progress">
<ol>
<li>Account <span class="visually-hidden">(completed)</span></li>
<li aria-current="step">Details</li>
<li>Review</li>
</ol>
</nav>Only make earlier steps links or buttons if jumping back is a supported action. A list item that looks clickable but is not will confuse everyone.
Keyboard behavior
Use real button elements for "Back" and "Next". Give "Back" type="button" so it never submits the form. Test these points with the mouse unplugged:
- Tab order follows the visual order. If you reorder with CSS, the DOM order still decides.
- Focus is always visible. Never remove the outline without a replacement.
- Pressing Enter in a text field triggers the same action as the primary button, which is usually "Next".
- Nothing traps focus. A step is not a modal dialog.
- Touch and pointer targets are large enough to hit, at least 24 by 24 CSS pixels under WCAG 2.2.
If your flow uses the browser history for the Back button, restore focus to the step heading in the same way. Otherwise the history change is silent.
Conditional fields
A field that appears because of an earlier answer needs three things. It must be reachable only when visible, so use hidden and not opacity: 0 or an off-screen position. It must come right after the control that reveals it in DOM order. It must not move focus on its own. The user chose a radio button, and jumping to a new field is disorienting.
Matching the logic chapter, a hidden field is not validated and not submitted. The accessibility side of the same rule is that it is also not announced and not focusable.
Common errors
- Focus stays on a removed "Next" button, so the next Tab starts from the top of the page.
- The summary appears but focus does not move to it, so screen reader users never learn it exists.
- Step headings are styled
divelements, which makes heading navigation useless. - The title never changes, so "Sign up" is announced on every step.
- Placeholder text is the only label, and it vanishes once the user types.
- A timeout or draft restore reloads the form without telling anyone. Announce "Draft restored" in a
role="status"element.
Verifying the flow
Walk through each step with the keyboard and note where focus lands after every action: Next, Back, a failed validation, a revealed field, and a restored draft. Record the expected landing spot beforehand, then compare. These checks make good automated end-to-end tests, because you can assert document.activeElement after each action. The testing chapter returns to this.
Exercise
A user on step 2 of a three-step form presses "Next" with an empty required field. Visually, a red message appears under the field. A screen reader user hears nothing. Name two changes that fix this and say what each one does.
Show answer
First, render an error summary at the top of the step and move focus to it, so the screen reader reads the heading and the list of problems. Each summary item links to its field and moves focus there on click. Second, connect the inline message to the input with aria-describedby and set aria-invalid="true", so the error is read when the user reaches the field. Do not rely on color alone for the message.
Exercise
After the user passes validation on step 1, your code hides step 1 and shows step 2. Why is a screen reader user still lost, and what is the minimal fix?
Show answer
The focused element, the Next button, was hidden, so focus is lost and nothing announces the new content. The fix is to move focus to the new step's heading, which needs tabindex="-1" to be focusable by script. Also update document.title to include the step number.