Make sure that error and alert messages are accessible to screen reader users. 

General Guidelines

Provide labels or instructions when content requires user input.

Ensure that data entered by the user is checked for input errors and the user is provided an opportunity to correct them.

Do not rely on color alone to convey the error or alert message when something is not completed correctly or missing. 

Provide a description and the nature of the error message and how to correct it. Example: “Please provide the correct date of birth. The primary applicant must be 18 years of age or older”. 

Declare form controls as invalid and display inline error messages once the form control has lost focus, or there has been an adequate delay in key presses (a few seconds)

Using ARIA to Create Accessible Inline Error Messages

Make inline error messages accessible to screen reader users by adding ARIA labels.

Code Examples:

Default Error Message Treatment

<form novalidate>
<label for="name"> Name:</label>
<input id="name" aria-required="true" required aria-invalid="false">
</form>

Invalid Error Message Treatment

<form novalidate>
<label for="name">  Name:</label>
<input id="name" aria-required="true" required aria-describedby="name_msg" aria-invalid="true">
<span id="name_msg">Please enter your name.</span>
</form>
<form novalidate>
<label for="Email">  Email:</label>
<input id="Email" aria-required="true" required aria-describedby="emal_msg" aria-invalid="true">
<span id="email_msg">The email address entered is invalid.</span>
</form>

https://codepen.io/TPG/pen/3b68c22db120c0960503fe892bb2c068

Declaring Form Controls as Invalid

Wait to declare form controls as invalid until the form control has lost focus, or there has been an adequate delay in key presses (maybe a few seconds).

Example Default State:

<form novalidate>

<label for="name"> Name:</label>

<input id="name" required aria-invalid="false">

</form>

Example Invalid Error Message State:

<form novalidate>

<label for="name">  Name:</label>

<input id="name" required aria-describedby="name_msg" aria-invalid="true">

<span id="name_msg">Please enter your name.</span>

</form>

Code Example: https://codepen.io/TPG/pen/3b68c22db120c0960503fe892bb2c068


References

Please see our forms guide for additional information on error message acceptance criteria.

Error Messaging