Lesson 3 of 8

Error messages you can hear

Goal

Get the error across to people who can't see the color

01

Explanation

A red border around a field means nothing to a screen reader, or to someone who can't distinguish red at all. That's why you have to tie the error message to the field in the code itself.

Three attributes are all it takes: aria-describedby links the field to the message element, aria-invalid="true" announces that the field's value is wrong, and role="alert" on the message element makes the screen reader read it out as soon as it appears.

You can keep the color, but it becomes a reinforcement of the message, not the only way to deliver it.

02

Your task

When the form is submitted with the field empty, write the message, link it to the field and mark the field as invalid. When the user fixes the value, remove all of that.

Checks

5 checks
  1. The message element has role=alert
  2. Submitting with the field empty shows a message
  3. The field is announced as invalid
  4. The message is correctly linked to the field
  5. Fixing the value removes the error mark and the message
03

Hints

0/3
Track lessons0 of 8 done

In this track you'll write your own validation rules, tie one field to another, and write error messages a screen reader can announce.

Intermediate level, 8 lessons, 1.5 hours in total.

index.html
Preview
index.html100%
–/5

Press “Run and check” to grade your code.

5 checks listed under “Your task”.

Track lessons0 of 8 done

In this track you'll write your own validation rules, tie one field to another, and write error messages a screen reader can announce.

Intermediate level, 8 lessons, 1.5 hours in total.