Track 03 · Lesson 7 of 8Building for everyone

Track 03 · Building for everyone

Helpful, accessible errors

Lesson 7 of 8· 7 min

Good validation tells people exactly what's wrong and how to fix it, in text, next to the field, and in a way screen readers announce. Submit the form empty in both versions.

Submit it empty

Then fill it in properly

What a screen reader user hears on submit

Submit the form empty to find out.

The techniques

<input placeholder="Email">

<!-- On error: a red border and a vague message -->
<p class="red">Please fix the errors.</p>

What the helpful form does differently#

  • Visible labels, not placeholders. A placeholder disappears the moment you start typing, and some screen readers never read it.
  • Messages that say what to do: "Enter an email address like name@example.com", not "Invalid".
  • Errors tied to their fields with aria-describedby, and flagged with aria-invalid, so a screen reader reads the message when you land on the field.
  • A summary on submit, with focus moved to it and a link to each broken field.
  • Rules shown up front, like the password checklist, so people don't have to fail first to learn them.
  • The right autocomplete values, so browsers and password managers can fill the form in.

Don't fight the browser#

Allow pasting into password fields. Blocking paste doesn't make anything safer; it just breaks password managers and pushes people towards weak passwords they can type from memory.

Check yourself

An input has a placeholder “Email” but no label. What's wrong?