The HTML aria-errormessage attribute
The aria-errormessage attribute references the id of the element that holds a field's validation error message. It only takes effect when the field is also marked aria-invalid="true".
Overview
The aria-errormessage attribute references the element that contains the validation error message for a field.
It is a relationship property: it wires elements together for assistive technology by referencing their ids. The element(s) you point at must exist in the DOM with matching ids, and the relationship is exposed only to assistive technology — it has no visual effect, so you still style and lay out the page normally.
Like all ARIA, aria-errormessage 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="email-err">
<p id="email-err">Enter a valid email.</p>
Values
| Value |
|---|
| A single element id. |
Example
<label for="email">Email</label>
<input id="email" aria-invalid="true" aria-errormessage="err">
<p id="err">Please enter a valid email address.</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.
- Reference real elements — every target
idmust exist in the DOM. - Remember the relationship is conveyed only to assistive technology and has no visual effect.
- Prefer native associations (a <label>'s
for, a <table>'s structure) where they exist.
Frequently asked questions
What does aria-errormessage do?
How does this attribute reference another element?
id. The element(s) you point at must exist in the DOM with matching ids.