Accessible forms
Every field
<div class="field">
<label for="email">Email address</label>
<p id="email-hint" class="hint">We'll send the receipt here.</p>
<input id="email" name="email" type="email" autocomplete="email" required
aria-describedby="email-hint email-error" aria-invalid="true">
<p id="email-error" class="error">Enter an email address in the format name@example.com</p>
</div>
- A visible
<label>tied withfor/id. Placeholders are not labels: they disappear and often fail contrast. - Right
type(email,tel,url,numberonly for real numbers,date) andinputmodefor on-screen keyboards. autocompletetokens (name,given-name,email,tel,street-address,postal-code,cc-number,one-time-code,new-password,current-password) so browsers and password managers fill fields (WCAG 1.3.5).- Group related controls with
<fieldset>+<legend>(radio groups, address blocks). - Mark required fields in the label text (“Email (required)”) or mark the optional ones; do not rely on color or an unexplained asterisk alone.
Validation
- Validate on submit, and on blur for fields the user has finished; do not show errors while they are still typing the first time.
- Error messages say what is wrong and how to fix it, in plain words, next to the field, linked with
aria-describedby, witharia-invalid="true"on the field. - On submit with errors: show an error summary at the top (a heading plus links to each field), move focus to it, and update the page
<title>(e.g. “Error: Checkout”). - Do not clear what the user typed. Keep values after a failed submit (also WCAG 3.3.7 Redundant Entry: do not ask for the same information twice in a process).
- Errors must not be shown by color alone; add an icon or text.
- For dynamic messages that are not tied to a field (e.g. “Saved”), use a polite live region (
role="status").
Authentication (WCAG 2.2, 3.3.8)
Do not require a cognitive test (remembering or transcribing) to log in: allow paste into password and code fields, support password managers (autocomplete="current-password"), and offer alternatives to puzzles.
Custom controls
Prefer native <select>, <input type="checkbox">, <input type="radio">, styled with CSS (appearance, accent-color). If you must build a custom combobox, listbox or switch, follow the ARIA Authoring Practices pattern exactly (roles, aria-expanded, aria-activedescendant or roving tabindex, arrow keys, Escape) and test with a keyboard and a screen reader.
Checklist before shipping
- Can be completed with keyboard only, in a logical order
- Every control has a visible label and correct autocomplete
- Errors are specific, adjacent, announced, and summarized on submit
- Works at 320 px width and 200% zoom
- Focus indicator visible on every control (3:1 contrast)
- Touch targets at least 24x24 CSS px
- Nothing times out without warning, or the user can extend it