feedbackcss

Toast

Sonner-style stacked notifications created imperatively through window.zToast, grouped by screen position, with swipe dismissal and promise helpers.

CSS Variables

VariableDefaultScopeDescription
--z-toast-base-y0px.z-toastComputed vertical rest position of the toast (peek or expanded offset).
--z-toast-bgvar(--z-drop).z-toastBackground color of a toast; re-tinted by rich colors.
--z-toast-blurvar(--z-global-blur).z-toastBackdrop blur radius used by the blur classes.
--z-toast-border-colorvar(--z-border).z-toastBorder base color, mixed with transparency using --z-toast-border-o.
--z-toast-border-ovar(--z-border-o).z-toastBorder opacity percentage used in the border color mix.
--z-toast-colorvar(--z-drop-f).z-toastText color of a toast; re-tinted by rich colors.
--z-toast-description-colorvar(--z-muted-f).z-toastText color of the description line.
--z-toast-dir-1.z-toastStacking direction: -1 for bottom groups, 1 for top groups.
--z-toast-front-height · hookauto.z-toast[data-mounted='true'][data-expanded='false'][data-front='false']Set by the singleton: measured height of the front toast, used to clip stacked toasts behind it.
--z-toast-index0.z-toastSet by the singleton: depth of the toast in the stack (0 = front); drives stacking order, peek offset, and scale.
--z-toast-initial-height · hookauto.z-toast[data-mounted='true'][data-expanded='true'][data-front='false']Set by the singleton: measured natural height of the toast, restored when the stack expands.
--z-toast-offset0px.z-toastSet by the singleton: expanded-stack offset of the toast from the group edge.
--z-toast-padding0.875rem 1rem.z-toastInner padding of a toast.
--z-toast-radiusvar(--z-global-radius).z-toastCorner radius of a toast.
--z-toast-scale1.z-toastComputed scale of the toast; collapsed stacks shrink by 5% per depth.
--z-toast-shadowvar(--z-global-shadow).z-toastBox shadow of a toast.
--z-toast-swipe-out-x0px.z-toastSet by the singleton: horizontal exit target of a swipe dismissal.
--z-toast-swipe-out-y0px.z-toastSet by the singleton: vertical exit target of a swipe dismissal.
--z-toast-swipe-x0px.z-toastSet by the singleton: live horizontal swipe offset.
--z-toast-swipe-y0px.z-toastSet by the singleton: live vertical swipe offset.
--z-toaster-gap0.75rem.z-toasterGap between toasts when the stack is expanded.
--z-toaster-offset-x1.5rem.z-toasterHorizontal distance from the viewport edge.
--z-toaster-offset-y1.5rem.z-toasterVertical distance from the viewport edge.
--z-toaster-peek0.875rem.z-toasterVisible sliver of each stacked toast when the group is collapsed.
--z-toaster-width22.25rem.z-toasterWidth of the toaster group on wide viewports.
--z-toaster-z-index1040.z-toasterStacking order of the toaster group.

Methods

SignatureDescription
config(options?: ZToastGlobalConfig): Readonly<InternalGlobalConfig>Reads or updates the global defaults (position, duration, max, expand, dismissible, closeButton, richColors, blur, gap, offset, cls, stl, i18n) and returns the current configuration.
danger(input: string | ZToastOptions, options?: ZToastOptions): stringShows a toast with the danger status icon and coloring; returns its id.
dismiss(id?: string): voidDismisses one toast by id, or every toast when called without an id.
error(input: string | ZToastOptions, options?: ZToastOptions): stringAlias of danger.
info(input: string | ZToastOptions, options?: ZToastOptions): stringShows a toast with the info status icon and coloring; returns its id.
loading(input: string | ZToastOptions, options?: ZToastOptions): stringShows a persistent loading toast with no auto-dismiss timeout; returns its id.
message(input: string | ZToastOptions, options?: ZToastOptions): stringShows a neutral toast and returns its id. Accepts a message string or a full options object.
promise(promise: Promise<T> | (() => Promise<T>), options: ZToastPromiseOptions<T>): ZToastPromiseResult<T>Shows a loading toast that updates to success or danger when the promise settles. Branches accept strings, options objects, or functions of the settled value; a missing branch dismisses the toast. Returns the id plus a thenable with unwrap().
success(input: string | ZToastOptions, options?: ZToastOptions): stringShows a toast with the success status icon and coloring; returns its id.
update(id: string, input: string | ZToastOptions, options?: ZToastOptions): stringUpdates an existing toast in place (same id), merging options and restarting its timer.
warning(input: string | ZToastOptions, options?: ZToastOptions): stringShows a toast with the warning status icon and coloring; returns its id.

Data Hooks

AttributeValuesApplies toRoleDescription
data-close-button—descendantmarkerWhether the toast renders a close button.
data-dismissible—descendantmarkerWhether swipe dismissal is enabled for the toast.
data-expanded—descendantmarkerWhether the group is expanded (hover/focus) or collapsed to the peek stack.
data-front—descendantmarkerWhether this toast is the front (newest) item of the collapsed stack.
data-mounted—descendantmarkerfalse until the first animation frame, then true; drives the enter transition.
data-position—descendantmarkerOn the toaster group: the screen position (bottom-right by default, plus bottom-left, bottom-center, top-right, top-left, top-center).
data-removed—descendantmarkerSet true while the toast plays its leave transition.
data-rich-colors—descendantmarkerWhether status colors tint the whole toast (from the richColors option).
data-status—descendantmarkerToast status (default, success, danger, warning, info, loading); colors the icon and, with rich colors, the whole toast.
data-swipe-out—descendantmarkerSet true when a swipe dismisses the toast; plays the swipe-out transform.
data-swiping—descendantmarkerSet true during an active swipe; disables transitions.
data-toast-id—descendantmarkerThe toast's id, set on its li element.
data-visible—descendantmarkerSet false for toasts beyond the max visible count.
data-x-position—descendantmarkerOn each toast: left, right, or center; used for swipe-direction resistance.
data-y-position—descendantmarkerOn each toast: top or bottom, derived from its group; flips the stacking direction and transform origin.

CSS Classes

ClassRoleApplies toDescription
.z-toastroot.z-toasterRoot class of a single toast (li); absolutely positioned in the stack with enter/leave transitions.
.z-toast-actionelement.z-toasterPrimary action button or link (a[href]) of the toast.
.z-toast-actionselement.z-toasterRow holding the action and cancel controls.
.z-toast-blurmodifier.z-toasterApplies a backdrop blur and a slightly translucent background to one toast.
.z-toast-cancelelement.z-toasterCancel button or link (a[href]) of the toast.
.z-toast-closeelement.z-toasterClose button in the top inline-end corner, shown when closeButton is enabled.
.z-toast-contentelement.z-toasterColumn holding the title and description.
.z-toast-descriptionelement.z-toasterMuted secondary line under the title.
.z-toast-iconelement.z-toasterStatus icon slot at the start of the toast; colored by data-status.
.z-toast-titleelement.z-toasterMedium-weight toast title.
.z-toasterroot.z-toasterRoot class of the fixed toaster group (ol appended to body); positions the stack at a screen corner or edge.
.z-toaster-blurmodifier.z-toasterApplies the backdrop blur to every toast in the group.

Accessibility

  • The toaster group is a role="region" list with a localized aria-label (Notifications by default); each toast is a role="status" listitem with aria-live="polite" (assertive for danger and warning).
  • Close, action, and cancel controls are native <button> elements (or <a href> links when href is set on action/cancel) with localized labels and visible focus outlines.