How to Make Forms Accessible: Labels, Errors and Focus
An accessible form gives every field a visible, programmatically linked label, tells people what is required before they submit, explains errors in text next to the field and in a summary, and moves keyboard focus to where the user needs to be. Native HTML elements do most of this for you, so start with them. This guide shows the code for each part and the WCAG criteria behind it.
Why do forms fail accessibility audits so often?
Forms are where people complete tasks: logging in, booking, paying. They are also where custom controls, scripts and styling tend to break the basics. Typical failures are placeholder-only labels, errors shown only in red, focus lost after a failed submit and fields that cannot be reached with a keyboard.
How do you label form fields correctly?
Every input needs a label that is visible and connected to the field. This covers 1.3.1 Info and Relationships, 3.3.2 Labels or Instructions, 2.4.6 Headings and Labels and 4.1.2 Name, Role, Value.
Use a <label> with a for attribute that matches the input's id:
<label for="email">Email address</label>
<input type="email" id="email" name="email" autocomplete="email">
You can also wrap the input in the label:
<label>
Email address
<input type="email" name="email" autocomplete="email">
</label>
Clicking the label focuses the field, which also helps people with small hands or motor impairments.
Is a placeholder a label?
No. A placeholder disappears when you type, often has low contrast, and is not reliably announced as a label. Use it for an example at most, never instead of a label.
Bad:
<input type="text" placeholder="Full name">
Good:
<label for="name">Full name</label>
<input type="text" id="name" name="name" autocomplete="name">
What if the design has no visible label?
Prefer a visible label. If a design truly cannot show one, for example a search box next to a clearly labeled button, use aria-label as a fallback. Visible labels also satisfy 2.5.3 Label in Name, which asks that the accessible name contains the visible text.
How do you group related fields?
Use <fieldset> and <legend> for groups such as radio buttons, checkboxes and address blocks, so the group's question is announced with each option.
<fieldset>
<legend>Delivery method</legend>
<label><input type="radio" name="delivery" value="standard"> Standard</label>
<label><input type="radio" name="delivery" value="express"> Express</label>
</fieldset>
How do you show which fields are required?
Say so in text, and say it before the form starts. Do not rely on a red asterisk alone.
<p>Fields marked "required" must be filled in.</p>
<label for="phone">Phone number (required)</label>
<input type="tel" id="phone" name="phone" autocomplete="tel" required>
The required attribute tells assistive technology the field is required. If you use an asterisk, explain it at the top of the form, and consider adding the word "required" so it does not depend on color or symbols. This supports 3.3.2 and 1.4.1 Use of Color.
How does autocomplete help?
The autocomplete attribute lets browsers and password managers fill in fields, and it is required for fields that collect personal data under 1.3.5 Identify Input Purpose.
<input type="text" name="fname" autocomplete="given-name">
<input type="text" name="lname" autocomplete="family-name">
<input type="email" name="email" autocomplete="email">
<input type="text" name="street" autocomplete="street-address">
<input type="text" name="zip" autocomplete="postal-code">
Use the right type too (email, tel, number where appropriate) so mobile keyboards match.
How do you write accessible error messages?
Errors must be identified in text (3.3.1 Error Identification) and, where the fix is known, suggest it (3.3.3 Error Suggestion). Do not use color alone to show an error.
Bad: a red border and no text.
Good: text next to the field, linked to it, and the field marked invalid.
<label for="email">Email address</label>
<input
type="email"
id="email"
name="email"
autocomplete="email"
aria-invalid="true"
aria-describedby="email-error">
<p id="email-error" class="error">
Error: Enter an email address in the format name@example.com
</p>
aria-invalid="true"marks the field as invalid for screen readers.aria-describedbylinks the error text so it is read with the field.- The message says what went wrong and how to fix it. "Invalid input" is not enough.
- Add an icon or the word "Error", so the message does not depend on red.
- Make sure the error text has enough contrast. See how to fix color contrast errors.
How should you handle focus after a failed submit?
When a user submits a form with errors, keyboard and screen reader users need to know it failed and where to go. Two common patterns work:
1. An error summary at the top, with focus moved to it. It lists each error with a link to the field.
<div id="error-summary" tabindex="-1" role="alert">
<h2>There are 2 problems with your form</h2>
<ul>
<li><a href="#email">Enter an email address in the format name@example.com</a></li>
<li><a href="#phone">Enter a phone number with at least 10 digits</a></li>
</ul>
</div>
const summary = document.getElementById("error-summary");
summary.focus();
2. Focus on the first invalid field, with its error message linked by aria-describedby.
Pick one pattern and use it everywhere. Do not leave focus on the submit button with no explanation, and do not move focus somewhere unexpected.
How do you announce messages without moving focus?
Status messages such as "Saving...", "Saved" or "3 items added" should be announced without moving focus (4.1.3 Status Messages). Use a live region:
<div role="status" aria-live="polite" id="form-status"></div>
document.getElementById("form-status").textContent = "Your details were saved.";
Use role="alert" only for urgent errors, because it interrupts the user.
When should you validate: while typing or on submit?
Validating on every keystroke is noisy for screen reader users, and it shows errors before people finish typing. A safer default is to validate when a field loses focus or when the form is submitted. If you do validate live, keep messages short, and do not announce them on every key press.
What else do accessible forms need?
- Keyboard access. Every control works with Tab, Shift+Tab, Enter, Space and arrow keys (2.1.1 Keyboard). Use real
<button>,<input>and<select>elements, not clickable<div>s. - Visible focus. Do not remove focus outlines without a replacement (2.4.7 Focus Visible).
- Control contrast. Input borders need at least 3:1 against the background (1.4.11).
- Target size. Radios, checkboxes and buttons should be at least 24 by 24 CSS pixels or have enough spacing (2.5.8 Target Size (Minimum)).
- No unexpected changes. Changing a field should not submit the form or move focus without warning (3.2.2 On Input).
- Don't ask twice. Prefill information the user already gave in the same process (3.3.7 Redundant Entry).
- Accessible login. Allow paste and password managers, and offer an alternative to puzzles or transcribed codes (3.3.8 Accessible Authentication (Minimum)).
- Review before the final step. For legal, financial or data-changing submissions, let users review, correct or confirm (3.3.4 Error Prevention (Legal, Financial, Data)).
- Time limits. Warn users and let them extend (2.2.1 Timing Adjustable).
Do not block pasting into password or email fields.
How do multi-step forms stay accessible?
- Show where the user is, for example "Step 2 of 4: Delivery", in text.
- Keep labels and instructions the same across steps.
- Move focus to the new step's heading when it loads.
- Keep entered data when users go back.
- Offer a summary before the final submit.
How do you test a form?
- Complete the form using only the keyboard.
- Submit it empty and with invalid data, and check what is announced and where focus goes.
- Zoom to 200% and check nothing is cut off.
- Test with a screen reader such as NVDA or VoiceOver. Does each field announce its label, required state and error?
- Run an automated scan to catch missing labels. See the best free accessibility testing tools.
Kerbwise audits the page you have open against WCAG 2.2 Level A and AA and ranks accessibility issues by severity, with the WCAG number, who is affected and how to fix each one. It is automated, so the keyboard and screen reader checks above still apply. See how to run a website accessibility audit for the full process.
Try Kerbwise on a page you own
Try Kerbwise ($29 one-time) to run this audit locally and export a client-ready PDF report. Get it on the Chrome Web Store or read more on the Kerbwise page.
Frequently asked questions
Do all form fields need labels?
Yes. Every field needs a label that is visible and linked to the input. A placeholder is not a label.
How should I show form errors accessibly?
Show the error as text next to the field, link it with aria-describedby, mark the field with aria-invalid="true", and add a summary at the top. Do not rely on color alone.
Should I use aria-required or the required attribute?
Use the native required attribute where you can, and say in text which fields are required. Native attributes are better supported than extra ARIA.
Where should focus go after a failed submit?
To an error summary at the top of the form, or to the first invalid field. Pick one pattern and use it everywhere.
Is it okay to block pasting into a password field?
No. Blocking paste stops password managers and can fail 3.3.8 Accessible Authentication (Minimum). Allow it.