JavaScript Element ariaErrorMessageElements Property

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline 2025
Instance property

What You’ll Learn

Element.ariaErrorMessageElements is an instance property that holds an array of elements providing an error message. Learn how it relates to aria-errormessage, how to pair it with ariaInvalid, and how to get or set the relationship from JavaScript—with five examples and try-it labs.

01

Kind

Instance property

02

Returns

HTMLElement[]

03

Writable

Yes (get / set)

04

Reflects

aria-errormessage

05

Status

Baseline 2025

06

Pairs with

ariaInvalid

Introduction

Form fields need a clear place for error text: “Enter a valid email address,” “Password is required,” and so on. ARIA links a control to that message with aria-errormessage.

ariaErrorMessageElements is the modern element-reference form: you work with real DOM nodes instead of only managing id strings. Pair it with ariaInvalid so the error is announced and styled when the field is invalid.

JavaScript
const msgs = email.ariaErrorMessageElements;
const text = msgs.map((e) => e.textContent.trim()).join(" ");
console.log(text);
💡
Beginner tip

Point the field at the error message element(s), then set ariaInvalid = "true" when validation fails and "false" when it passes. CSS can show or hide the message with [aria-invalid="true"].

Understanding the Property

MDN: the ariaErrorMessageElements property of the Element interface is an array containing the element (or elements) that provide an error message for the element it is applied to.

  • Get / set — read or assign an array of elements.
  • Flexible alternative to the aria-errormessage attribute.
  • No id required on message nodes when you set the property (MDN).
  • Reflection — reads valid in-scope id refs from the attribute; setting the property clears the attribute.

📝 Syntax

JavaScript
ariaErrorMessageElements

Value

An array of subclasses of HTMLElement. The inner text of these elements can be joined with spaces to get the error message.

  • When read, the returned array is static and read-only.
  • When written, the assigned array is copied—later edits to that array do not change the property.

⚖️ Property vs aria-errormessage Attribute

AttributeProperty
APIaria-errormessage="err1"el.ariaErrorMessageElements
Points toSpace-separated id stringsArray of Element objects
Targets need id?YesNo (when set via property)
After you set the propertyCorresponding attribute is cleared (MDN)

📋 Email Input With Error (MDN Shape)

MDN links an email field to an error span via aria-errormessage, then toggles ariaInvalid from Constraint Validation:

JavaScript
<p>
  <label for="email">Email address:</label>
  <input type="email" name="email" id="email" aria-errormessage="err1" />
  <span id="err1" class="errormessage">Error: Enter a valid email address</span>
</p>
JavaScript
const email = document.querySelector("#email");

email.addEventListener("input", () => {
  email.ariaInvalid = email.validity.typeMismatch ? "true" : "false";
});

Related: hide the message by default and show it when [aria-invalid="true"] is present (as in MDN’s CSS).

⚡ Quick Reference

GoalCode / note
Feature-detect"ariaErrorMessageElements" in Element.prototype
Readel.ariaErrorMessageElements
Writeel.ariaErrorMessageElements = [errSpan]
Show invalidel.ariaInvalid = "true"
Attribute formaria-errormessage="err1"
MDN statusBaseline Newly available (Apr 2025)

🔍 At a Glance

Four facts about Element.ariaErrorMessageElements.

Kind
get / set

Instance

Type
HTMLElement[]

Static copy

ARIA
aria-errormessage

Reflected

Baseline
2025

Newly available

Examples Gallery

Examples follow MDN Element: ariaErrorMessageElements. Labs feature-detect first so older browsers still show a clear message.

📚 Getting Started

Detect support and read MDN’s email error-message example.

Example 1 — Feature-Detect

Check whether the reflected property exists.

JavaScript
if ("ariaErrorMessageElements" in Element.prototype) {
  console.log("ariaErrorMessageElements is supported");
} else {
  console.log("ariaErrorMessageElements not supported by browser");
}
Try It Yourself

How It Works

Matches MDN’s feature test before reading or writing the property.

Example 2 — Get Error Message Elements (MDN)

Read the attribute id, then the element array and joined error text.

JavaScript
const email = document.querySelector("#email");

console.log("aria-errormessage:", email.getAttribute("aria-errormessage"));

if ("ariaErrorMessageElements" in Element.prototype) {
  const propElements = email.ariaErrorMessageElements;
  console.log("count:", propElements.length);
  const text = propElements.map((e) => e.textContent.trim()).join(" ");
  console.log("Error message details:", text);
} else {
  console.log("ariaErrorMessageElements not supported by browser");
}
Try It Yourself

How It Works

The property resolves valid in-scope id references from aria-errormessage into real element objects.

📈 Set Array, Attribute Sync & Snapshot

Assign error nodes without ids and verify reflection rules.

Example 3 — Set Error Message Array

Assign an error span that has no id; the attribute is cleared after set.

JavaScript
const input = document.createElement("input");
const err = document.createElement("span");
input.type = "email";
err.textContent = "Error: Enter a valid email address";
document.body.append(input, err);

if ("ariaErrorMessageElements" in Element.prototype) {
  input.ariaErrorMessageElements = [err];
  console.log({
    count: input.ariaErrorMessageElements.length,
    attrAfterSet: input.getAttribute("aria-errormessage"),
    text: input.ariaErrorMessageElements.map((e) => e.textContent).join(" ")
  });
} else {
  console.log("ariaErrorMessageElements not supported by browser");
}
Try It Yourself

How It Works

MDN: setting the property clears the corresponding attribute. Error message nodes do not need ids when linked this way.

Example 4 — Attribute Ids vs Resolved Elements

Compare the id string with the resolved element ids from the property.

JavaScript
const email = document.querySelector("#email");

console.log({
  fromAttribute: email.getAttribute("aria-errormessage"),
  supported: "ariaErrorMessageElements" in Element.prototype,
  fromProperty: "ariaErrorMessageElements" in Element.prototype
    ? email.ariaErrorMessageElements.map((el) => el.id)
    : null
});
Try It Yourself

How It Works

Prefer the property in script when supported; keep id-based aria-errormessage as a markup fallback for older browsers.

Example 5 — Support Snapshot

Feature-detect and remember the ariaInvalid pairing.

JavaScript
console.log({
  supported: "ariaErrorMessageElements" in Element.prototype,
  tip: "Returned array is static/read-only; assigned arrays are copied",
  pairsWith: "ariaInvalid true/false when validation fails",
  status: "Baseline Newly available (MDN, Apr 2025)"
});
Try It Yourself

How It Works

Re-assign a fresh array when error message nodes change. Do not mutate an old array and expect the relationship to update.

🚀 Common Use Cases

  • Email, password, and other inputs with dedicated error message elements.
  • Custom form controls that need ARIA error association.
  • Dynamic UIs that attach error nodes without assigning ids.
  • Showing/hiding errors with CSS based on aria-invalid.
  • Custom elements via ElementInternals.ariaErrorMessageElements.

🔧 How It Works

1

You point the field at error nodes

Via aria-errormessage ids or an element array.

Wire
2

Validation fails or passes

Constraint Validation or your own checks update state.

Validate
3

Set ariaInvalid true / false

CSS and AT react to the invalid state.

Flag
4

Users get a clear error association

The message elements explain what to fix.

📝 Notes

Browser Support

Element.ariaErrorMessageElements is Baseline Newly available (MDN: across latest browsers since April 2025). Feature-detect on older engines and keep an aria-errormessage id fallback if needed. Logos use the shared browser-image-sprite.png sprite from this project.

Baseline 2025

Element.ariaErrorMessageElements

HTMLElement[] — reflected aria-errormessage element references.

Baseline Newly available 2025
Google Chrome Supported in current releases — feature-detect older
Yes
Microsoft Edge Supported in current releases — feature-detect older
Yes
Mozilla Firefox Supported in current releases — feature-detect older
Yes
Apple Safari Supported in current releases — feature-detect older
Yes
Opera Follow Chromium support
Yes
Internet Explorer Not supported — use aria-errormessage attribute
No
ariaErrorMessageElements Baseline

Bottom line: Detect "ariaErrorMessageElements" in Element.prototype. Prefer element arrays for dynamic error text. Pair with ariaInvalid. Fall back to aria-errormessage id strings when the property is missing.

Conclusion

ariaErrorMessageElements lets you associate error message elements with a control using real Element references. Feature-detect on older browsers, pair with ariaInvalid, and re-assign the array when message nodes change.

Continue with ariaExpanded, ariaDisabled, EventTarget, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Feature-detect before using the property
  • Pair with ariaInvalid when validation fails
  • Keep error text clear and actionable
  • Assign a fresh array when message nodes change
  • Keep id-based aria-errormessage as a fallback

❌ Don’t

  • Mutate a previously assigned array and expect updates
  • Assume every older browser exposes the IDL property
  • Leave ariaInvalid true after the field is fixed
  • Point to empty or unrelated elements
  • Confuse this with a general description (aria-describedby)

Key Takeaways

Knowledge Unlocked

Five things to remember about ariaErrorMessageElements

Reflected aria-errormessage as an array of element references.

5
Core concepts
📝 02

Element array

HTMLElement[]

Type
🔍 03

No id needed

when property-set

Rule
04

Baseline

newly available

Status
🎯 05

ariaInvalid

show when invalid

Pair

❓ Frequently Asked Questions

An array of HTMLElement subclasses that provide an error message for the element. Join their inner text with spaces to form the error message string.
No. MDN marks Element.ariaErrorMessageElements as Baseline 2025 (newly available since April 2025). It is not Deprecated, Experimental, or Non-standard. Feature-detect on older browsers.
The attribute uses space-separated id strings. The property uses Element references. Assigned elements do not need an id. Setting the property clears the corresponding attribute.
Wire the error message elements with ariaErrorMessageElements (or aria-errormessage), then set ariaInvalid to true when the field is invalid so assistive technologies and CSS can show the error.
No. When read, the returned array is static and read-only. When written, the assigned array is copied—later changes to that array do not update the property.
Yes. Custom elements can use ElementInternals.ariaErrorMessageElements for the same relationship from inside a component.
Did you know?

An error message association is most useful when the field is marked invalid. MDN’s email demo uses Constraint Validation’s typeMismatch to drive ariaInvalid, which in turn reveals the linked error text.

Next: Element ariaExpanded

Learn the reflected aria-expanded property for open and closed controls.

ariaExpanded →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful