feedbackcss
Toast
Sonner-style stacked notifications created imperatively through window.zToast, grouped by screen position, with swipe dismissal and promise helpers.
CSS Variables
| Variable | Default | Scope | Description |
|---|---|---|---|
--z-toast-base-y | 0px | .z-toast | Computed vertical rest position of the toast (peek or expanded offset). |
--z-toast-bg | var(--z-drop) | .z-toast | Background color of a toast; re-tinted by rich colors. |
--z-toast-blur | var(--z-global-blur) | .z-toast | Backdrop blur radius used by the blur classes. |
--z-toast-border-color | var(--z-border) | .z-toast | Border base color, mixed with transparency using --z-toast-border-o. |
--z-toast-border-o | var(--z-border-o) | .z-toast | Border opacity percentage used in the border color mix. |
--z-toast-color | var(--z-drop-f) | .z-toast | Text color of a toast; re-tinted by rich colors. |
--z-toast-description-color | var(--z-muted-f) | .z-toast | Text color of the description line. |
--z-toast-dir | -1 | .z-toast | Stacking direction: -1 for bottom groups, 1 for top groups. |
--z-toast-front-height · hook | auto | .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-index | 0 | .z-toast | Set by the singleton: depth of the toast in the stack (0 = front); drives stacking order, peek offset, and scale. |
--z-toast-initial-height · hook | auto | .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-offset | 0px | .z-toast | Set by the singleton: expanded-stack offset of the toast from the group edge. |
--z-toast-padding | 0.875rem 1rem | .z-toast | Inner padding of a toast. |
--z-toast-radius | var(--z-global-radius) | .z-toast | Corner radius of a toast. |
--z-toast-scale | 1 | .z-toast | Computed scale of the toast; collapsed stacks shrink by 5% per depth. |
--z-toast-shadow | var(--z-global-shadow) | .z-toast | Box shadow of a toast. |
--z-toast-swipe-out-x | 0px | .z-toast | Set by the singleton: horizontal exit target of a swipe dismissal. |
--z-toast-swipe-out-y | 0px | .z-toast | Set by the singleton: vertical exit target of a swipe dismissal. |
--z-toast-swipe-x | 0px | .z-toast | Set by the singleton: live horizontal swipe offset. |
--z-toast-swipe-y | 0px | .z-toast | Set by the singleton: live vertical swipe offset. |
--z-toaster-gap | 0.75rem | .z-toaster | Gap between toasts when the stack is expanded. |
--z-toaster-offset-x | 1.5rem | .z-toaster | Horizontal distance from the viewport edge. |
--z-toaster-offset-y | 1.5rem | .z-toaster | Vertical distance from the viewport edge. |
--z-toaster-peek | 0.875rem | .z-toaster | Visible sliver of each stacked toast when the group is collapsed. |
--z-toaster-width | 22.25rem | .z-toaster | Width of the toaster group on wide viewports. |
--z-toaster-z-index | 1040 | .z-toaster | Stacking order of the toaster group. |
Methods
| Signature | Description |
|---|---|
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): string | Shows a toast with the danger status icon and coloring; returns its id. |
dismiss(id?: string): void | Dismisses one toast by id, or every toast when called without an id. |
error(input: string | ZToastOptions, options?: ZToastOptions): string | Alias of danger. |
info(input: string | ZToastOptions, options?: ZToastOptions): string | Shows a toast with the info status icon and coloring; returns its id. |
loading(input: string | ZToastOptions, options?: ZToastOptions): string | Shows a persistent loading toast with no auto-dismiss timeout; returns its id. |
message(input: string | ZToastOptions, options?: ZToastOptions): string | Shows 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): string | Shows a toast with the success status icon and coloring; returns its id. |
update(id: string, input: string | ZToastOptions, options?: ZToastOptions): string | Updates an existing toast in place (same id), merging options and restarting its timer. |
warning(input: string | ZToastOptions, options?: ZToastOptions): string | Shows a toast with the warning status icon and coloring; returns its id. |
Data Hooks
| Attribute | Values | Applies to | Role | Description |
|---|---|---|---|---|
data-close-button | — | descendant | marker | Whether the toast renders a close button. |
data-dismissible | — | descendant | marker | Whether swipe dismissal is enabled for the toast. |
data-expanded | — | descendant | marker | Whether the group is expanded (hover/focus) or collapsed to the peek stack. |
data-front | — | descendant | marker | Whether this toast is the front (newest) item of the collapsed stack. |
data-mounted | — | descendant | marker | false until the first animation frame, then true; drives the enter transition. |
data-position | — | descendant | marker | On the toaster group: the screen position (bottom-right by default, plus bottom-left, bottom-center, top-right, top-left, top-center). |
data-removed | — | descendant | marker | Set true while the toast plays its leave transition. |
data-rich-colors | — | descendant | marker | Whether status colors tint the whole toast (from the richColors option). |
data-status | — | descendant | marker | Toast status (default, success, danger, warning, info, loading); colors the icon and, with rich colors, the whole toast. |
data-swipe-out | — | descendant | marker | Set true when a swipe dismisses the toast; plays the swipe-out transform. |
data-swiping | — | descendant | marker | Set true during an active swipe; disables transitions. |
data-toast-id | — | descendant | marker | The toast's id, set on its li element. |
data-visible | — | descendant | marker | Set false for toasts beyond the max visible count. |
data-x-position | — | descendant | marker | On each toast: left, right, or center; used for swipe-direction resistance. |
data-y-position | — | descendant | marker | On each toast: top or bottom, derived from its group; flips the stacking direction and transform origin. |
CSS Classes
| Class | Role | Applies to | Description |
|---|---|---|---|
.z-toast | root | .z-toaster | Root class of a single toast (li); absolutely positioned in the stack with enter/leave transitions. |
.z-toast-action | element | .z-toaster | Primary action button or link (a[href]) of the toast. |
.z-toast-actions | element | .z-toaster | Row holding the action and cancel controls. |
.z-toast-blur | modifier | .z-toaster | Applies a backdrop blur and a slightly translucent background to one toast. |
.z-toast-cancel | element | .z-toaster | Cancel button or link (a[href]) of the toast. |
.z-toast-close | element | .z-toaster | Close button in the top inline-end corner, shown when closeButton is enabled. |
.z-toast-content | element | .z-toaster | Column holding the title and description. |
.z-toast-description | element | .z-toaster | Muted secondary line under the title. |
.z-toast-icon | element | .z-toaster | Status icon slot at the start of the toast; colored by data-status. |
.z-toast-title | element | .z-toaster | Medium-weight toast title. |
.z-toaster | root | .z-toaster | Root class of the fixed toaster group (ol appended to body); positions the stack at a screen corner or edge. |
.z-toaster-blur | modifier | .z-toaster | Applies the backdrop blur to every toast in the group. |
Accessibility
- The toaster group is a
role="region"list with a localizedaria-label(Notificationsby default); each toast is arole="status"listitem witharia-live="polite"(assertivefor danger and warning). - Close, action, and cancel controls are native
<button>elements (or<a href>links whenhrefis set onaction/cancel) with localized labels and visible focus outlines.