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

General Guidelines

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

Provide a description of the nature of the error message as well as an anchor link to the location of the error message. Example: “Please provide the correct date of birth. The primary applicant must be 18 years of age or older”.

Non-Compliant Error Message Treatment

 

Compliant Error Message Treatment

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" hrequired aria-invalid="false">
</form>

Invalid Error Message Treatment

<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>
<form novalidate>
<label for="Email">  Email:</label>
<input id="Email" 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

Provide Users With a List of Error Messages

In addition to using inline error message treatments it can also be helpful to list out the error messages at the top of the form.

Provide direct links to the form elements that require input or need to be corrected.

This is especially helpful when multiple required form fields have been left empty by the user. 

The list of error messages can be triggered once the user has attempted to submit the form.