Rule

Error message linkage

Fields marked invalid need their error described in text.

Rule
error-message-linkage
WCAG 2.2
3.3.1 Error Identification (opens in a new tab) (Level A)
Severity
Serious

What it checks

The rule looks at fields the page has marked as in error with aria-invalid="true", "spelling" or "grammar", and at any element with aria-errormessage. A page shows this state only while an error is displayed, so on a form nobody has submitted the rule usually finds nothing.

A field marked invalid passes when its aria-errormessage points at a visible element with text, or, when it has no aria-errormessage, when its aria-describedby does. An aria-errormessage on a field that is not marked invalid passes, because assistive technology follows it only while the field is invalid.

When a person decides

The rule never fails. A field marked invalid with no linked error text, or with an aria-errormessage that points at nothing, at an empty element or at a hidden one, is sent for review. WCAG asks for the error to be described in text, not for the text to be linked in code, so a visible message beside the field can meet the criterion on its own. A person needs to check that a message exists and says what is wrong.

Example

Sent to review

<label for="email">Email</label>
<input id="email" type="email" aria-invalid="true">
<p>Enter an email address in the format name@example.com</p>

Passes

<label for="email">Email</label>
<input id="email" type="email" aria-invalid="true" aria-describedby="email-error">
<p id="email-error">Enter an email address in the format name@example.com</p>

The engine is tested against both examples.

How to fix it

Put the error text next to the field and reference it with aria-describedby or aria-errormessage, so a screen reader announces it with the field.

Check your own pages

This rule runs in every pour audit: the browser extension, the bookmarklet, the command line and the editor. Get pour, free.