Skip to content
IndexRequest a UIAboutContact

Toast

Short, non-blocking messages that stack, auto-dismiss and pause on hover.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Build a toast system. A fixed container at bottom-right (bottom-centre under 480px) with aria-live="polite" holds toasts. A function toast(message, type) appends a card with an icon (check for success, ! for error, i for neutral), the message, and a close button with aria-label "Dismiss". Each toast animates in with translateY(16px) and fade over 220ms, shows a 2px progress line that shrinks over 4000ms, auto-dismisses at the end, and pauses (timer and progress) while hovered or focused. Closing animates opacity and collapses the height in 200ms before removing the node. Limit to three visible toasts; remove the oldest when exceeded. Provide three buttons in the demo to trigger each type. Use role="status" for neutral and success, role="alert" for errors. Under prefers-reduced-motion use opacity only.

About this pattern

Definition

A small message that appears briefly at the edge of the screen to report the result of an action, then disappears by itself. Several toasts stack without covering each other.

Purpose & UX principles

  • Confirms outcomes that do not need a decision ("Link copied").
  • It must never be the only place an important error is shown, because it disappears. Use inline messages for problems that need fixing.
  • Announce it to screen readers with a polite live region so it is heard without stealing focus.

Interaction states

  • Entering, visible, paused (on hover or focus), leaving.
  • Variants: success, error and neutral, each with an icon so colour is not the only cue.
  • Close button always available; auto-dismiss after 4 seconds, with a progress line showing time left.

Motion specification

  • Enter: translateY(16px) and opacity 0 to 1, 220ms ease-out.
  • Exit: opacity to 0 and height collapse, 200ms.
  • Progress line: linear over 4000ms; paused with the timer on hover.
  • Reduced motion: opacity only.

Responsive behaviour

  • Desktop: bottom-right stack, 320px wide.
  • Phones: full-width minus 16px margins at the top or bottom, away from the on-screen keyboard.

Code

HTML
<div class="demo"><button class="b ok">Success</button><button class="b er">Error</button><button class="b nu">Info</button></div>
<div class="toasts" id="toasts" aria-live="polite"></div>

Related patterns

Snackbar

↗
SnackbarFeedback & Notifications

Tooltip

↗
TooltipFeedback & Notifications

Validation States

↗
Validation StatesInputs & Forms