Skip to content
← Blog

Best practice

Error messages that tell people what to do next

A good error message says what happened and what to do next, in plain words, next to the problem. How to write one, where to put it and when to show it.

· 6 min read · Musab Alfawal

An expiry date field with a red border holding the value 13/27, and the message “Enter a month from 01 to 12, like 08/27.” underneath.

An error message turns up at an awkward moment. Someone was trying to get something done, it didn’t work, and the next sentence they read decides whether they fix it in seconds or give up.

Most bad error messages fail in a few familiar ways. They describe the system instead of the problem, they appear far from the thing that needs fixing, they arrive too early, or they throw away work. Each of these is a decision about words, placement or timing, so each one is yours to fix.

When to show an error message

The same date of birth, typed into two forms. On the left, the field turns red before the person has finished typing.

A half-typed date isn’t wrong yet. Checking on every keystroke tells people they have failed at something they haven’t finished, and it pulls their attention away from the field they are working in.

A calmer default is to check each field when the person leaves it, and check the whole form again when they submit it. Once a field is showing an error, re-check it as they type, so the message goes away the moment the problem is fixed. You stay quiet while people work, and you confirm quickly when they have put something right.

Some checks can only happen on submit, such as whether a username is taken or a card has been declined. Those messages still belong next to the field or step they are about, not only in a banner at the top of the page.

The same upload, fixed

Here is an upload dialog after the connection drops, then the same dialog rewritten. Both use the same layout. The second says what happened, keeps the file and offers a way forward.

Before

An upload dialog showing “Error 0x80070057: Operation failed.”, an empty file area with “No file selected” and a single OK button, marked with three numbered problems.
  1. A code and a phrase that describe the system. Nobody can act on “0x80070057”.
  2. The file has gone, so the person has to find it again before they can retry.
  3. One button, and all it does is close the dialog.

After

The same dialog explaining that the upload stopped at 64% because the connection dropped, still showing lease-agreement.pdf, with Try again and Choose another file buttons and a small reference code, marked with four numbered fixes.
  1. What happened and why, in plain words, and a reassurance that the file is safe.
  2. The file the person chose is still selected.
  3. The likely next step is the main button, with a second route under it.
  4. The code is still there, as small print for anyone who contacts support.

How to write an error message

A useful error message answers three questions, in this order: what happened, why it happened if knowing that helps, and what to do now. “The upload stopped because your connection dropped. Try again.” covers all three in two short sentences.

Write in the words your users would use. “Session token expired” means something to a developer. “You were signed out after 30 minutes without activity. Sign in again to carry on.” means something to everyone. Leave out codes, exception names and status numbers. If your support team needs a reference, show it after the message in smaller text, where it helps the person who gets in touch and stays out of everyone else’s way.

Describe the problem, never the person. “You entered an invalid email” reads as an accusation. “Enter an email address like name@example.com” asks for the same thing and tells people how to give it. Leave out “Oops”, exclamation marks and jokes too. Someone who has just lost a form is not in the mood for them.

Be specific. “Invalid date” is true and no help. “Enter a date in the past” or “Enter the year in full, like 1992” is a fix someone can make without guessing. When you know what a correct answer looks like, say so.

Put the message where the problem is

An error belongs next to the thing that needs fixing: under the field, beside the file, inside the payment step that failed. People look where they were working, and a message at the top of a long page is easy to miss.

On a long form, a short summary at the top helps as well, as long as each item links to its field and the message is repeated on the field itself. The GOV.UK error summary is a well-tested version of this pattern.

Keep everything the person has entered. Clearing a form because one field failed turns a small correction into starting again. The same goes for uploads, baskets and drafts: keep the file, the items and the text, and let people fix the one thing that went wrong.

What WCAG asks for

Two success criteria cover most of this. SC 3.3.1 Error Identification (Level A) says that when an input error is detected automatically, the item in error is identified and the error is described to the user in text. SC 3.3.3 Error Suggestion (Level AA) adds that when suggestions for correcting the error are known, you provide them, unless that would put the security or purpose of the content at risk.

The words “in text” matter. A red border on its own fails 3.3.1, and it also fails SC 1.4.1 Use of Color, which says colour can’t be the only visual means of conveying information.

Mistakes, and what to do instead

  1. An “Upload document” dialog with a pink banner reading “Error 0x80070057: Operation failed.” above a single OK button.

    Don’t

    “Error 0x80070057: Operation failed.”

    The same dialog reading “The upload stopped because your connection dropped. Try again.”, with a Try again button and “Reference 0x80070057” in small grey text underneath.

    Do

    Say what happened and what to do: “The upload stopped because your connection dropped. Try again.” Keep the code as small print.

  2. A date of birth field holding “June 1992”, outlined in red, with only “Invalid input.” under it.

    Don’t

    “Invalid input.”

    The same field with the message “Enter your date of birth as day, month and year.” under it.

    Do

    Name the field and the fix: “Enter your date of birth as day, month and year.”

  3. An email field holding “amira.haddad@gmail”, outlined in red, with “You entered an invalid email.” under it.

    Don’t

    “You entered an invalid email.”

    The same field with “Enter an email address like name@example.com.” under it.

    Do

    Describe what is needed, not what the person did: “Enter an email address like name@example.com.”

  4. A contact form after a failed submit: the order number field is empty and outlined in red, and the message box below it is empty too.

    Don’t

    Clearing the form after a failed submit.

    The same form with “48213” still in the order number field, the only field marked in red, and the written message about a cracked teapot lid still in the box.

    Do

    Keep every value. Mark only the fields that need attention.

  5. A card number field and a Pay £48.00 button, with a fading grey toast at the bottom reading “Enter all 16 digits of your card number.” and its timer bar almost run out.

    Don’t

    A toast that disappears before anyone has read it.

    The same card number field outlined in red, with “Enter all 16 digits of your card number.” fixed underneath it, above the Pay button.

    Do

    A message that stays next to the problem until it is fixed.

  6. A date of birth field with “14/06/” half typed and the cursor still in it, already outlined in red with “Invalid date” underneath.

    Don’t

    Turning a field red while someone is still typing.

    The same half-typed date with a blue focus outline and no error, left alone until the person moves on.

    Do

    Check when they leave the field or submit, then re-check as they correct it.

Prevent the error instead

An error you prevent is better than the best message you could write for it. Accept the formats people actually type: dates with slashes or spaces, phone numbers with spaces, postcodes in lower case. Show rules, such as a minimum password length, before anyone types. Offer a short list when the set of possible answers is small and known.

For actions that are hard to undo, WCAG SC 3.3.4 Error Prevention (Legal, Financial, Data) asks that submissions which commit people to something legal or financial, or change or delete data they have stored, are reversible, checked for errors, or confirmed before they are final. A review step before payment is the familiar example.

Before you ship: a checklist

Questions people ask

Should an error message apologise?

Only when the fault is clearly yours, such as an outage or a payment that failed on your side. For a mistyped date, “sorry” adds words without helping. When you do apologise, keep it to one word and move straight on to the fix.

Should errors appear in a toast or a pop-up?

Not usually. Toasts disappear on a timer, often before people have read them, and they appear away from the thing that needs fixing. A pop-up blocks the very thing people need to look at. Keep the message next to the problem until it is resolved.

How do screen reader users find out about an error?

Connect each message to its field in code with aria-describedby, and mark the field with aria-invalid. After a failed submit, move focus to the error summary or to the first field with a problem. If a message appears without moving focus, such as an upload failing in the background, use a live region so it is announced. WCAG SC 4.1.3 Status Messages covers this.

Resources

If this was useful, share it with someone it would help.