Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

aria-invalid — report an invalid value

`aria-invalid` communicates a control’s error state but does not perform validation or prevent form submission.

Version: WAI-ARIA 1.2

Syntax

<input aria-invalid="true" aria-describedby="error">

Values are false, true, grammar, and spelling. The default signals no error. Choose the state from an actual check, usually after interaction or a submission attempt; do not unnecessarily mark a pristine empty form invalid.

Show a useful explanation and associate it with the field. Changing ARIA replaces neither HTML constraints nor server checks. When the value is corrected, remove the stale error and update the state accordingly.

The example detects digits in a name that requires letters and displays an explanation. The accessibility tree gets invalid state, but checkValidity() still returns true because no native constraint was set. This deliberately demonstrates the boundary rather than complete form validation.

Examples

<!doctype html><meta charset="utf-8">
<label for="name">Project name</label><input id="name" value="123" aria-describedby="error">
<p id="error" hidden>Use letters only.</p><output id="result"></output>
<script>
const input = document.querySelector('#name');
const invalid = !/^[A-Za-z]+$/.test(input.value);
input.setAttribute('aria-invalid', String(invalid));
document.querySelector('#error').hidden = !invalid;
document.querySelector('#result').textContent = 'marked=' + invalid + '; nativeValid=' + input.checkValidity();
</script>

Result

marked=true; nativeValid=true

The test checks a visible explanation and semantic error, distinguishing them from native field validity.

Sources