Sub topic 11
Making Forms and Step Changes Accessible
Assume you know basic HTML form elements, JavaScript or TypeScript, and how browsers submit form data. This chapter focuses on keyboard users, screen reader users, and people who need clear status messages while moving through a multi-step form.
Give every field a usable name
A field needs a visible label, a programmatic label, instructions when needed, and an error message that assistive technology can discover. A programmatic label connects the label element to the input through matching identifiers.
<div>
<label for="email">Email address</label>
<input id="email" name="email" type="email" autocomplete="email" required
aria-describedby="email-hint email-error" aria-invalid="true">
<p id="email-hint">We only use this to send your receipt.</p>
<p id="email-error">Enter an email address in the format [email protected].</p>
</div>The for attribute gives the input its accessible name. The aria-describedby attribute points to supporting text. Use aria-invalid only when the current value fails validation. Do not mark every empty required field invalid before the user has interacted with it.
Group related controls with fieldset and legend. For example, a group of radio buttons should have one question in the legend, while each radio button has its own label. This gives screen reader users the group context as they move between choices.
Make errors discoverable and actionable
An error should identify the field, explain what is wrong, and state how to fix it. Avoid messages such as “Invalid input.” Put the message near the field and connect it with aria-describedby.
When a step contains errors, also provide a summary near the top of the step. The summary should be a list of links that move focus to the affected fields. This helps keyboard users avoid searching through the page.
Use a live region for status changes that are not already obvious from focus movement. For example, announce that a step has loaded or that a draft was saved. Do not put every keystroke into a live region.
<div id="step-status" role="status" aria-live="polite"></div>
<nav aria-label="Checkout steps">
<ol>
<li><span aria-current="step">Account</span></li>
<li>Details</li>
<li>Review</li>
</ol>
</nav>The aria-current attribute identifies the current step. A status region with polite priority waits for a suitable pause before announcing its message.
Manage focus when the step changes
A multi-step form changes the page without a full navigation. After moving forward or backward, place focus on the new step heading or the first invalid field. Otherwise, keyboard and screen reader users may remain focused on a button while the visible content changes around them.
Make the heading focusable without making it part of the normal tab order. A common pattern is a heading with tabindex set to minus one. After rendering, call focus on that heading. Do not move focus unexpectedly while the user is typing.
The Back button should preserve values and should not trap focus. A keyboard user must be able to reach every control in a predictable order. Do not use positive tabindex values, because they create a separate and fragile tab sequence.
Test the complete interaction
Accessibility testing should include the flow, not only individual fields.
| Check | Expected result |
|---|---|
| Keyboard navigation | Every control is reachable with Tab and usable without a pointer |
| Step change | Focus moves to the new heading or first invalid field |
| Error recovery | The message is announced and explains how to fix the value |
| Screen reader context | Each field exposes its label, hint, state, and group |
| Back navigation | Previously entered values remain available |
Test with a keyboard, browser accessibility tools, and at least one screen reader. Also test zoom, narrow screens, slow network responses, and validation errors on every step.
Exercise
After a user selects Next and the next step renders, where should focus go, and where should it go if validation fails?
Show answer
Focus the new step heading when validation succeeds. If validation fails, focus the first invalid field and expose its connected error message.