The person must guess what format will be accepted.
<input class="error" value="alex@">
<span>Invalid input</span>
Accessible HTML forms
A red border says something changed. A useful error says what happened, where it happened, and how to recover.
The principle
Do not make people hunt, guess, or rely on color. Bring them to the error and explain the next step.
Do / Don’t
“Invalid” confirms failure but does not help someone succeed. Name the field’s problem in text and include a known correction or example.
The person must guess what format will be accepted.
<input class="error" value="alex@">
<span>Invalid input</span>
Text identifies both the problem and a path to correction.
<input aria-invalid="true"
aria-describedby="email-error">
<p id="email-error">
Enter an email address in the format
name@example.com.
</p>
The error formula
No single ARIA attribute creates an accessible error experience. Combine clear language, visible styling, programmatic state, association, and deliberate focus behavior.
Identify what is wrong and, when known, how to fix it.
Use text and a strong visual treatment—not color alone.
Set aria-invalid and connect the message with aria-describedby.
After submission, move focus to the field or an error summary. Avoid announcing the same error twice.
Interactive demo
Submit an empty or incomplete email address, then observe the complete error state.
aria-invalid="true".Implementation
The error starts hidden. It becomes both visible and programmatically associated only after validation fails. Once corrected, the invalid state and error relationship are removed.
<label for="email">Email address (required)</label>
<p id="email-hint">We will send the receipt here.</p>
<input id="email" name="email" type="email"
required aria-describedby="email-hint">
<p id="email-error" hidden></p>
<button type="submit">Send receipt</button>
input.setAttribute('aria-invalid', 'true');
input.setAttribute(
'aria-describedby',
'email-hint email-error'
);
error.hidden = false;
input.focus();
input.removeAttribute('aria-invalid');
input.setAttribute('aria-describedby', 'email-hint');
error.hidden = true;
error.textContent = '';
Quick test
For forms with several errors: add a summary at the top with links to each invalid field. Focus the summary after submission so people understand the scope before correcting individual fields.