Skip to content
Paste
UX Platform
Change the site theme
GitHub

Alert

An alert notifies a user to high-priority or time-sensitive information.

Status
production
Version
7.0.0
Sources
Abstract
Import from
@twilio-paste/core/alert — or — @twilio-paste/alert

Guidelines#

About Alerts#

Use an alert to notify a user about high-priority or time-sensitive changes in the system. Alerts communicate system-level information that isn't triggered by a user action.

Use an alert for one of these types of information:

  • Neutral or general information. Use this in most cases where you are notifying a user of a change.
  • Warning. Use this for critical information that will help a user avoid an issue.
  • Error. Use this for critical information that's preventing a user from continuing a flow and if there's action required on their end to resolve the issue.

Alerts vs. Feedback indicators and dialogs#

To communicate feedback on a user action, use a toast or in-page validation (e.g., full-page confirmation, inline error) instead.

To interrupt a user flow or provide the user with more than one action, use an alert dialog.

Accessibility#

  • On all alerts, pass in role="alert" or role="status" through props.
  • Screen readers will announce error and warning alert text immediately. Alerts that persist across multiple pages will announce themselves repeatedly which may become annoying. Consider making alerts in these cases dismissible.
  • Render an alert only when it's needed. Assistive technologies will be able to read a visually hidden element. Don't visually hide an alert and then make it visible through client-side code.

Our alerts have icons that both announce the type of alert it is to screen readers and visually indicate what type of alert it is. That way the background color isn't the only distinguishing feature between alert types.

Examples#

Here are ways that you can compose neutral, warning, error, and dismissible alerts.

information:
Martin Luther King, Jr.: We may have all come on different ships, but we’re in the same boat now.

Neutral#

Use a neutral alert to notify a user of a change that's relevant for them to achieve their current goal. Don't use an alert to communicate general promotional information.

In most cases, a neutral alert should be dismissible (i.e., have a close button) and should be assigned role="status"

A notification sent irrespective of the current user goal would likely be ignored, and may even annoy users because it will disrupt their current task and be irrelevant to their current needs.

information:
Set up your contact preferences. You can now set up your contact preferences on your dashboard. Go to contact preferences

Warning#

Use a warning alert to help a user avoid an issue. If the user can take an immediate action to avoid the issue, provide a way to do that.

Be cautious about using a warning alert because they can be stressful for a user to see. In most cases, a warning alert should be assigned role="alert".

Error#

Use an error alert to help a user understand a critical issue at the system level. Provide a way to resolve the issue in the alert.

Be cautious about using an error alert because they can be stressful for a user to see. In most cases, error alerts should be assigned role="error".

There's a good chance you need to use an error alert if both these conditions are met:

  • The system-level issue is preventing the user from continuing a flow.
  • The user must take an action to resolve the issue.

Dismissible#

Add a close button to the alert if it doesn't communicate a persistent status of the system or the account. If you make an alert dismissible, provide another way for the user to retrieve the alert information.

Don't add a close button to the alert if all these conditions are true:

  • The alert communicates a persistent status of the system or the account.
  • The information is relevant to the user's goals on the page(s) the alert is on.
  • The user wouldn't be able to access the information in the alert if it were closed.

Keep in mind that the longer an alert is present, the more it starts looking like part of the page and loses its interruptive intent. This might make users start to ignore important alert information.

information:
We've enabled new security options for your account. Learn more

Composition Notes#

Keep alert text brief by placing only the highest priority information in an alert. Too much text in an alert can overwhelm a user. A good rule of thumb is to keep alert text to a single line in a desktop-sized container, or limiting it to 90 characters.

Regardless of screen width, the optimal line length is still 45–90 characters. As you test your layout, make sure that text elements stay within this range.

Compose an alert with:

  • A title (optional). Bold this text at the beginning of the alert. This should be the most scannable text in the alert.
  • Body text. Use the default text style. Provide specificity on the issue and a resolution if applicable via an anchor. Be cautious about using a button in an alert since it may compete with other buttons on the screen and should be used only to trigger an action. If you must use a button, use a small button.

When to Use an Alert#

Place an alert where it makes the most contextual sense. Don't cover other UI elements with an alert.

In general, the persistence and behavior on scroll of an alert should match the element it's scoped to. For example, if an alert is scoped to a navigation bar that is sticky on scroll and persists across several pages, the alert should similarly be sticky and persist across several pages. However, don't persist the alert across too many pages in a user session since it may lose its interruptive intent.

Do

Use only 1 alert per page. Use 2 alerts only if absolutely necessary and if the alerts are placed in different containers.

Don't

Don't use more than 2 alerts per page.

Section Heading

Please fill in the details below...

Do

Place global alerts at the top of the page. Place all other alerts at the top of the container it relates to beneath the heading.

Billing information

Don't

Don't cover other UI elements with an alert.

information:
A call to action Learn more
Do

Use anchors to link to more information that may be helpful for users to resolve or clarify an alert message.

information:
A call to action
Don't

Avoid using buttons in alerts unless it triggers an action.

Do

Be cautious about using alerts since they can be stressful for users to see.

Don't

Don't use alerts to communicate every change in a product (e.g., marketing messages, trial status) so that important messaging isn't diluted.

Anatomy#

PropertyDefault tokenModifiable?
background-color
  • Error: color-background-error-lightest
  • Neutral: color-background-primary-lightest
  • Warning: color-background-warning-lightest
No
border-color
  • Error: color-border-error-light
  • Neutral: color-border-neutral
  • Warning: color-border-warning-light
No
border-radiusborder-radius-0No
border-widthBottom border: border-width-20No
icon color
  • Error: color-text-error
  • Neutral: color-text-neutral
  • Warning: color-text-warning
  • Close: color-text-icon
No
icon size
  • Alert icon: size-icon-20
  • Close icon: size-icon-20
No
spacing
  • Top padding: space-50
  • Bottom padding: space-50
  • left/right padding: space-60
  • Between icon and body: space-30
  • Between body and close button: space-60
No

Usage Guide#

API#

Installation#

yarn add @twilio-paste/alert - or - yarn add @twilio-paste/core

Usage#

import {Alert} from '@twilio-paste/alert';
const Component = () => (
<Alert variant="error">
<Text>There is an error in the system.</Text>
</Alert>
);

Props#

PropTypeDescriptionDefault
children?ReactNodenull
onDismiss?() => voidCreate dismissable alerts by providing an onDismiss callbacknull
role?stringProvide a specific ARIA role to the alert that overrides the calculated one set by the componentnull
variant?stringerror / neutral / warningnull

Black lives matter.