Skip to content
Back to log

Error message design

Chainabit's Chao · · 8 min read

In short

An error message explains the problem and, where possible, how to fix it. Text, placement, timing, and accessibility using NN/g, GOV.UK Design System, and WCAG criteria.

The role of an error message

NN/g defines an error message as the system interrupting the user's workflow to report a condition that is incomplete, incompatible, or undesirable according to how the system operates. NN/g also calls for the message to explain the problem clearly and offer the user possible ways to correct it.

The GOV.UK Design System says that a validation error message should explain what went wrong and how to fix it. A message next to a form field and an Error summary at the top of the page address the same error in two locations. The message next to the field appears with the relevant question; the Error summary brings together the errors on that page.

Describe the problem in text

According to W3C's WCAG Error Identification success criterion, when an input error is detected automatically, the item in error must be identified and the error described to the user in text. Redisplaying a form without any explanation after a failed submission is not enough. The user must be told the nature of the error and which item it concerns.

W3C defines an input error as information provided by the user that is not accepted. This includes information the page requires but the user has not entered. Information entered in a format or outside the values allowed is also an input error. For example, entering letters in a telephone field that accepts only numbers is one of the examples W3C gives.

If a value is outside the allowed range and the page automatically changes it to a value within that range, the need to explain the error remains. According to W3C, an explanation informing the user of the changed value can satisfy both the Error Identification and Error Suggestion criteria.

NN/g recommends using short, clear text that explains exactly what the problem is instead of a generic error statement. Too much technical detail, however, can make the message harder to understand. The user's understanding of how the system works may not match the way the system is coded.

Specify how to correct it

The WCAG Error Suggestion criterion requires that correction suggestions be provided to the user when they are known for an automatically detected input error. There is a limit to this requirement: it does not apply if providing the suggestions would jeopardize the security or purpose of the content.

In W3C's example, a field asks for the name of a month and the user enters a number. A correction suggestion could be a list of accepted month names. The system could also interpret the number entered as a different month format and ask which month was intended. In both cases, the suggestion relates to the values the field accepts.

W3C treats a field requiring a specific format and a field requiring a limited set of values as separate cases. Error descriptions and suggested correction text are among the techniques that can be used in these cases. A field can also be both required and require information in a specific format.

NN/g also recommends offering possible solutions instead of only stating the problem. In its example, a message about an out-of-stock product could include information about when the product will be available again or an option to receive a stock notification. NN/g also describes linking from a short message to more detailed information when further explanation is needed.

Place the message near the relevant field

NN/g recommends showing the error indicator close to the interface element where the error occurred. The proximity of the message to the relevant element helps the user associate the explanation with the element that needs attention. In the GOV.UK Design System, a validation error is shown both next to the field and in the Error summary.

In the GOV.UK Design System layout, the error message appears in red after the question and any hint text. A red border visually connects the message and the question it concerns. If the error relates to a specific field within the question, that field also receives a red border and the message refers to it.

The GOV.UK Design System says that the message next to the field and the message in the Error summary should be the same. It also recommends that the error message directly include the wording from the question or fieldset label. In one of its examples, the same field name is used in both the label asking for an address line and the error message.

WCAG Error Identification does not require a single location for displaying an error. W3C gives examples of listing errors at the beginning of a form, showing them next to the relevant fields, or presenting them in an alert or dialog. The criterion requires the error to be presented to the user in text or as a text alternative.

Turn this insight into action.

Use the mobile app to continue with guided workflows.

Use visual indicators alongside text

NN/g describes prominent visual indicators for error messages and items that need correction. Bold text, high contrast, and red are among the indicators used. The same guidance says that color or animation alone should not be relied on to indicate an error.

According to W3C, color, an image, or another visual indicator can be added as long as the error is explained in text. Text helps people who are blind or have low vision and people who have difficulty seeing colors perceive that an error has occurred. In one of W3C's examples, two empty fields are highlighted in yellow in addition to the error explanation.

The GOV.UK Design System's Error message component places a visually hidden “Error:” prefix before the message for screen reader users. This prefix can be changed if the message is written in another language. The component's announced text includes this prefix along with the error explanation.

Language and timing

NN/g says error text should use readable, plain language that users are familiar with. Error codes or abbreviations that are difficult to understand can be hidden or used less often; displaying them for technical diagnosis is a separate case. The tone of the message also matters: NN/g recommends avoiding language that blames the user and humor that can become stale in frequently encountered errors.

The GOV.UK Design System says to use different messages for different errors. A text field may have been left empty, filled in with too much text, or filled in with too little text. The field may also contain disallowed characters or information in the wrong format. GOV.UK uses messages that describe the specific situation instead of a generic “an error occurred” statement.

When the message is shown is also part of the design. NN/g says not to treat an empty text field as an error just because the user moved focus away from it. On the other hand, it recommends providing immediate error information next to the field for error-prone interactions where entering the correct information on the first attempt is unlikely. Showing password requirements during entry is one of the examples NN/g gives in this context.

NN/g also distinguishes message formats according to the impact of the problem. Information about an unexpected condition that does not prevent the user from continuing and an error that stops progress are not presented with the same weight. The guidance gives conditional labels, toast notifications, and banners as examples for situations requiring little interaction; it limits the use of modal dialogs to serious errors.

Preserve entered information

The GOV.UK Design System says that no form fields should be cleared when an Error message is displayed. Both accepted and incorrect answers are preserved. Keeping the incorrect information helps the user see what went wrong and edit the previous answer instead of retyping it.

NN/g also recommends allowing the user to correct an error by editing their original action. Information entered in a text field can remain visible and editable by the user even if it does not meet the field's requirements. In another NN/g example, when a city and postal code do not match, a button is offered to select the city corresponding to the entered postal code.

Limits of the component and browser validation

The GOV.UK Design System does not use the Error message component to tell a user that they are ineligible, do not have permission to perform an action, or face a service problem they cannot fix. In these cases, it describes directing the user to a page that explains the problem and provides useful information about the next step. There are separate page layouts for a service problem, a page that cannot be found, and an unavailable service.

W3C states that when built-in HTML client-side validation is used, the user agent prevents submission of incomplete or invalid forms and displays generic error messages. Focus usually returns to the first field in error. In common user agent and screen reader combinations, the error message and the programmatic name of the focused field are announced.

This approach also has limitations. According to W3C, the message may not persist or may not scroll with the page, depending on the user agent. The message text may not enlarge even when the page is zoomed. If there is more than one error, only the first may be shown; the next error may appear when the first is corrected and the form is submitted again. Generic messages may also lack correction suggestions specific enough for Error Suggestion.

Ready to start?

Download the app and continue from your phone.

End of Entry