JavaScript Element ariaInvalid Property

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

What You’ll Learn

Element.ariaInvalid is an instance property that reflects the aria-invalid attribute. Learn the true, false, grammar, and spelling tokens, when assistive tech treats a value as invalid, and how to get or set the property from JavaScript—with five examples and try-it labs.

01

Kind

Instance property

02

Type

String

03

Values

true · false · grammar · spelling

04

Reflects

aria-invalid

05

Status

Baseline widely

06

Pairs with

ariaErrorMessage*

Introduction

Forms and custom widgets often check whether a value matches what the app expects—an email shape, a required choice, or correct spelling. Sighted users may see a red border; assistive technology users need the same signal in the accessibility tree.

aria-invalid carries that signal. ariaInvalid is the JavaScript reflection of that attribute.

JavaScript
const el = document.getElementById("quote");
console.log(el.ariaInvalid); // null when omitted
el.ariaInvalid = "grammar";
💡
Beginner tip

Set ariaInvalid when validation fails, and clear it to "false" (or remove the attribute) when the value is fixed. Pair with ariaErrorMessageElements so users hear why the field is invalid.

Understanding the Property

MDN: the ariaInvalid property of the Element interface reflects the value of the aria-invalid attribute. Relevant for roles such as application, checkbox, combobox, gridcell, listbox, radiogroup, slider, spinbutton, textbox, and tree, it indicates to the accessibility API whether the entered value does not conform to the format expected by the application.

  • Reflected attribute — mirrors aria-invalid.
  • Get / set — readable and writable string.
  • Four tokenstrue, false, grammar, spelling.
  • Baseline — widely available since October 2023 (MDN).

📝 Syntax

JavaScript
ariaInvalid

Value

A string with one of the following values:

ValueMeaning (MDN)
"true"The element is invalid.
"false"The element is not in an invalid state (default).
"grammar"Invalid because a grammatical error was detected.
"spelling"Invalid because a spelling error was detected.
⚠️
How assistive technology treats values (MDN)

If the attribute is missing or set to the empty string, AT treats the value as false. If the attribute is present but set to something other than false, grammar, spelling, or "", AT treats it as true. The property reflects the attribute value as set, not as normalized by AT.

📋 MDN Example Shape

MDN starts with a contenteditable textbox that omits aria-invalid (so the property is null, treated like valid), then sets "grammar" because of errors in the text:

JavaScript
<div id="quote" role="textbox" contenteditable>you are your best thing..</div>
JavaScript
const el = document.getElementById("quote");
console.log(`Initial value: ${el.ariaInvalid}`);
el.ariaInvalid = "grammar";
console.log(`Updated value: ${el.ariaInvalid}`);

⚡ Quick Reference

GoalCode / note
Readel.ariaInvalid
Mark invalidel.ariaInvalid = "true"
Mark validel.ariaInvalid = "false"
Grammar errorel.ariaInvalid = "grammar"
Spelling errorel.ariaInvalid = "spelling"
Error messagePair with ariaErrorMessageElements
MDN statusBaseline Widely available

🔍 At a Glance

Four facts about Element.ariaInvalid.

Kind
get / set

Instance

Type
string

Validation state

Reflects
aria-invalid

Attribute

Baseline
widely

Oct 2023+

Examples Gallery

Examples follow MDN Element: ariaInvalid. Labs use a textbox-style control so you can safely read and write the property.

📚 Getting Started

Read the reflected value and follow MDN’s grammar update.

Example 1 — Read ariaInvalid

Log the initial value when aria-invalid is omitted.

JavaScript
const el = document.getElementById("quote");
console.log(el.ariaInvalid);

// HTML omits aria-invalid → often null (AT treats as false)
Try It Yourself

How It Works

When the attribute is missing, many browsers return null. Assistive technology still treats that as not invalid (false).

Example 2 — MDN Update to "grammar"

MDN: mark a textbox invalid because of grammar issues.

JavaScript
const el = document.getElementById("quote");
console.log(`Initial value: ${el.ariaInvalid}`);
el.ariaInvalid = "grammar";
console.log(`Updated value: ${el.ariaInvalid}`);
Try It Yourself

How It Works

Assigning the property updates the reflected aria-invalid attribute so assistive technologies can announce the invalid (grammar) state.

📈 Form Invalid State, Attribute Sync & Snapshot

Practice generic invalid marking and verify reflection.

Example 3 — Set "true" on an Input

Mark a required email field invalid after a failed check.

JavaScript
const input = document.createElement("input");
input.type = "email";
input.setAttribute("aria-label", "Email");
document.body.appendChild(input);

input.ariaInvalid = "true";
console.log({
  ariaInvalid: input.ariaInvalid,
  attr: input.getAttribute("aria-invalid")
});
Try It Yourself

How It Works

Use "true" for general validation failures. Prefer "spelling" or "grammar" when those are the specific error kinds.

Example 4 — Property vs getAttribute

Confirm the attribute stays in sync after a write.

JavaScript
const el = document.createElement("div");
el.setAttribute("role", "textbox");
el.setAttribute("contenteditable", "true");
el.textContent = "teh quick brown fox";
document.body.appendChild(el);

el.ariaInvalid = "spelling";
console.log({
  fromProperty: el.ariaInvalid,
  fromAttribute: el.getAttribute("aria-invalid"),
  same: el.ariaInvalid === el.getAttribute("aria-invalid")
});
Try It Yourself

How It Works

Prefer ariaInvalid in script; keep the attribute for HTML markup.

Example 5 — Support Snapshot

Feature-detect and list the allowed tokens.

JavaScript
console.log({
  supported: "ariaInvalid" in Element.prototype,
  allowed: ["true", "false", "grammar", "spelling"],
  tip: "Pair invalid state with ariaErrorMessageElements for why",
  status: "Baseline Widely available (MDN)"
});
Try It Yourself

How It Works

Keep ariaInvalid in sync with your validation logic, and clear it when the value becomes valid again.

🚀 Common Use Cases

  • Marking required fields invalid after submit or blur checks.
  • Flagging grammar or spelling issues in editable textboxes.
  • Syncing custom widget validation with the accessibility tree.
  • Clearing invalid state when the user corrects the value.
  • Keeping script and markup aligned without manual setAttribute.

🔧 How It Works

1

User enters a value

In a textbox, combobox, slider, or similar role.

Input
2

App validation fails

Format, required, grammar, or spelling rules do not pass.

Check
3

Set ariaInvalid (and error message)

Use true, grammar, or spelling; link helpful error text.

Announce
4

Assistive tech announces invalid state

Users know the field needs fixing—and ideally why.

📝 Notes

Browser Support

Element.ariaInvalid is Baseline Widely available (MDN: across browsers since October 2023). Logos use the shared browser-image-sprite.png sprite from this project.

Baseline Widely available

Element.ariaInvalid

String true / false / grammar / spelling — reflects aria-invalid for validation state.

Baseline Widely available
Google Chrome Supported (ARIA reflection)
Yes
Microsoft Edge Supported (ARIA reflection)
Yes
Mozilla Firefox Supported (ARIA reflection)
Yes
Apple Safari Supported (ARIA reflection)
Yes
Opera Follow Chromium support
Yes
Internet Explorer No ariaInvalid IDL — use setAttribute
No
ariaInvalid Baseline

Bottom line: Use ariaInvalid when a control's value fails app expectations. Prefer grammar or spelling when those apply. Pair with ariaErrorMessageElements so users hear why, and clear the state when fixed.

Conclusion

ariaInvalid reflects aria-invalid so forms and widgets can tell assistive technologies when a value is wrong—generally, or specifically for grammar and spelling. Keep it in sync with your validation logic and link a clear error message.

Continue with ariaKeyShortcuts, ariaErrorMessageElements, EventTarget, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Set invalid state when validation fails
  • Clear to false when the value is fixed
  • Use grammar / spelling when specific
  • Link error text with ariaErrorMessageElements
  • Test announcements with a screen reader

❌ Don’t

  • Leave fields marked invalid after the user fixes them
  • Rely only on color (red borders) without ARIA state
  • Invent random tokens and expect specific AT wording
  • Announce invalid without explaining how to fix it
  • Forget native HTML constraint validation when it fits

Key Takeaways

Knowledge Unlocked

Five things to remember about ariaInvalid

Reflected aria-invalid string for validation state.

5
Core concepts
📝 02

Four tokens

true false grammar spelling

Values
🔍 03

Missing = valid

AT treats as false

Default
04

Baseline

widely available

Status
🎯 05

Error message

pair for why

Pair

❓ Frequently Asked Questions

It reflects the aria-invalid attribute as a string, telling the accessibility API whether the entered value does not conform to the format expected by the application.
No. MDN marks Element.ariaInvalid as Baseline Widely available (since October 2023). It is not Deprecated, Experimental, or Non-standard.
The strings "true", "false" (default), "grammar", or "spelling". Prefer grammar or spelling when those are the specific error kinds.
If aria-invalid is not present or is set to the empty string, assistive technology treats the value as false. The property itself often returns null when the attribute is omitted.
When a field is invalid, point to helpful error text with aria-errormessage / ariaErrorMessageElements so users hear why it failed.
Yes. Reading and writing ariaInvalid updates the reflected aria-invalid attribute. The property reflects the attribute value as set, not how assistive technology may normalize unknown tokens.
Did you know?

Native HTML constraint validation (for example required or type="email") and aria-invalid can both appear in the same UI. For custom widgets without native validity, ariaInvalid is often the main way to expose that state to assistive technologies.

Next: Element ariaKeyShortcuts

Learn the reflected aria-keyshortcuts property for documented keyboard shortcuts.

ariaKeyShortcuts →

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