Skip to content
English

How it works

A self-contained toast system: ToastProvider renders the region and useToast() returns toast(). Each toast is a floating surface card (18px corners, hairline ring and soft shadow, no border) with its status icon in a tinted rounded square, an optional soft pill action and a quiet round close button. Each toast is absolutely positioned and its transform is computed in JS from measured heights. Collapsed layers shrink 5%, step back 10px and fade 18%. When a layer behind is taller than the front one, clip-path trims the overflow instead of changing height. Timers pause on hover, focus, drag and in background tabs.

Use it for

  • Light feedback for an action: order placed, saved, copied.
  • Messages that must not interrupt the current task, such as a new message or a status change.
  • Results with a quick action, such as “Deleted · Undo” or “Order placed · View”.

Look elsewhere when

  • Information the user must confirm or choose from: use a dialog.
  • Validation errors tied to an input: show them next to the field.
  • Long content people need to revisit: toasts vanish in seconds, use a message center.
  • A page that already uses another notification system: do not mix two.

Usage

import { ToastProvider, useToast } from './ToastProvider.jsx'

export function App() {
  return (
    <ToastProvider position="bottom-right" duration={4000}>
      <OrderButton />
    </ToastProvider>
  )
}

function OrderButton() {
  const toast = useToast()
  return (
    <button
      onClick={() =>
        toast.success('Order placed', {
          description: 'Trail running shoes · Size 42',
          action: { label: 'View', onClick: () => navigate('/orders') },
        })
      }
    >
      Order
    </button>
  )
}

// Inside one panel: give the parent position: relative, then use <ToastProvider contained>

Props

PropTypeDefaultWhat it does
ToastProvider.position'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right''bottom-right'Where toasts appear. On the left edge they are swiped left to dismiss, otherwise right.
ToastProvider.durationnumber4000Default time on screen, in ms.
ToastProvider.visibleToastsnumber3Maximum layers in the stack; older ones are hidden, also when expanded.
ToastProvider.containedbooleanfalsePositions toasts inside the nearest positioned ancestor (it needs position: relative). Otherwise they are fixed and portaled to body.
ToastProvider.offsetnumber16Distance from the container edge, in px.
ToastProvider.gapnumber12Space between toasts when expanded, in px.
ToastProvider.labelstring'Notifications'Accessible name of the notification region.
ToastProvider.labelsobject—Replaces built-in text (close). Shallow-merged over the English defaults.
useToast()() => ToastFn—Returns toast(message, options) with success, error, info and dismiss. Must be used inside ToastProvider.
toast(message, options)(message: ReactNode, options?: ToastOptions) => string—Shows a toast and returns its id. toast.success, error and info take the same arguments with a fixed type.
toast.dismiss(id?)(id?: string) => void—Closes one toast, or all of them when no id is given.
options.descriptionReactNode—Second line of text.
options.type'default' | 'success' | 'error' | 'info''default'Sets the icon. Errors are announced assertively.
options.durationnumber—Time on screen for this toast, in ms. Infinity never dismisses automatically.
options.action{ label: ReactNode; onClick: () => void }—Action button on the right; the toast closes after a click.
options.idstring—Custom id. Calling again with the same id updates the toast in place and restarts its timer.

Accessibility

  • The region is a labelled landmark, with two always-present live regions: polite for normal toasts, assertive for errors.
  • Each toast is focusable; focus expands the stack and pauses timers. Esc or Delete closes the toast and moves focus to a neighbour.
  • The close button has an accessible name and focus ring, is always visible and has a 44px hit area.
  • Toasts hidden behind the front one or exiting are inert and skipped by Tab.
  • With reduced motion, toasts fade without sliding or moving.

Motion

Enter and re-stacking 360ms ease-out (a new toast rises from the edge while growing from 94%); exit 200ms ease-in (40% toward the edge while fading); swipe snap-back 240ms ease-out. The action pill presses to 0.96.

Add it to your project

Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the component next to your own.

ToastProvider.jsxtoast-stack.csstokens.cssREADME.md

Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.

Feedback
Confetti burst comes with Pro. Its preview shows once you unlock it.