Skip to content
API reference

<Toaster />

Renders the toasts. Add it once, in your root layout; every prop below is optional.

Playground

These controls drive the site's own Toaster — the settings stay while you browse.

position
theme
richColors
expand
closeButton
invert
<Toaster />

Props

PropTypeDefault
positionSignalPosition"bottom-right"
Where toasts stack: top-left, top-center, top-right, bottom-left, bottom-center or bottom-right. Swipe direction follows it.
themeSignal"light" | "dark" | "system""light"
Color scheme. system follows prefers-color-scheme and its changes.
richColorsSignalbooleanfalse
Colored backgrounds for success, info, warning and error toasts.
invertSignalbooleanfalse
Dark toasts on a light theme and vice versa.
dirSignal"ltr" | "rtl" | "auto""auto"
Text direction. auto reads <html dir> (and keeps tracking it).
expandbooleanfalse
Show every toast expanded instead of stacked; otherwise they expand on hover.
visibleToastsnumber3
How many toasts are visible at once; the rest wait behind.
closeButtonbooleanfalse
Adds a close button to every toast.
durationnumber4000
Default time in ms before a toast closes on its own.
gapnumber14
Space in px between expanded toasts.
offsetstring | number | { top?, right?, bottom?, left? }"24px"
Distance from the viewport edges. Numbers are pixels; omitted sides keep the default.
mobileOffsetstring | number | { top?, right?, bottom?, left? }"16px"
Same as offset, below 600px viewport width.
swipeDirections("top" | "right" | "bottom" | "left")[]from position
Directions a toast can be swiped away. Defaults to the vertical edge plus the horizontal side of position.
toastOptionsToastOptions—
Defaults for every toast — see below.
iconsToastIcons—
Replace the success, info, warning, error, loading and close icons with your own JSX.
hotkeystring[]["altKey", "KeyT"]
Keys that expand the toasts and move focus to them. Modifier properties (altKey, metaKey…) or KeyboardEvent.code values.
idstring—
Names this Toaster. It then only renders toasts created with a matching toasterId; unnamed Toasters render toasts without one.
topLayerbooleanfalse
Promote the toaster to the browser top layer (Popover API) so toasts show above <dialog> modals and fullscreen elements.
containerAriaLabelstring"Notifications"
Label of the toasts region; the hotkey is appended (e.g. Notifications alt+T).
customAriaLabelstring—
Replaces the whole region label, hotkey included.
classstring—
Class added to each toast list (<ol data-sonner-toaster>).
styleCSSProperties—
Inline style for each toast list — handy for CSS variables.
loadingIconDeprecatedJSXOutput—
Use icons.loading.
pauseWhenPageIsHiddenDeprecatedboolean—
No effect: timers always pause while the page is hidden (sonner 2 behaviour).

Changing props at runtime

Props marked Signal also accept a Signal. The Toaster is rendered on the server and resumed, so pass the signal itself — not signal.value — when the value should change after load:

import { component$, useSignal } from "@qwik.dev/core";
import { Toaster, type ToasterProps } from "qwik-sonner";

type Position = Extract<ToasterProps["position"], string>;

export default component$(() => {
  const position = useSignal<Position>("bottom-right");

  return (
    <>
      <Toaster position={position} />
      <button onClick$={() => (position.value = "top-center")}>Move</button>
    </>
  );
});

toastOptions

Defaults applied to every toast; a toast's own options win.

OptionTypeDefault
durationnumber—
Default duration in ms (wins over duration).
closeButtonboolean—
Close button on every toast.
classstring—
Class for every toast element.
descriptionClassstring—
Class for every description.
classesToastClassnames—
Per-part classes, see Styling.
styleCSSProperties—
Inline style for every toast.
actionButtonStyleCSSProperties—
Style for action buttons (a toast's own wins).
cancelButtonStyleCSSProperties—
Style for cancel buttons (a toast's own wins).
unstyledboolean—
Drop the default toast styles.
closeButtonAriaLabelstring"Close toast"
Accessible label of the close button.

Icons

Any key you leave out keeps the default icon. To change one toast's icon use its icon option.

<Toaster
  icons={{
    success: <CheckIcon />,
    info: <InfoIcon />,
    warning: <WarningIcon />,
    error: <ErrorIcon />,
    loading: <Spinner />,
    close: <XIcon />,
  }}
/>

Offset

<Toaster offset={32} />
<Toaster offset="5vh" />
<Toaster offset={{ bottom: 80, right: 24 }} mobileOffset={{ bottom: 64 }} />

Keyboard

Alt + T expands the toasts and moves focus to them; Esc collapses them again.

// ⌘ + K on macOS
<Toaster hotkey={["metaKey", "KeyK"]} />