Form Errors
This lesson explains Form Errors in web accessibility with clear examples, practical use cases, and implementation best practices.
Accessible Form Errors Overview
Accessible form error handling helps users identify, understand, and
correct mistakes when completing forms. Error messages should be clear,
descriptive, easy to locate, and accessible to keyboard users and screen
readers.
Good error handling goes beyond displaying red text. Developers should
clearly explain what went wrong, how to fix it, associate errors with the
affected fields, and announce validation messages using semantic HTML and
appropriate ARIA attributes when necessary.
| Feature | Benefit |
| Clear Error Messages | Help users understand the problem. |
| Field Association | Links errors to the correct input field. |
| Screen Readers | Announce validation errors automatically. |
| Keyboard Navigation | Allows users to quickly reach invalid fields. |
| WCAG Compliance | Supports accessible form validation. |
| User Experience | Reduces frustration and improves completion rates. |
Accessible Error Message Example
<label for="email">
Email Address
</label>
<input
id="email"
type="email"
aria-describedby="email-error"
aria-invalid="true">
<p id="email-error">
Please enter a valid email address.
</p>
The aria-invalid attribute identifies the field as invalid,
while aria-describedby associates the input with its error
message so screen readers announce both together.
Common Form Validation Techniques
Accessible forms should provide meaningful feedback before, during, and
after validation. Different techniques help users recover from errors
efficiently.
| Technique | Purpose | Example |
| Required Field | Identify mandatory inputs. | Name and Email fields. |
| Inline Error | Display validation next to the field. | Invalid email format. |
| Error Summary | List all errors at the top of the form. | Registration forms. |
| aria-invalid | Identify invalid controls. | Form validation. |
| aria-describedby | Associate fields with error messages. | Password requirements. |
| Focus Management | Move focus to the first error. | Form submission. |
Accessible Form Error Best Practices
| Best Practice | Description |
| Write Clear Messages | Explain exactly what is wrong and how to fix it. |
| Use More Than Color | Add icons or text instead of relying only on red highlights. |
| Associate Errors | Connect messages with inputs using aria-describedby. |
| Move Focus | Send keyboard focus to the first invalid field. |
| Use aria-invalid | Indicate invalid fields to assistive technologies. |
| Validate in Real Time Carefully | Avoid displaying errors before users finish entering data. |
Common Form Error Mistakes
- Using only color to indicate validation errors.
- Displaying vague messages such as "Invalid Input".
- Not associating error messages with form controls.
- Failing to move keyboard focus to invalid fields.
- Showing errors before users finish typing.
- Using alert dialogs for every validation message.
- Not announcing validation errors to screen readers.
- Removing error messages before users can read them.
Key Takeaways
- Error messages should clearly explain the problem and its solution.
- Never rely on color alone to communicate validation errors.
- Use
aria-invalid and aria-describedby for accessible error handling. - Move keyboard focus to the first invalid field after submission.
- Provide inline validation near the affected form control.
- Accessible error handling improves usability, accessibility, and WCAG compliance.
Pro Tip
Instead of displaying "Invalid Input," write actionable messages such as
"Enter a valid email address in the format name@example.com." Helpful
error messages reduce user frustration and significantly improve form
completion rates.