Skip to content
API reference

Toast options

The last argument of every toast helper — typed as ExternalToast. Toaster-wide defaults live in toastOptions.

Reference

OptionTypeDefault
idstring | number—
Reuse an existing id to update that toast in place.
descriptionstring | JSXOutput | () => …—
Second line under the title.
durationnumber4000
Time in ms before the toast closes. Number.POSITIVE_INFINITY keeps it until dismissed.
iconJSXOutput—
Replaces the icon of this toast.
actionAction | JSXOutput—
Primary button (see below), or your own JSX.
cancelAction | JSXOutput—
Secondary button. Does nothing on toasts with dismissible: false.
closeButtonboolean—
Show (or hide) the close button, overriding the Toaster.
dismissiblebooleantrue
false disables swiping and the cancel button. Use with duration: Infinity for toasts that must stay.
onDismiss$QRL<(toast: Toast) => unknown>—
Called when the user closes the toast with the close button or a swipe, or your code calls toast.dismiss(). Not called for the cancel/action buttons or the timer.
onAutoClose$QRL<(toast: Toast) => unknown>—
Called when the toast closes because its timer ran out.
positionPosition—
Show this toast in another corner than the Toaster's.
toasterIdstring—
Send the toast to the <Toaster id> with that id.
richColorsboolean—
Override the Toaster's richColors.
invertboolean—
Override the Toaster's invert.
unstyledboolean—
Drop the default styles for this toast.
classstring—
Class for the toast element.
descriptionClassstring—
Class for the description.
classesToastClassnames—
Per-part classes — see Styling.
styleCSSProperties—
Inline style for the toast element.
actionButtonStyleCSSProperties—
Inline style for the action button.
cancelButtonStyleCSSProperties—
Inline style for the cancel button.
testIdstring—
Rendered as data-testid on the toast.
importantDeprecatedboolean—
No effect. In qwik-sonner 1.x it announced the toast with aria-live="assertive"; sonner 2 dropped it, and every toast is announced through the Toaster's polite live region.

Action

The shape of action and cancel when you don't pass JSX:

FieldTypeDefault
labelstring | JSXOutput—
Button content.
onClick$QRL<(event, button) => any>—
Runs on click. Wrap it in $().
preventDefaultbooleanfalse
Keep the toast open after the click.
actionButtonStyleDeprecatedCSSProperties—
No effect, as in sonner. Style the buttons with the toast's actionButtonStyle / cancelButtonStyle or the Toaster's toastOptions.

Duration

toast("Saved", { duration: 10000 });

// Stays until the user or your code dismisses it
toast("Connection lost", { duration: Number.POSITIVE_INFINITY });

Hovering the toasts, pressing on them, or hiding the tab pauses every timer.

Callbacks

import { $ } from "@qwik.dev/core";

toast("Event has been created", {
  onDismiss$: $((t) => console.log(`Toast ${t.id} was dismissed`)),
  onAutoClose$: $((t) => console.log(`Toast ${t.id} closed on its own`)),
});

Position

toast("Copied to clipboard", { position: "top-center" });

Toasts that must stay

toast.warning("You have unsaved changes", {
  duration: Number.POSITIVE_INFINITY,
  dismissible: false,
  action: { label: "Save", onClick$: $(() => save()) },
});