Skip to main content

Blog

Form error messages that help people fix the problem

· 6 min read

A red border and "Invalid input" help nobody. How to write form errors people can find, understand and fix, with the HTML for each step and how to test your own forms.

Blog cover with the title: Form error messages that help people fix the problem.

Forms are where websites earn their money: the checkout, the booking, the contact form, the newsletter sign-up. They are also where many visitors give up, and error messages are a big part of why.

A typical bad error looks like this: the page reloads, one field gets a thin red border, and a message at the top says "Please correct the errors below." A sighted mouse user may spot the red border. Someone using a screen reader hears nothing at all. Someone with colour vision deficiency sees a border that looks like every other border. Someone with a cognitive disability sees that something is wrong, but not what to do about it.

Good error messages fix all of that, and they help every visitor, not only disabled people. Here's how.

What WCAG asks for

The Web Content Accessibility Guidelines have a few success criteria that cover form errors directly:

  • Error identification (3.3.1, level A): when an error is detected automatically, say which field has the problem and describe the error in text.
  • Error suggestion (3.3.3, level AA): if you know how to fix it, tell the person.
  • Labels or instructions (3.3.2, level A): give the instructions people need before they make the mistake.
  • Use of color (1.4.1, level A): colour can't be the only way to show which field is wrong.
  • Error prevention (3.3.4, level AA): for legal, financial and data submissions, let people check, correct or undo before it's final.

In plain words: say what's wrong, where it's wrong and how to fix it, in text, and don't rely on red.

Write the message first

Most of the work is the words. A good error message:

  • Names the field. "Enter your email address", not "This field is required."
  • Says what's wrong in human terms. "The card number is too short", not "Validation failed" or an error code.
  • Says how to fix it. "Enter a date in the format 21/03/1990" or "Your password needs at least 8 characters."
  • Doesn't blame. "Enter a phone number" reads better than "You entered an invalid phone number."
  • Is short. One sentence is usually enough.

Some before and after examples:

  • "Invalid input" → "Enter your postcode, for example SW1A 1AA"
  • "Required" → "Enter your first name"
  • "Error 422" → "That email address is already registered. Log in or use a different email address."
  • "Wrong format" → "Enter the date as day, month and year, for example 21 3 1990"

The GOV.UK Design System publishes its error message guidance and examples for common fields. It's a good free reference even if your site looks nothing like a government service.

Put the error next to the field, in the code

The message needs to be visible next to the field and connected to it in the HTML, so a screen reader reads it when the person lands on the field.

<!-- Before: a red border and nothing else -->
<label for="email">Email</label>
<input id="email" name="email" type="email" class="error">
<!-- After: the error is text, it's next to the field and it's connected -->
<label for="email">Email address</label>
<p id="email-error" class="field-error">
  <span class="visually-hidden">Error:</span>
  Enter an email address in the correct format, like name@example.com
</p>
<input id="email" name="email" type="email" autocomplete="email"
       aria-invalid="true" aria-describedby="email-error">

What each part does:

  • The label is a real <label> connected with for and id. Without it, nothing else matters much (see form labels).
  • aria-describedby points to the message, so screen readers read it after the label.
  • aria-invalid="true" tells assistive technology the field currently has an error. Remove it once the field is fixed.
  • The hidden word "Error:" makes the message clear when it's read out of context. The red colour and icon are for sighted visitors; the text works for everyone.
  • autocomplete="email" lets browsers fill the field, which prevents many errors in the first place (see autocomplete).

For the styling, add something besides colour: an icon, a bold message, a thicker border. And check that the red text passes contrast against its background. Plenty of error reds don't; our contrast checker tells you in a second.

Add an error summary for longer forms

On a form with more than two or three fields, put a summary at the top that lists every error, with each item linking to its field. Then move keyboard focus to the summary when the form is submitted, so screen reader and keyboard users start right there.

<div class="error-summary" tabindex="-1" id="error-summary">
  <h2>There is a problem</h2>
  <ul>
    <li><a href="#email">Enter an email address in the correct format, like name@example.com</a></li>
    <li><a href="#phone">Enter a phone number, like 01632 960 001</a></li>
  </ul>
</div>
// After validation finds errors:
document.getElementById('error-summary').focus();

The tabindex="-1" lets the script move focus to the box without adding it to the Tab order. Use the same wording in the summary as next to the field, so people recognise it. If the page reloads with errors, also start the page title with "Error:" so it's the first thing a screen reader announces.

Timing: when to show errors

  • Validate when the form is submitted, not on every keystroke. Showing "invalid email" while someone is still typing their address is distracting, and a screen reader may announce it over and over.
  • Keep what people typed. Never clear the form after an error. Re-typing a long address because one field was wrong is how people leave. (Passwords and card security codes are the usual exception.)
  • Don't disable the submit button until the form is valid. People can't tell why it doesn't work, and a disabled button often has low contrast. Let them submit, then show the errors.
  • Remove errors as they're fixed. When a field becomes valid, drop the message and aria-invalid.

If you update errors without a page reload, screen readers need to hear about it. Moving focus to the summary does that. For smaller updates, such as "2 errors remaining", use a status message (WCAG 4.1.3): an element with role="status" that is already on the page before you put the text in.

Prevent the error before it happens

The best error message is the one nobody sees:

  • Put format hints in the label or a hint below it, before the field, not only in the error. "Date of birth, for example 21 3 1990."
  • Accept common variations: spaces in phone and card numbers, upper- or lowercase postcodes. Clean them up in your code instead of rejecting them.
  • Don't use placeholder text as the only instruction. It disappears as soon as someone types and is often too light to read.
  • Mark required fields in text ("required"), or mark the few optional ones as "(optional)". An asterisk alone needs explaining.
  • On checkout and booking forms, show a review step before the final payment so people can check and change their details.

Common platforms

  • WordPress: the error messages come from your form plugin (Contact Form 7, Gravity Forms, WPForms, Fluent Forms and others), not from WordPress itself. Check the plugin's settings for the message wording, and test the form with a keyboard and a screen reader before trusting it.
  • Shopify: the contact, login and account forms are part of the theme. Test each one by submitting it empty and with a bad email address. If messages aren't connected to their fields, the fix is in the theme's Liquid templates, or ask the theme developer.
  • Webflow, Wix and Squarespace: built-in forms have their own error behaviour, and you may not be able to change the markup. Test what they do; if the errors are hard to find, a dedicated form tool with better error handling may be the faster fix.

How to test your own forms

  1. Submit the form empty. Can you tell, without colour, which fields need fixing?
  2. Do it again with only the keyboard (our 2-minute keyboard test shows how). Where does focus go after submitting? Can you get to each error?
  3. Turn on a screen reader (VoiceOver on Mac with Cmd + F5, or the free NVDA on Windows), go to a field with an error and listen. Do you hear the label and the error?
  4. Fix one field. Does its error go away? Is everything else you typed still there?

Automated checkers can find some of this: missing labels, broken aria-describedby references, low-contrast error text. They can't judge whether "Invalid input" is a helpful message or whether focus goes somewhere sensible. Automated checks find only part of the WCAG issues, and forms need a manual test like the one above.

Need a second pair of eyes?

Run the free checker on your contact or checkout page to catch missing labels and contrast problems first. Then post a screenshot of your error messages in our free Website Accessibility Help group on Facebook, and people will help you reword them.

Automated testing detects only a portion of WCAG issues. Manual testing is required to assess full conformance. This article is general information, not legal advice.

All blog posts