Skip to content

React Toast Notifications

A React toast is a glass notification that stacks, fans out on hover and can be swiped away, announced automatically to screen readers.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/toast.json

Release 4.2

  • Build4.2s
  • Deploy3 regions
  • Health checkeu-west
  • Toaster
  • ToastProvider
  • useToast
  • defaultToasterLabels
  • +2 more

Files to copy

6 folders · 5 files · 4 packages
From theme/src/
  • components/toast/
  • components/spinner/
  • hooks/{use-direction.ts, use-media-query.ts}
  • motion/tokens.ts
  • lib/{cn.ts, state-light.tsx}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/toast.jsonRegistry item: toast. The styles need the Tailwind v4 glass UI setup.
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Position

Pick an edge and a side, then stack a few. The newest toast sits at the edge and older ones peek out behind it; hover the stack (or press F6) to fan it out. Swipe a toast up or right to dismiss it.

Types

Success, error and info each get their own icon color. Fire a few in a row to see them stack.

Promise, action, persistent and update

toast.promise shows one toast that turns into success or error. An action adds a button such as Undo. persistent keeps a toast until it is dismissed, and update edits one by id.

Props

PropTypeDefaultDescription
viewportReadybooleantrueSet to false while the Toaster is lazy-loaded: toasts raised meanwhile are held (their timer has not started) and shown, in order, once this turns true, which is when the Toaster has mounted.
onViewportNeeded(() => void)undefinedCalled when a toast is held because the viewport is not ready, so the app can start loading the Toaster.
positionToastPositionProp"top-right"Where the stack sits. Top positions slide in from above and stack downwards; bottom positions slide up and stack upwards. On phones every position spans the screen width (minus 16px gutters), so only top / bottom matters there. "top-left" and the other left / right names are physical; "top-start", "top-end", "bottom-start" and "bottom-end" follow the text direction (start is the left corner in ltr, the right corner in rtl).
classNamestringNoneExtra classes for the viewport (the fixed element that holds the stack).
containerHTMLElement | nullthe page (document.body, fixed to the screen)Render the stack inside this element instead of the page: the viewport turns absolute and sits in the corner of the container (give it position: relative), so a demo or a panel can host its own toasts next to what triggers them.
onlyPositionedbooleanfalseShow only toasts that were given this position option (a second Toaster for per-toast positions).
labelsPartial<ToasterLabels>defaultToasterLabelsVisible-to-assistive-tech text of the toasts. Translate it here; dismiss is the accessible name of each toast's × button. Every other string, for translation: labels={{ dismiss: "…" }}; omitted keys keep the English of defaultToasterLabels. All 4 keys of ToasterLabels are listed in the key table under the props table.
ToastProvider timeoutnumber (ms)5000How long a toast stays up. 0 keeps it until dismissed.
ToastProvider limitnumber3How many toasts show at once; older ones are hidden, not dropped.
<Toaster />componentNoneRenders the stack. Place it once, inside the provider.
useToast(){ info, success, warning, error, loading, promise, update, dismiss }Noneinfo / success / warning / error / loading take (title, description?, options?) and return the toast id.
optionsToastOptionsNoneid, duration (ms; 0 or persistent keeps it; a toast with an action stays until dismissed), action ({ label, onClick }), position (per toast, shown by a Toaster with onlyPositioned), priority, onClose.
promise(promise, { loading, success, error }, options?) => PromiseNoneOne toast that shows loading, then success or error; success and error may be functions of the result.
update(id: string, changes: ToastUpdate) => voidNoneChange a showing toast: type, title, description, duration, action.
dismiss(id?: string) => voidNoneClose one toast by id, or all of them when called without one.
ToasterLabels keys and English defaults (4)
Pass any key in labels; the rest keep the defaults of defaultToasterLabels.
KeyEnglish default
dismissDismiss
loadingLoading
regionToast notifications
actionHint(action) => `Press F6, then Tab to reach ${action}.`

Keyboard

KeysAction
F6Move focus to the toast region (announced once with every toast that has an action). Tab then reaches each Action and Dismiss button.
TabReach each toast's Dismiss button while the stack is open.
Enter/SpaceDismiss the focused toast.
EscapeDismiss the focused toast.

Accessibility

  • Toasts are announced through a polite live region (errors too) and never steal focus. A toast with an action adds a hidden line to that announcement: "Press F6, then Tab to reach Undo."
  • A toast with an action stays until it is dismissed (WCAG 2.2.1); an explicit duration on it is raised to at least 20 s. Timers also pause while a toast is hovered or focused. Still offer the same action somewhere in the page (an Undo in the list, say).
  • The stack expands, and each toast pauses its timer, while it is hovered or holds focus, so there is time to read.
  • Every action in a toast needs a visible label; swipe towards the nearest edge dismisses it on touch.

All exports on this page

  • ToastProvider — Glass toasts that stack, expand on hover and can be swiped away.
  • Toaster — The fixed viewport that renders the toast stack.
  • defaultToasterLabels — English defaults of ToasterLabels.
  • useToast — const toast = useToast() returns the functions that show toasts.

When to use Toast

  • Use Toast as an animated toast in React for short, non-blocking feedback such as Saved, Copied to clipboard or Invite sent, where the person can keep working and the message needs no answer. If you are comparing a sonner alternative, SheenUI's Toast is called through the useToast hook and styled with the same glass tokens as the rest of the kit.
  • Use toast.error for a failed background request, such as a sync that did not finish, with a description line explaining what to try next.
  • Use position on Toaster for bottom-center on a mobile-first app or top-right on a desktop dashboard, remembering that on phones every position spans the screen width.
  • Skip it when the message must stay visible next to a form or needs a decision. Use Alert for persistent inline messages and Dialog or AlertDialog when the person must answer.
  • Pair it with Button actions that call useToast, Switch and Checkbox settings that save instantly, and DataTable bulk actions that finish in the background.

Choosing between SheenUI Toast and Sonner

Sonner is a popular React toast library built around one global toast() call. SheenUI's toast is built on Base UI's Toast: you wrap the app in ToastProvider, render one Toaster and call useToast() for toast.success, toast.info, toast.error and toast.dismiss. Toasts stack, expand on hover or focus, can be swiped away, pause their timer while hovered or focused and fade under reduced motion. Choose Sonner if you want a global function and nothing to provide; choose this one if you want glass styling, Base UI's accessibility model and the source in your own repository.

Frequently asked questions

67 components pages in all: browse them on All components.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .