Sub topic 10
9. Help Users Recognize, Diagnose, and Recover from Errors
What this heuristic means
This heuristic says that an interface should help users understand what went wrong, why it went wrong, and what they can do next. Error handling is part of the main user experience, not an afterthought.
This chapter assumes that you understand basic user-interface concepts. Basic HTML is useful for the examples, but you do not need to know JavaScript.
A useful error message answers three questions:
- What happened?
- What caused it?
- How can the user fix it?
For example, “Invalid input” gives almost no useful information. “Enter an email address that includes an @ sign, such as [email protected]” identifies the problem and suggests a correction.
Make errors visible at the right time
An error should appear near the control or action that caused it. If a form has five fields, a message at the top saying “Something went wrong” forces the user to search for the problem.
Use several signals when appropriate:
- Place the message beside the affected field.
- Keep the user's entered value when it is safe to do so.
- Mark the invalid field clearly.
- Move focus to the first invalid field after form submission.
- Provide a summary for long or complex forms.
- Do not rely on color alone.
The following example connects the error message to the input for assistive technology:
<form>
<label for="email">Email address</label>
<input
id="email"
name="email"
type="email"
value="ana.example.com"
aria-invalid="true"
aria-describedby="email-error"
>
<p id="email-error">
Enter an email address that includes an @ sign, such as [email protected].
</p>
<button type="submit">Continue</button>
</form>The aria-invalid attribute communicates that the value is invalid. The aria-describedby attribute points to the element containing the explanation. The browser can then associate the message with the field.
Give users a path to recovery
A recovery action should be specific and achievable. “Try again” may be appropriate for a temporary network failure, but it is not enough for a malformed date or a missing required field.
| Error situation | Useful recovery |
|---|---|
| Missing required name | Identify the field and ask for the name |
| Invalid email format | Show the required format and preserve the value |
| Network timeout | Explain that the request failed and offer retry |
| Permission denied | Explain the required permission or provide another route |
Do not erase all form data after one validation error. Data loss increases frustration and may create a second problem. For destructive actions, provide an undo option or a confirmation step when the action is difficult to reverse.
A practical error-handling flow
Common violations
Watch for these patterns during an evaluation:
- A form shows one generic error at the top.
- A server error exposes technical details such as a stack trace.
- An error disappears before the user can read it.
- A failed upload gives no progress or retry state.
- Validation runs only after submission when earlier feedback would prevent the error.
- The interface uses a red border without text or another accessible signal.
- A correction causes the user to re-enter information that was already valid.
Client-side validation can provide quick feedback, but the server must validate submitted data too. Client-side checks improve interaction; they do not provide security.
Exercise
A checkout form says “Payment failed” after submission and clears every field. Name two violations of this heuristic and one concrete fix for each.
Show answer
The message does not explain the cause or recovery step, so show a specific message such as “The card was declined. Check the number or use another card.” Clearing every field causes data loss, so preserve non-sensitive entries and retain the user's place in the form.