Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Visual Example

Search Default

...

Suggestion/Popup List Expanded

...

Required Form Control

...

Invalid Form Control

...

Acceptance Criteria

As a screen reader and keyboard only user I should:

  • be provided with an inline error message when the form control has been declared as invalid

  • be provided with the inline error message once the form control has lost focus, or there has been an adequate delay in key presses (a few seconds)

  • be provided with a description and the nature of the error message and how to correct it

...

  • the screen reader should announce that it is a required elemententry

When the invalid form control has lost keyboard focus: 

  • the screen reader should announce that this is an invalid entry

  • the screen reader should announce what the error is and how to correct the error

...

Markup and Code

Use ARIA to Create Accessible Inline Error Messages

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

  • Most screen reader and browser combinations announce a form control as “required” required when using the required “required” attribute.

  • Prevent screen readers from announcing required form controls as invalid by default (when the form control first receives keyboard focus), by using aria-invalid="false".

  • Update the aria-invalid attribute to “true” if the current value (or lack of value) of a required control does not pass validation.Wait to declare form controls as invalid and display inline error messages once the control has lost focus, or there has been an adequate delay in key presses (a few seconds)

  • Use aria-describedby on required form controls to point to an element that will contain any necessary the inline error messagingmessage on how to resolve the error.

  • Can’t always rely on browser’s client-side error validation to be accessible.

  • Create a custom client-side validation script and helpful messaging by suppressing the browser’s default validation message by adding the novalidate attribute to the form element. 

Markup - Default Error Message TreatmentRequired Form Control

Code Block
<form novalidate>
<label for="namefname">>First Name:</label>
<input id="name" aria-required="truefname" required aria-invalid="false">
</form>

Markup - Invalid Error Message Treatment

Code Block
<form novalidate>
<label for="namefname"> >First Name:</label>
<input id="namefname" aria-required="true" required aria-describedby="namefname_msg" aria-invalid="true">
<span id="namefname_msg">Please enter your first 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>

...

View Markup on github

View HTML, CSS and Javasript Code