Accessible Forms
What makes a form accessible?
- Clean HTML with semantic tags.
- Organized, meaningful and easy to use.
- Use appropriate aria information.
- A screen reader can make sense of the formatting.
- Keyboard users can complete and move logically through the form.
- All mouse and pointer events translate to keyboard events.
- Clear visual cues when a form element is in focus.
- Proper labels and instructions.
- Provide clear input errors.
Example form:
<form method="post" action="#">
<label for="name">Name</label>
<input
type="text"
name="name"
id="name"
required
aria-label="Enter your name"
aria-required="true"
/>
<label for="email">Email</label>
<input
type="email"
name="email"
id="email"
required
aria-label="Enter your email"
aria-required="true"
/>
<fieldset>
<legend aria-label="Select a subject">
Select a subject:
</legend>
<input id="payments" type="checkbox" name="subject" value="payments" />
<label for="payments">Payments</label>
<input id="purchases" type="checkbox" name="subject" value="purchases" />
<label for="purchases">Purchases</label>
<input id="question" type="checkbox" name="subject" value="question" />
<label for="question">Question</label>
<input id="suggestion" type="checkbox" name="subject" value="suggestion" />
<label for="suggestion">Suggestion</label>
</fieldset>
<label for="message">Message</label>
<textarea name="message" id="message" rows="5" aria-label="Enter a message" />
<button type="submit">Send</button>
<input type="reset" value="Clear" />
</form>
Other things to consider:
-
You may want a Skip Navigation link at the top of your page. Allows a keyboard user to:
- Skip tabbing through the entire navigation menu.
- Get right to the main content of the site.
- Confirm contrast is ok for visually impaired people.
- Test the site with Lighthouse and/or aXe.
-
Do your own manual tests:
- Use the site with a screen reader.
- Use the site with a keyboard.