References

Beginner-friendly references for web development, with live, editable examples.

The HTML aria-invalid attribute

ARIA Accessibility All modern browsers Updated
Quick answer

The aria-invalid attribute tells assistive technology that a field's value has failed validation. Values: false (default), true, grammar or spelling. Pair it with aria-errormessage to point at the error text.

Overview

The aria-invalid attribute indicates that the value of a field has failed validation.

It is a widget state: a condition that can change as the user interacts. Because ARIA does nothing on its own, you must update this value in JavaScript every time the underlying state changes; a stale state is worse than none. And wherever a native element already expresses the same thing (a checkbox's checked state, the disabled attribute, a <details>'s open state), use that instead.

Like all ARIA, aria-invalid changes only the accessibility tree (what assistive technology perceives), never the element's behavior or appearance. The first rule of ARIA applies: if a native HTML element or attribute conveys this, use that instead, and only reach for ARIA when nothing native fits.

Syntax

<input aria-invalid="true" aria-errormessage="err">

Values

Value
false | true | grammar | spelling

Example

Live example
<input aria-invalid="true" aria-errormessage="e1">
<p id="e1">That email is already taken.</p>

Best practices

  • Follow the first rule of ARIA: use a native HTML element or attribute that conveys this where one exists, rather than adding ARIA.
  • Update the value in JavaScript whenever the state changes; keep it in sync with reality.
  • Use the matching native state where one exists (a checkbox's checked, the disabled attribute, a <details>'s open state) instead of the ARIA version.
  • Set it only on an element whose role actually supports this state.

Frequently asked questions

What does aria-invalid do?
Indicates that the value of a field has failed validation.
Does setting this attribute change how the element behaves?
No. ARIA changes only what assistive technology perceives. You must implement the behavior yourself and keep the attribute in sync in JavaScript.
What happens if the element's role does not support this state?
Assistive technology ignores it. Every role defines the states it supports, so check the role before adding one; an unsupported combination can make a widget harder to understand, not easier.
Do I need aria-invalid if native HTML already conveys it?
Usually not. ARIA is for what native HTML cannot express; redundant or incorrect ARIA can make accessibility worse. Reach for it only when no native element fits.