# Toast (`.z-toaster`)

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

- **Kind:** css
- **Category:** feedback

## CSS Variables

| Variable | Default | Scope | Affects | Description |
| --- | --- | --- | --- | --- |
| `--z-toast-base-y` | `0px` | `.z-toast` | `transform` | Computed vertical rest position of the toast (peek or expanded offset). |
| `--z-toast-bg` | `var(--z-drop)` | `.z-toast` | `background-color` | Background color of a toast; re-tinted by rich colors. |
| `--z-toast-blur` | `var(--z-global-blur)` | `.z-toast` | `-webkit-backdrop-filter`, `backdrop-filter` | Backdrop blur radius used by the blur classes. |
| `--z-toast-border-color` | `var(--z-border)` | `.z-toast` | `border` | Border base color, mixed with transparency using `--z-toast-border-o`. |
| `--z-toast-border-o` | `var(--z-border-o)` | `.z-toast` | `border` | Border opacity percentage used in the border color mix. |
| `--z-toast-color` | `var(--z-drop-f)` | `.z-toast` | `color` | Text color of a toast; re-tinted by rich colors. |
| `--z-toast-description-color` | `var(--z-muted-f)` | `.z-toast` | `color` | Text color of the description line. |
| `--z-toast-dir` | `-1` | `.z-toast` | `transform` | Stacking direction: `-1` for bottom groups, `1` for top groups. |
| `--z-toast-front-height` | `auto` | `.z-toast[data-mounted='true'][data-expanded='false'][data-front='false']` | `height` | Set by the singleton: measured height of the front toast, used to clip stacked toasts behind it. |
| `--z-toast-index` | `0` | `.z-toast` | `transform`, `z-index` | Set by the singleton: depth of the toast in the stack (0 = front); drives stacking order, peek offset, and scale. |
| `--z-toast-initial-height` | `auto` | `.z-toast[data-mounted='true'][data-expanded='true'][data-front='false']` | `height` | Set by the singleton: measured natural height of the toast, restored when the stack expands. |
| `--z-toast-offset` | `0px` | `.z-toast` | `transform` | Set by the singleton: expanded-stack offset of the toast from the group edge. |
| `--z-toast-padding` | `0.875rem 1rem` | `.z-toast` | `padding` | Inner padding of a toast. |
| `--z-toast-radius` | `var(--z-global-radius)` | `.z-toast` | `border-radius` | Corner radius of a toast. |
| `--z-toast-scale` | `1` | `.z-toast` | `transform` | Computed scale of the toast; collapsed stacks shrink by 5% per depth. |
| `--z-toast-shadow` | `var(--z-global-shadow)` | `.z-toast` | `box-shadow` | Box shadow of a toast. |
| `--z-toast-swipe-out-x` | `0px` | `.z-toast` | `transform` | Set by the singleton: horizontal exit target of a swipe dismissal. |
| `--z-toast-swipe-out-y` | `0px` | `.z-toast` | `transform` | Set by the singleton: vertical exit target of a swipe dismissal. |
| `--z-toast-swipe-x` | `0px` | `.z-toast` | `transform` | Set by the singleton: live horizontal swipe offset. |
| `--z-toast-swipe-y` | `0px` | `.z-toast` | `transform` | Set by the singleton: live vertical swipe offset. |
| `--z-toaster-gap` | `0.75rem` | `.z-toaster` | `height` | Gap between toasts when the stack is expanded. |
| `--z-toaster-offset-x` | `1.5rem` | `.z-toaster` | `inset-inline-end`, `inset-inline-start`, `max-width` | Horizontal distance from the viewport edge. |
| `--z-toaster-offset-y` | `1.5rem` | `.z-toaster` | `bottom`, `top` | Vertical distance from the viewport edge. |
| `--z-toaster-peek` | `0.875rem` | `.z-toaster` | `transform` | Visible sliver of each stacked toast when the group is collapsed. |
| `--z-toaster-width` | `22.25rem` | `.z-toaster` | `width` | Width of the toaster group on wide viewports. |
| `--z-toaster-z-index` | `1040` | `.z-toaster` | `z-index` | Stacking order of the toaster group. |

## Methods

| Method | Params | Returns | 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 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.

## Notes

- Toasts are created imperatively (`zToast.success('Saved')`); the toaster group is created on demand and appended to `body`, so no markup is required. The toast pack exposes `window.zToast`.
- Setting `href` on `action` or `cancel` renders a native `<a>` link (supporting `target` and `rel`, defaulting `rel` to `noopener noreferrer` for `target="_blank"`) while still running `onClick` and dismissing unless prevented.
- Collapsed stacks peek by `--z-toaster-peek` per item and scale down by 5% per depth; hovering or focusing the group expands it.
- Auto-dismiss timers pause while the group is expanded or hovered, or the page is hidden; `loading` toasts never auto-dismiss. Default duration is 4000 ms (danger 6000 ms).
- Toasts can be swiped away along the group's edge direction; `dismissible: false` or interactive content under the pointer blocks the swipe.
- On viewports up to 40rem wide the group spans the viewport with 1rem side offsets.

## Guides

- [Styling with cls and stl](https://next.0build.dev/docs/guides/styling.md)
- [Translating Components](https://next.0build.dev/docs/guides/i18n.md)
- [Icon Resolution](https://next.0build.dev/docs/guides/icons.md)
- [The data-source Convention](https://next.0build.dev/docs/guides/data-source.md)
- [Openers & Triggers](https://next.0build.dev/docs/guides/triggers.md)
- [Dialog Behavior](https://next.0build.dev/docs/guides/dialogs.md)
- [Utilities](https://next.0build.dev/docs/guides/utilities.md)
- [Runtime](https://next.0build.dev/docs/guides/runtime.md)

## Related

- [Alert](https://next.0build.dev/docs/components/alert.md)
