Skip to main content

What are you looking for?

Try searching for…

Components

Alert

Alert provides users with information that is especially important for them to see and understand. The component is designed to capture users' attention. The text in the alert should be short and clear.

What you need to check

Alert that appears or updates after the page has loaded must be automatically announced by screen readers.

Use role="alert" for critical messages that require immediate attention. Use role="status" for less critical messages.

WCAG: 4.1.3 Status messages


Alert must be placed so that it follows the reading order.

This means the Alert must appear in the DOM in a way that provides a logical reading order for screen readers. If the Alert has a heading, the heading level must be correct in the page structure.

WCAG: 1.3.1 Info and relationships


Alert text must explain what happened and what it means for the user.

Example: “Your changes have been saved” or “An error occurred while saving. Please try again later”. Not just: “Error” or “Warning”.

See the system notifications pattern for guidance on writing.

Alert in a live region

If you want the alert to be read out dynamically, you must place the Alert inside a live region. The region must wrap around the Alert component, not be placed on the component itself.

Out of the box, Alert is presented to screen reader users as regular static content. For alerts that appear dynamically, you can define a live region for screen readers yourself, but be aware of the behaviour this introduces. You can read more about this in MDN's documentation on ARIA live regions.

Pay particular attention to the fact that the live region — that is, the element with the attribute role="alert", role="status", or aria-live with the value "assertive" or "polite" — must exist on the page before the alert that is to be read out.

For dynamic alerts, it is generally most relevant to use role="alert" for critical alerts or role="status" for less critical alerts, as described in the system notifications pattern. See also the alert role and the status role on MDN.

Do not combine role="alert" and aria-live, since this may cause the alert to be read out twice in VoiceOver (mozilla.org).

You should combine role="status" and aria-live="polite" to maximise compatibility (mozilla.org).

For status messages implemented using markup, the following applies:

The result of an action must be coded with one of the following:

  • role="status"
  • aria-live="polite"

A waiting state must be coded with one of the following:

  • role="status"
  • aria-live="polite"

Errors must be coded with one of the following:

  • role="alert"
  • aria-live="polite"
  • aria-live="assertive"

Progress in a process must be coded with one of the following:

  • role="progressbar"
  • the <progress> element
  • role="log"
  • role="status" and aria-atomic="false"
  • aria-live="polite" and aria-atomic="false"

Source: 4.1.3 Status messages (Level AA) (uutilsynet.no)

Edit this page on github.com (opens in a new tab)