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*
Fundamentals
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.
Concept
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 tokens — true, false, grammar, spelling.
Baseline — widely available since October 2023 (MDN).
Foundation
📝 Syntax
JavaScript
ariaInvalid
Value
A string with one of the following values:
Value
Meaning (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.
Pattern
📋 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>
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)"
});
Element.ariaInvalid is Baseline Widely available (MDN: across browsers since October 2023). Logos use the shared browser-image-sprite.png sprite from this project.
Internet ExplorerNo ariaInvalid IDL — use setAttribute
No
ariaInvalidBaseline
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.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about ariaInvalid
Reflected aria-invalid string for validation state.
5
Core concepts
📄01
Get / set
on Element
Kind
📝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.