Aria-invalid identifies a control whose current value failed validation; an associated message explains how to repair it.
HTML aria-invalid: connect a failed field to a repair instruction
When it earns its place
A server rejects a case reference after a search request because the value has the wrong format. The response returns the submitted value, marks only that field invalid, and puts a plain-language repair instruction beside it. The instruction has an id used by aria-describedby, so the field and the reason stay connected. This state belongs to a failed submission, not to an untouched form. For a full-page response, also provide a visible error summary near the top when several controls fail.
<form action="/cases/search" method="get">
<label for="case-lookup">Case reference</label>
<input id="case-lookup" name="reference" value="C47" aria-invalid="true" aria-describedby="case-lookup-error" required>
<p id="case-lookup-error">Enter two letters followed by four digits, such as CD0047.</p>
<button type="submit">Search cases</button>
</form>Browser boundary
Aria-invalid communicates state; it does not run validation or prevent submission. The server must still check syntax, permission, and whether the case exists. Remove the invalid state after the user corrects the value or after a successful response.
Cost and maintenance
One attribute and a message have negligible load cost. The main maintenance cost is keeping error state, text, and actual validation rule aligned across client and server rendering.
Common Mistakes
- Do not mark every empty required field invalid before interaction.
- Do not show only a red border with no repair text.
- Do not leave aria-invalid=true after the error has cleared.
Connected lessons
- HTML form help: connect visible instructions and errors to a control
- HTML constraint validation: improve feedback without trusting the browser
- HTML required versus aria-required: semantics do not replace validation
Apply this in HTML form error project: return values, summary links, and field repairs.
