Sub topic 6
5. Error prevention
This chapter assumes you know the first four heuristics and have read basic HTML. The JavaScript example uses plain DOM calls.
What the heuristic says
Nielsen's fifth heuristic is: good error messages matter, but the best designs prevent problems from happening at all. A design can do this in two ways:
- It removes the conditions that cause errors.
- It checks for those conditions and asks the user to confirm before they commit to an action.
Heuristic 9 covers what happens after an error occurs. Heuristic 5 covers the moment before. When you evaluate an interface, you can usually tell them apart by one question: could the design have stopped this error from happening? If so, it is an error prevention problem. If the error was unavoidable and the problem is how it was explained, it belongs under heuristic 9.
Slips and mistakes
Prevention works better when you know which kind of error you are preventing. Human-error research, from James Reason and Donald Norman, separates two kinds.
| Kind | What happens | Example | Typical prevention |
|---|---|---|---|
| Slip | The user has the right goal but the action goes wrong | Clicking "Delete" instead of the "Edit" button next to it | Spacing, constraints, undo, confirmation |
| Mistake | The user has a wrong goal or a wrong understanding of the system | Believing "Archive" also notifies the customer | Clear labels, previews, plain-language descriptions |
Slips come from attention lapses, small targets, and habit. Mistakes come from a mismatch between the user's mental model and the system, so they connect to heuristic 2 (match with the real world) and heuristic 6 (recognition rather than recall). A confirmation dialog helps with slips. It does little for mistakes, because a user with the wrong mental model will confirm the wrong action.
Prevention techniques
Techniques range from strongest to weakest. The strongest make the error impossible. The weakest only warn.
- Make the error impossible. Use a date picker instead of a free-text date field. Disable options that do not apply. Use a slider with fixed limits for a quantity that has a maximum.
- Constrain the input. Use the right input type, a maximum length, or a numeric keypad on mobile. The browser then blocks malformed values.
- Provide good defaults. Pre-select the safest or most common choice. Users often accept defaults without checking, so a bad default causes errors at scale.
- Accept varied formats. A phone field that rejects "555 0100" because of the space has made an error where none needed to exist. Strip spaces and dashes in code instead of asking users to retype.
- Show a preview. Show what will happen before it happens, such as "12 files will be moved to Archive."
- Separate dangerous actions. Keep "Delete account" away from "Save". Give it a different style and place.
- Confirm. Ask before irreversible actions. Use this last, for the reasons below.
Example 1: constrain input with the right type
The email field below uses the email input type, the required attribute, and autocomplete. The browser blocks a missing or malformed address before the form is submitted, and it can fill in a known address so the user does not type it at all.
<label for="email">Email address</label>
<input id="email" name="email" type="email" required autocomplete="email">Autofill reduces typing errors, and the email type catches most remaining ones. The same idea applies to other fields. A date input with min blocks dates in the past:
<label for="checkin">Check-in date</label>
<input id="checkin" name="checkin" type="date" min="2026-11-28" required>In a real page, the server would generate the min value for the current date.
Example 2: a high-friction confirmation for rare, destructive actions
Some actions cannot be undone, such as deleting a project with all its data. A simple "Are you sure?" dialog is weak here, because people click through it by reflex. A stronger pattern asks the user to type the project name. This works because it forces attention. A user cannot confirm it by habit.
<form id="delete-form">
<p>To delete the project "Apollo", type its name below. This cannot be undone.</p>
<label for="confirm">Project name</label>
<input id="confirm" autocomplete="off">
<button id="delete" type="submit" disabled>Delete project</button>
</form>
<script>
const expected = "Apollo";
const input = document.getElementById("confirm");
const button = document.getElementById("delete");
input.addEventListener("input", () => {
button.disabled = input.value !== expected;
});
document.getElementById("delete-form").addEventListener("submit", (event) => {
event.preventDefault();
if (input.value === expected) {
console.log("Project deleted");
}
});
</script>Two details matter:
- The submit handler checks the value again. A disabled button is a convenience, not a guarantee, so the real action must verify the condition too.
- The page text states the consequence ("This cannot be undone"). Prevention fails if the user does not understand what they are confirming.
Prevention versus undo
Heuristic 3 (user control and freedom) offers an alternative: let the action happen and make it reversible. The fifth chapter's concerns overlap with it, so choose between them deliberately.
| Situation | Better choice | Reason |
|---|---|---|
| Action is cheap to reverse (delete an email, remove a list item) | Undo | No interruption for the many users who meant it |
| Action is costly or impossible to reverse (send payment, delete a database) | Prevention and confirmation | Undo cannot be built or is unsafe |
| Action is rare and high stakes | Typed or explicit confirmation | Friction is acceptable when use is infrequent |
| Action is frequent | Avoid confirmation | Repeated prompts train users to ignore them |
A frequent confirmation dialog is a common design failure. Users learn to press "OK" without reading, so the dialog stops protecting them and only slows them down. This also conflicts with heuristic 7 (flexibility and efficiency of use). Save confirmations for actions where the cost of an error justifies the interruption.
Common errors when applying this heuristic
- Using confirmation as the default fix. A dialog on every delete is the weakest form of prevention. Look first for a way to remove the error or make the action undoable.
- Blocking valid input. A strict pattern that rejects names with apostrophes or hyphens, or addresses with a plus sign, prevents legitimate use. Validate for what you need, no more. Over-strict validation is itself a usability problem.
- Disabling controls without explanation. A greyed-out button with no visible reason leaves users guessing, which violates heuristic 1. Show why it is disabled, for example "Enter the project name to enable".
- Validating only on submit. Users then find every problem at once, after they have finished. Check as they go where it helps, but avoid showing an error before the user has finished typing.
- Ignoring state conflicts. Examples are two people editing the same record, or a form left open past a session timeout. Warn about the conflict early. Do not let users lose work at the end.
Using the heuristic in an evaluation
When you review an interface for error prevention, walk through each task and ask four questions at every step:
- Where could a user plausibly make a slip? Look for small adjacent targets, similar-looking buttons, and long forms.
- Where could a user form a wrong mental model? Look for ambiguous labels and outcomes that surprise people.
- Which actions are irreversible, and what stands between the user and them?
- Does the interface accept reasonable variations in how people type things?
Record each problem with the screen, the step, and the specific design change. For example: "The phone field rejects numbers containing spaces. Strip spaces and dashes before validating." This format helps when you rate severity later in the tutorial.
Exercise
A settings page shows "Delete account" as a red button directly beside "Save changes". Clicking "Delete account" immediately deletes the account with no further step. Which heuristic does this violate, which kind of error is likely, and what two changes would you propose?
Show answer
It violates error prevention (heuristic 5). The likely error is a slip: a user who means to click "Save changes" hits the adjacent destructive button. Proposed changes: first, separate the two controls, for example by moving "Delete account" to its own section lower on the page with extra spacing. Second, add a confirmation that matches the stakes, such as asking the user to type their username before the deletion proceeds. If your system can support it, add a grace period in which deletion can be cancelled. That moves part of the fix into heuristic 3.
Exercise
A team adds an "Are you sure?" dialog to every action in an email app, including archiving and marking messages as read. Users now click "OK" without reading. Explain the problem and suggest a better approach for these actions.
Show answer
Frequent confirmations teach users to dismiss them by reflex, so they stop protecting anything and they slow down common tasks. Archiving and marking as read are cheap to reverse. A better approach is to remove the dialogs and offer an undo option, such as a short "Message archived. Undo" notice. Keep confirmation for rare, irreversible actions.