Forms and validation: Error messages
An error needs both a specific explanation and a programmatic relationship to the invalid control.
Current edit
Understand the pattern
An error needs both a specific explanation and a programmatic relationship to the invalid control.
An error needs both a specific explanation and a programmatic relationship to the invalid control.
Misconceptions to reject
- A visual appearance alone guarantees the intended HTML meaning.
- Replacing semantic elements with generic divs automatically improves accessibility.
The preview is a sanitized subset, not a full browser compatibility test.
Worked example and expected result
<label for="email">Email</label><input id="email" type="email" aria-invalid="true" aria-describedby="email-error"><p id="email-error">Enter an address including @.</p>An error needs both a specific explanation and a programmatic relationship to the invalid control.
Explain it
Apply it elsewhere
Keep the momentum.
Complete the lab, then explain and apply the pattern.
Next: Forms and validation: Input descriptionsTry an incident drillAnonymous lesson and mastery progress lasts for this session. Sign in to keep synced lesson XP between sessions; mastery stays device-local. No speed bonus, lost lives, or hint penalties.
Keep learning
- 01Forms and validation: Help text relationshipsaria-describedby associates a control with help text identified by an existing element id.Practice
- 02Forms and validation: Input descriptionsA placeholder is not a replacement for a visible label or persistent help text.Practice
- 03Forms and validation: Grouped choicesfieldset and legend give a related set of form controls a shared accessible name.Practice