Skip to content

    Toast

    A short message about something the user just did, in a corner or at the top or bottom center of the screen: Changes saved, Link copied, Upload failed. It closes on its own after a few seconds, or when swiped away. Several at once overlap in a stack, the newest in front, and spread out on hover or focus. Mount one Toaster at the root of the app and call toast({ title }) from an event handler; a Toast element shown with state works too.

    React

    Preview

    Props

    • variant
    • position
    • duration
    • title
    • description
    import { Button } from "@/components/ui/button"
    import { toast } from "@/components/ui/toast"
    
    <Button variant="secondary" onClick={() => toast({ title: "Changes saved", description: "Your project is up to date." })}>Show toast</Button>

    Usage

    When to use

    • Confirm an action the user just took, without stopping them: Changes saved, Link copied.
    • Offer a quick undo right after an action, when the same undo also exists elsewhere.

    When not to use

    • An error that blocks work. Show it in the page, next to what failed, for example with Field.
    • A question or a decision. Use AlertDialog.
    • A state that lasts, such as a failed build. Use Badge.

    Platform support

    What each platform has, from the spec. A selected platform is highlighted.

    NameWebiOSAndroidNote
    variantYesYesYes
    positionYesNoNoOnly on web. Not generated for iOS and Android.
    titleYesYesYes
    descriptionYesYesYes
    durationYesNoNoOnly on web. Not generated for iOS and Android.
    actionYesYesYes
    dismissibleYesYesYes
    openYesNoNoOnly on web. Not generated for iOS and Android.
    onOpenChangeYesNoNoOnly on web. Not generated for iOS and Android.
    iconNoYesYesOnly on iOS, Android.
    dismissLabelNoYesYesOnly on iOS, Android.
    onDismissNoYesYesOnly on iOS, Android.
    value of keyboard: F8YesDeferredDeferred

    Variants

    variant

    default has no icon. success, danger, warning and info add their status icon; the surface stays neutral.

    • defaultdefault

    • success

    • danger

    • warning

    • info

    import { Button } from "@/components/ui/button"
    import { toast } from "@/components/ui/toast"
    
    <Button variant="secondary" onClick={() => toast({ title: "Changes saved", description: "Your project is up to date." })}>Show toast</Button>
    <Button variant="secondary" onClick={() => toast({ variant: "success", title: "Changes saved", description: "Your project is up to date." })}>Show toast</Button>
    <Button variant="secondary" onClick={() => toast({ variant: "danger", title: "Changes saved", description: "Your project is up to date." })}>Show toast</Button>
    <Button variant="secondary" onClick={() => toast({ variant: "warning", title: "Changes saved", description: "Your project is up to date." })}>Show toast</Button>
    <Button variant="secondary" onClick={() => toast({ variant: "info", title: "Changes saved", description: "Your project is up to date." })}>Show toast</Button>

    position

    Where the toast shows. Set on the Toaster for all its toasts, or on one toast() call. Corners swipe sideways to dismiss; the centers swipe toward their edge.

    • bottom-rightdefault

    • bottom-left

    • bottom-center

    • top-right

    • top-left

    • top-center

    import { Button } from "@/components/ui/button"
    import { toast } from "@/components/ui/toast"
    
    <Button variant="secondary" onClick={() => toast({ title: "Changes saved", description: "Your project is up to date." })}>Show toast</Button>
    <Button variant="secondary" onClick={() => toast({ title: "Changes saved", description: "Your project is up to date.", position: "bottom-left" })}>Show toast</Button>
    <Button variant="secondary" onClick={() => toast({ title: "Changes saved", description: "Your project is up to date.", position: "bottom-center" })}>Show toast</Button>
    <Button variant="secondary" onClick={() => toast({ title: "Changes saved", description: "Your project is up to date.", position: "top-right" })}>Show toast</Button>
    <Button variant="secondary" onClick={() => toast({ title: "Changes saved", description: "Your project is up to date.", position: "top-left" })}>Show toast</Button>
    <Button variant="secondary" onClick={() => toast({ title: "Changes saved", description: "Your project is up to date.", position: "top-center" })}>Show toast</Button>

    Examples

    Saved

    A button here; pressing it shows the toast on the screen, as toast() does in an app.

    import { Button } from "@/components/ui/button"
    import { toast } from "@/components/ui/toast"
    
    <Button variant="secondary" onClick={() => toast({ variant: "success", title: "Changes saved" })}>Show toast</Button>

    With an action

    A longer duration, since the user has to reach the button. The action also lives in the History panel. In an app: toast({ title: "Project archived", duration: 8000, action: <ToastAction altText="Undo from the History panel" onClick={undo}>Undo</ToastAction> }).

    import { Button } from "@/components/ui/button"
    
    <Button variant="secondary" onClick={archiveProject}>Archive project</Button>

    Failed

    import { Button } from "@/components/ui/button"
    import { toast } from "@/components/ui/toast"
    
    <Button variant="secondary" onClick={() => toast({ variant: "danger", title: "Upload failed", description: "The file is larger than 25 MB." })}>Show toast</Button>

    Top center

    Pick a corner or an edge center with position. At the top the stack hangs down, and a swipe up dismisses a toast.

    import { Button } from "@/components/ui/button"
    import { toast } from "@/components/ui/toast"
    
    <Button variant="secondary" onClick={() => toast({ variant: "success", title: "Link copied", position: "top-center" })}>Show toast</Button>

    Info

    import { Button } from "@/components/ui/button"
    import { toast } from "@/components/ui/toast"
    
    <Button variant="secondary" onClick={() => toast({ variant: "info", title: "Export started", description: "The file downloads when it is ready." })}>Show toast</Button>

    Stacked

    Press the button several times. The toasts overlap, the newest in front; hover or focus the stack to spread it out. Only the 3 newest show at once.

    import { Button } from "@/components/ui/button"
    import { toast } from "@/components/ui/toast"
    
    <Button variant="secondary" onClick={() => toast({ variant: "success", title: "Changes saved" })}>Show toast</Button>

    Do and don't

    Do

    • Confirm an action the user just took: Changes saved, Link copied.
    • Write the title in the past tense, and keep it to a few words.
    • Mount one Toaster at the root of the app, and call toast() after the action is done.
    • Keep the stack on and maxVisible low (3), so a burst of toasts never covers the page. Reuse an id, toast({ id: "saved" }), for an action the user repeats, so one toast updates instead of piling up.

    Don't

    • Don't put an error that blocks work in a toast; show it in the page, next to what failed.
    • Don't use it for a question or a decision; use AlertDialog.
    • Don't put the only way to do something in a toast action; it closes on its own.

    Props

    NameTypeValuesDefaultDescription
    variantenumdefault | success | danger | warning | infodefaultdefault has no icon. success, danger, warning and info add their status icon; the surface stays neutral.
    positionenumbottom-right | bottom-left | bottom-center | top-right | top-left | top-centerbottom-rightWhere the toast shows. Set on the Toaster for all its toasts, or on one toast() call. Corners swipe sideways to dismiss; the centers swipe toward their edge. Only on web. Not generated for iOS and Android.
    title requirednode--What happened, in a few words, past tense: Changes saved.
    descriptionnode--One more sentence when the title is not enough.
    durationnumber-4000How long it stays, in ms. Make it longer for a toast with an action or a long description. Only on web. Not generated for iOS and Android.
    actionnode--One ToastAction, such as Undo. Its altText says where else to do it.
    dismissibleboolean-trueThe Dismiss button. Keep it, so a toast never sits over content the user needs.
    openboolean--Set on Toast shown with state. Whether it is shown. Pair it with onOpenChange. Only on web. Not generated for iOS and Android.
    onOpenChangefunction--Set on Toast shown with state. Called with false when the time is up, or on Dismiss, Escape or a swipe. Only on web. Not generated for iOS and Android.
    iconnode--Native only. The status icon beside the title. The toaster supplies the one for the variant; a free-standing surface passes its own, or none for the default variant. Only on iOS, Android.
    dismissLabelstring-DismissNative only. The accessibility label of the Dismiss button. On the web it is labels.dismiss on the Toaster. Only on iOS, Android.
    onDismissfunction--Native only. Called when the Dismiss button is pressed. The toaster closes the toast; a free-standing surface removes itself. Only on iOS, Android.

    Slots

    NameRequiredDescription
    toasteryesOne Toaster, mounted once at the root of the app. position (bottom-right by default) picks the corner or edge center; a toast() call can pick another, which adds a stack there. stack (on by default) overlaps the toasts; maxVisible (3 by default) sets how many show at once. labels ({ region, dismiss }) gives the words screen readers hear in the page's language; they default to Notifications and Dismiss.

    Anatomy

    PartDescription
    rootToast: the raised surface with a border, radius-container and shadow-med, px-lg py-md, gap-md between its parts. The icon, text and buttons share its horizontal center line; with a description the icon stays level with the title.
    viewportToaster: the stack in the chosen corner or edge center, 384px wide at most, p-lg from the edges. Stacked, the toasts overlap, newest in front, and each older one is 5% smaller and peeks out by gap-sm, away from the edge; spread out, gap-sm sits between them. With stack={false} they sit in a column, gap-sm apart.
    iconThe status icon for success, danger, warning and info: Tabler icons, 16px, in the status text color, level with the title.
    titleWhat happened: 14px medium primary text.
    descriptionOptional second line: 14px secondary text.
    actionToastAction: one small secondary Button, such as Undo.
    closeThe Dismiss button: a 24px icon button with a Tabler X, 16px, secondary.
    hitAreaTransparent ::before on the Dismiss button, never smaller than size-target-min.
    contentThe text column beside the icon: title, description and action, gap-xs apart.
    closeIconThe X inside the Dismiss button: 16px (size-icon-md), in the secondary icon color.

    Accessibility

    Role: status

    KeysAction
    F8Moves focus to the toasts and spreads the stack out, so a keyboard user can reach an action or dismiss them.
    TabMoves through the action and the Dismiss button of each toast.
    EscapeCloses the focused toast.
    • Every toast is announced politely, after what a screen reader is reading. It never takes focus.
    • The timer pauses while the pointer is over a toast or focus is inside it, and while the window is in the background.
    • Stacked, the toasts spread out while the pointer is over them or focus is inside, so every action and Dismiss button can be read and reached. The toasts past maxVisible are hidden, from screen readers and Tab too, until a newer one closes; each was announced when it arrived.
    • A ToastAction needs altText: how to do the same without the toast (Undo from the History panel). A toast can close before anyone reaches it, so the action must also exist elsewhere.
    • The status icon is decorative; the title says what happened, so the state never relies on color alone.
    • It rises in from its edge only when the user allows motion, and fades in otherwise. A swipe dismisses it: sideways in a corner, toward the edge at the top or bottom center. It follows the finger while swiped; let go too early, it springs back. Under reduced motion it fades out. A stack slides and shrinks into place only when the user allows motion; under reduced motion it changes without moving.

    Install

    npx werewolf-ui add toast

    Run npx werewolf-ui init once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See Installation for requirements and the alternative registry setup.