Toast Notifications

Toast patterns for non-blocking notifications with variants, positions, and JavaScript API.

Overview

The toast component uses the <toast-msg> web component to display non-blocking notifications. Toasts require JavaScript to show dynamically but provide a clean API for common use cases like form feedback and status updates.

Key features:

  • Four semantic variants: info, success, warning, error
  • Six position options (corners and center edges)
  • Auto-dismiss with configurable duration
  • Manual dismiss option
  • Multiple toasts stack automatically

Live Example

Click the buttons to see different toast variants in action.

Setup

Place a single toast container in your page, typically at the body level.

JavaScript API

Use the show() method to display toasts programmatically.

Common Use Cases

Form Submission Feedback

Copy to Clipboard

Network Status

Configuration

The <toast-msg> element accepts these attributes:

Attribute Values Description
position top-start top-center top-end
bottom-start bottom-center bottom-end
Screen position for toasts. Default is top-end.

Show Options

The show() method accepts an options object:

Property Type Description
message String The notification text to display.
variant info success warning error Visual style and semantic meaning.
duration Number Auto-dismiss time in ms. Default 5000. Use 0 for manual dismiss.

Usage Notes

  • Single container: Only place one toast-msg container per page
  • Position: Use top-end for most applications (top-right in LTR)
  • Duration: Use shorter durations (2-3s) for success messages, longer or manual for errors
  • Stacking: Multiple toasts automatically stack vertically
  • Accessibility: Toasts use ARIA live regions for screen reader announcements

Related

Toast WC

Web component documentation

Modal Dialog

Blocking dialog patterns