<cs-toast>
StableFeedbackSince 0.1

Toasts display brief, non-blocking notifications that appear temporarily above the page content.

Show notification

Now Available in Cornerstone Core
Toast moved over from Pro in 3.11.0. On an earlier Core version? Upgrade to use it.

Adding a single <cs-toast> element to the page gives you the ability to dispatch notifications at any time. Toast notifications appear in a stack that renders in the top layer, showing above everything else on the page.

You can put the <cs-toast> element anywhere in the DOM, as long as it’s somewhere inside the <body>. In most apps, a single toast element is optimal.

Toasts carry unique accessibility challenges.
Read the accessibility considerations before using them — thoughtful implementation can mitigate the issues.

Overlapping toasts on this page are intentional, not a bug.
This page has many <cs-toast> elements to show off the component — most apps need only one.

Examples

Variant

Set the variant option to brand, success, warning, danger, or neutral to change the type of notification.

Neutral Brand Success Warning Danger

Size

Set the size option to xs, s, m, l, or xl to change the size of the toast item.

Extra Small Small Medium Large Extra Large

Icons

Pass an icon option to display an icon at the start of the toast item. You can pass a simple string for the icon name, or an object with additional options like library, family, and variant.

Show notification with icon

For more control over the icon, pass an object with name and optional library, family, or variant properties.

Filled icon Brand icon

Duration

Set the duration option to control how long notifications show before disappearing. The value is in milliseconds and defaults to 5000 (5 seconds). A value of 0 will keep the notification open until the user dismisses it.

3 seconds 10 seconds Until dismissed

Placement

Use the placement attribute to set the position of the toast stack on the screen.

top-start top-center top-end bottom-start bottom-center bottom-end
Show notification

Hover & Focus Behavior

Toast items automatically pause their countdown timer when you hover over them or when the close button receives focus. This gives users more time to read the content before it disappears. When the mouse leaves or focus moves away, the timer resets and starts counting down again.

Show notification (hover to pause)

Using HTML Content

Set allowHtml to true to render HTML content in notifications. Make sure you trust the content to avoid XSS vulnerabilities.

Show notification with HTML

Responding to Custom Buttons

You can add custom buttons or other interactive elements to a toast item using allowHtml. Use the returned toast item reference to query for your elements and attach event listeners.

Show notification with button

Responding to Events

The create() method returns a promise that resolves to the generated toast item. You can use this reference to add event listeners.

Show notification

Creating Toast Items Manually

While toast.create() is the easiest way to show notifications, you can also create <cs-toast-item> elements manually. This approach gives you full control over the toast item’s content and is useful when you need to add custom elements or complex layouts.

Create toast item manually

Accessibility Considerations

Toasts have a number of accessibility limitations. For example:

  • Due to their transient nature, toasts can be missed entirely by screen magnifier users and difficult to perceive for others depending on their visual and cognitive abilities.
  • Due to their DOM placement and vague position in a page’s reading order, toasts can be difficult for keyboard users to navigate to.
  • Due to their positioning on the page, toasts can obscure other essential elements, especially for users who use browser or OS zooming features.

Rarely will toasts offer the best usability for all of your users, so consider if other UX patterns, like dialogs or inline messages, offer a better experience. If toasts are the right fit for your use case, consider these tips:

  • Keep toasts short and sweet.
  • Set the duration to 5000 ms (5 seconds) or longer to give users enough time to locate and understand the toast item.
  • Consider allowing users to adjust the timing. While the duration of a toast item resets on hover (see Hover & Focus Behavior), a setting in your application can allow users to control the timing of toasts to best suit their needs and abilities.
  • Choose a consistent placement for toasts in your application and stick with it. Otherwise, users need to guess where transient notifications will appear and risk missing them entirely.
  • If a transient toast item contains an action, ensure that action is available elsewhere on the page. This ensures that users can still execute the action even if they miss the toast.

API

Importing

If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick this component, use one of the following snippets.

npm Self-Hosted React
import '@cruglobal/cornerstone-components/components/toast/toast.js';
import './cornerstone/components/toast/toast.js';
import CsToast from '@cruglobal/cornerstone-components/react/toast/index.js';

Slots

Learn more about using slots.

NameDescription
(default)Place <cs-toast-item> elements here to show them as notifications.

Attributes & Properties

Learn more about attributes and properties.

PropertyAttributeDescriptionTypeDefaultReflects
placementplacementThe placement of the toast stack on the screen.'top-start' | 'top-center' | 'top-end' | 'bottom-start' | 'bottom-center' | 'bottom-end''top-end'Yes

Methods

Learn more about methods.

NameDescriptionArguments
create()Creates a toast notification programmatically and adds it to the stack. Returns a reference to the created toast item element.message: string, options: ToastCreateOptions

CSS Custom Properties

Learn more about CSS custom properties.

NameDescriptionDefault
--gapThe gap between stacked toast items.var(--cs-space-s)
--widthThe width of the toast stack.28rem

Custom States

Learn more about custom states.

NameDescriptionCSS selector
visibleApplied when the toast stack has one or more visible toast items.:state(visible)

CSS Parts

Learn more about CSS parts.

NameDescriptionCSS selector
stackThe container that holds the toast items.::part(stack)

Dependencies

This component automatically imports the following elements. Sub-dependencies, if any exist, are included in this list.