Skip to content
Browse docs and components

Toast

toast

Stacked notifications you fire from anywhere with toast.success(), toast.error() or toast.promise(). They fan behind the newest one, expand on hover, take an undo action and swipe away. Mount one Toaster at the root.

Responsive

Install

$npxshadcnadd@forme/toast

Adds the component, its registry dependencies, and the token stylesheet you import once.

Usage

import { Toaster, toast } from "@/components/forme/toast/toast";

// Once, near the root of the app:
<Toaster />

// Anywhere, even outside React:
toast.success("Invoice sent", { description: "acme@example.com" });

When to use

Reach for it

  • Confirming something that just happened, and offering Undo for it.
  • Background results: a save that finished, an upload that failed with a Retry action.

Use something else

  • Errors a person has to fix in a form — put those beside the field.
  • Anything that must not be missed; toasts leave on their own after timeout, 5 seconds by default.

API reference

Read from the source, so it is the API of the file you install. A prop marked * is required.

Toaster

Render once, near the root of the app. Toasts appear bottom-right.

PropTypeDefaultDescription
limitnumber3How many stay visible. Older ones are pushed out.
timeoutnumber5000Default lifetime in ms. 0 keeps toasts until dismissed.
classNamestring—

Accessibility

  • Toasts are announced as they arrive, and the dismiss button is labelled.
  • Hovering or focusing the stack expands it and holds every toast open, so each can be read and reached.

Motion

  • Stacked toasts fan behind the newest one and spread out when the stack is hovered.
  • Swipe down or right to dismiss.

Responsive behaviour

  • Bottom-right and 22rem wide from sm; below that the stack spans the screen with a 1rem margin.