---
title: "Toast · UI SDK — StyleX Blocks"
description: "Transient notifications with indicator, title, description, action, and close slots."
url: "https://stylexblocks.com/components/ui-sdk/toast/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Toast

Transient notifications with indicator, title, description, action, and close slots.

- Behavior engine: UI SDK
- Also available for: [Ark UI](https://stylexblocks.com/components/ark-ui/toast.md), [Base UI](https://stylexblocks.com/components/base-ui/toast.md)
- Category: Feedback
- Used in blocks: [AI Chat Conversation](https://stylexblocks.com/block/ui-sdk/ai-chat.md), [AI Chat Landing](https://stylexblocks.com/block/ui-sdk/ai-chat-landing.md), [Analytics Dashboard](https://stylexblocks.com/block/ui-sdk/analytics-dashboard.md), [Basic Login](https://stylexblocks.com/block/ui-sdk/basic-login.md), [Canvas Editor](https://stylexblocks.com/block/ui-sdk/canvas-editor.md), [Card Grid](https://stylexblocks.com/block/ui-sdk/card-grid.md), [Centered Hero](https://stylexblocks.com/block/ui-sdk/centered-hero.md), [Checkout Form](https://stylexblocks.com/block/ui-sdk/checkout-form.md), [Checkout Wizard](https://stylexblocks.com/block/ui-sdk/checkout-wizard.md), [Collapsible Table](https://stylexblocks.com/block/ui-sdk/collapsible-table.md), [Comparison Table](https://stylexblocks.com/block/ui-sdk/comparison-table.md), [Contact Form](https://stylexblocks.com/block/ui-sdk/contact-form.md), [Course Detail](https://stylexblocks.com/block/ui-sdk/course-detail.md), [Data Dashboard](https://stylexblocks.com/block/ui-sdk/data-dashboard.md), [Documentation Catalog](https://stylexblocks.com/block/ui-sdk/documentation-catalog.md), [Documentation Design](https://stylexblocks.com/block/ui-sdk/documentation-design.md), [Documentation Technical](https://stylexblocks.com/block/ui-sdk/documentation-technical.md), [Executive Dashboard](https://stylexblocks.com/block/ui-sdk/executive-dashboard.md), [File Explorer](https://stylexblocks.com/block/ui-sdk/file-explorer.md), [Filterable Table](https://stylexblocks.com/block/ui-sdk/filterable-table.md), [Two-Column Form](https://stylexblocks.com/block/ui-sdk/form-two-column.md), [Form Wizard](https://stylexblocks.com/block/ui-sdk/form-wizard.md), [Dialog Wizard](https://stylexblocks.com/block/ui-sdk/form-wizard-dialog.md), [Inline Wizard](https://stylexblocks.com/block/ui-sdk/form-wizard-inline.md), [Vertical Wizard](https://stylexblocks.com/block/ui-sdk/form-wizard-vertical.md), [Funnel & Cohort Dashboard](https://stylexblocks.com/block/ui-sdk/funnel-cohort-dashboard.md), [Gallery Hero](https://stylexblocks.com/block/ui-sdk/gallery-hero.md), [Grouped Table](https://stylexblocks.com/block/ui-sdk/grouped-table.md), [IDE Workspace](https://stylexblocks.com/block/ui-sdk/ide.md), [Inbox Table](https://stylexblocks.com/block/ui-sdk/inbox-table.md), [Incident Console](https://stylexblocks.com/block/ui-sdk/incident-console.md), [Kanban Board](https://stylexblocks.com/block/ui-sdk/kanban-board.md), [Login Card](https://stylexblocks.com/block/ui-sdk/login-card.md), [Login Split](https://stylexblocks.com/block/ui-sdk/login-split.md), [Login SSO](https://stylexblocks.com/block/ui-sdk/login-sso.md), [Messaging Shell](https://stylexblocks.com/block/ui-sdk/messaging-shell.md), [Order Detail](https://stylexblocks.com/block/ui-sdk/order-detail.md), [Page Editor](https://stylexblocks.com/block/ui-sdk/page-editor.md), [Portfolio Dashboard](https://stylexblocks.com/block/ui-sdk/portfolio-dashboard.md), [Product Detail](https://stylexblocks.com/block/ui-sdk/product-detail.md), [Product Gallery](https://stylexblocks.com/block/ui-sdk/product-gallery.md), [Project Status Dashboard](https://stylexblocks.com/block/ui-sdk/project-status-dashboard.md), [Searchable Table](https://stylexblocks.com/block/ui-sdk/searchable-table.md), [Service Monitoring](https://stylexblocks.com/block/ui-sdk/service-monitoring.md), [Settings Dialog](https://stylexblocks.com/block/ui-sdk/settings-dialog.md), [Settings Form](https://stylexblocks.com/block/ui-sdk/settings-form.md), [Settings Panels](https://stylexblocks.com/block/ui-sdk/settings-panels.md), [Shell Nav](https://stylexblocks.com/block/ui-sdk/shell-nav.md), [Side Nav Shell](https://stylexblocks.com/block/ui-sdk/shell-side-nav.md), [Top Nav Shell](https://stylexblocks.com/block/ui-sdk/shell-top-nav.md), [Side Gallery](https://stylexblocks.com/block/ui-sdk/side-gallery.md), [Simple Table](https://stylexblocks.com/block/ui-sdk/simple-table.md), [Theme Showcase](https://stylexblocks.com/block/ui-sdk/theme-showcase.md), [Tree Table](https://stylexblocks.com/block/ui-sdk/tree-table.md), [Work Item Detail](https://stylexblocks.com/block/ui-sdk/work-item-detail.md)
- HTML page: https://stylexblocks.com/components/ui-sdk/toast/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init --style ui-sdk
```

Then add the item as source you own:

```sh
npx stylexblocks add toast
```

Equivalent: `npx shadcn add @stylexblocks/toast`. Registry item JSON: https://stylexblocks.com/r/ui-sdk/toast.json

## Usage

```tsx
import { Toaster, toaster } from "#components/ui/ui-sdk/toast.tsx";

// toaster is UI SDK's toast queue — call it from anywhere, no provider;
// <Toaster /> is the region rendering each toast through the toast slot
// recipe, with timers, pause on hover, and swipe-to-dismiss.
export function App() {
  return (
    <>
      <button
        onClick={() =>
          toaster.success("Changes saved", {
            description: "Your theme has been published.",
          })
        }
      >
        Save
      </button>
      <Toaster />
    </>
  );
}
```

## Source

`components/ui/ui-sdk/toast.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import {
  createToaster,
  Toast as UiSdkToast,
  ToastAction,
  ToastClose,
  ToastDescription,
  ToastRegion,
  ToastTitle,
  type Toaster as ToasterQueue,
} from "@ui-sdk/react/toast";
import { createSlotRecipeContext } from "#lib/ui-sdk/create-slot-recipe-context.tsx";
import { defineSlotRecipe, resolveSlotStyles } from "#lib/recipe-props.ts";
import { zIndices } from "@stylexblocks/ui/tokens/z-indices.stylex.ts";
import { colorPalette } from '@stylexblocks/ui/color-palette.stylex.ts'
import { cursor } from '@stylexblocks/ui/tokens/cursor.stylex.ts'
import { easings } from '@stylexblocks/ui/tokens/easings.stylex.ts'
import { fontSizes } from '@stylexblocks/ui/tokens/font-sizes.stylex.ts'
import { fontWeights } from '@stylexblocks/ui/tokens/font-weights.stylex.ts'
import { lineHeights } from '@stylexblocks/ui/tokens/line-heights.stylex.ts'
import { radii } from '@stylexblocks/ui/tokens/radii.stylex.ts'
import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'
import { semanticShadows } from '@stylexblocks/ui/semantic-tokens/shadows.stylex.ts'
import { sizes } from '@stylexblocks/ui/tokens/sizes.stylex.ts'
import { spacing } from '@stylexblocks/ui/tokens/spacing.stylex.ts'

const toastRoot = stylex.create({
  base: {
    width: sizes.full,
    display: 'flex',
    alignItems: 'flex-start',
    position: 'relative',
    gap: spacing._2,
    paddingBlock: spacing._3,
    paddingInlineStart: spacing._3,
    paddingInlineEnd: spacing._6,
    borderRadius: radii.md,
    borderWidth: '1px',
    translate: 'var(--x) var(--y)',
    scale: 'var(--scale)',
    zIndex: 'var(--z-index)',
    height: 'var(--height, var(--toast-height))',
    opacity: 'var(--opacity)',
    willChange: 'translate, opacity, scale, height',
    transition:
      'translate 400ms, scale 400ms, opacity 400ms, height 200ms, box-shadow 200ms',
    transitionTimingFunction: easings.bounceIn,
    backgroundColor: semanticColors.bgPanel,
    color: semanticColors.fg,
    boxShadow: semanticShadows.lg,
    overflow: 'hidden',
    '--toast-indicated-color': semanticColors.fgMuted,
  },
})

const toastTitle = stylex.create({
  base: {
    fontWeight: fontWeights.medium,
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    marginInlineEnd: spacing._2,
  },
})

const toastDescription = stylex.create({
  base: {
    display: 'inline',
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    opacity: 0.8,
  },
})

const toastIndicator = stylex.create({
  base: {
    flexShrink: 0,
    width: sizes._5,
    height: sizes._5,
    color: 'var(--toast-indicated-color)',
  },
})

const toastActionTrigger = stylex.create({
  base: {
    cursor: cursor.button,
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    fontWeight: fontWeights.medium,
    height: sizes._6,
    paddingInline: spacing._3,
    marginInlineStart: `calc(${spacing._3} * -1)`,
    borderRadius: radii.sm,
    alignSelf: 'flex-start',
    transition: 'background 200ms',
    color: {
      default: `color-mix(in oklch, ${colorPalette.solid} 80%, transparent)`,
      ':hover': colorPalette.solid,
    },
    backgroundColor: {
      default: null,
      ':hover': semanticColors.bgSubtle,
    },
  },
})

const toastCloseTrigger = stylex.create({
  base: {
    position: 'absolute',
    top: spacing._2,
    insetInlineEnd: spacing._2,
  },
})

// Local chrome the recipe leaves to the composition layer: logical-property
// fixes for generated Chakra shorthands (`ps`/`pe`/`ms`/`marginEnd`/
// `insetEnd`), the viewport's fixed stack in the bottom-end corner (above
// all page chrome), enter/leave transitions keyed off UI SDK's
// `data-starting-style` / `data-ending-style`, swipe-to-dismiss following
// `--toast-swipe-x/y`, the close trigger's icon-button look, and per-type
// indicator colors. The region is a plain stacked list, like the Base UI
// version: toasts lay out in a column rather than a collapsed pile.
const chrome = stylex.create({
  viewport: {
    position: "fixed",
    bottom: spacing._4,
    insetInlineEnd: spacing._4,
    display: "flex",
    flexDirection: "column",
    gap: spacing._2,
    width: "22rem",
    maxWidth: "calc(100vw - 2rem)",
    margin: 0,
    padding: 0,
    listStyle: "none",
    zIndex: zIndices.toast,
    outline: 0,
  },
  root: {
    maxWidth: "calc(100vw - 2rem)",
    paddingInlineStart: spacing._3,
    paddingInlineEnd: spacing._6,
    width: "22.5rem",
    transitionProperty: {
      default: "opacity, transform",
      ":is([data-swiping])": "none",
    },
    transitionDuration: "250ms",
    transitionTimingFunction: "cubic-bezier(0.21, 1.02, 0.73, 1)",
    opacity: {
      default: 1,
      ":is([data-starting-style])": 0,
      ":is([data-ending-style])": 0,
    },
    transform: {
      default: "translateY(0)",
      ":is([data-starting-style])": "translateY(0.75rem)",
      ":is([data-ending-style])": "translateY(0.75rem)",
    },
    translate: "var(--toast-swipe-x, 0px) var(--toast-swipe-y, 0px)",
    // the region lays toasts out in its own `ol`, out of reach of the
    // viewport's flex gap, so each toast spaces itself from the next
    marginBottom: {
      default: 0,
      ":not(:last-child)": spacing._2,
    },
    userSelect: "none",
  },

  title: {
    marginInlineEnd: spacing._2,
  },
  actionTrigger: {
    marginInlineStart: "-0.75rem",
    backgroundColor: "transparent",
    borderStyle: "none",
  },
  closeTrigger: {
    insetInlineEnd: spacing._2,
    display: "inline-flex",
    alignItems: "center",
    justifyContent: "center",
    width: "1.5rem",
    height: "1.5rem",
    borderRadius: radii.sm,
    borderStyle: "none",
    color: semanticColors.fgMuted,
    backgroundColor: { default: "transparent", ":hover": semanticColors.bgSubtle },
    cursor: "pointer",
  },
  body: {
    flex: 1,
    minWidth: 0,
  },
});

function typeColorFor(type?: string) {
  return (
    (type === "success" && typeColor.success) ||
    (type === "error" && typeColor.error) ||
    (type === "warning" && typeColor.warning) ||
    (type === "info" && typeColor.info) ||
    undefined
  );
}

const typeColor = stylex.create({
  success: { "--toast-indicated-color": semanticColors.fgSuccess },
  error: { "--toast-indicated-color": semanticColors.fgError },
  warning: { "--toast-indicated-color": semanticColors.fgWarning },
  info: { "--toast-indicated-color": semanticColors.fgInfo },
});

const toastRecipe = defineSlotRecipe({
  slots: {
    root: { styles: toastRoot },
    title: { styles: toastTitle },
    description: { styles: toastDescription },
    indicator: { styles: toastIndicator },
    actionTrigger: { styles: toastActionTrigger },
    closeTrigger: { styles: toastCloseTrigger },
  },
  defaultVariants: {},
});

const { withProvider, withContext } = createSlotRecipeContext(toastRecipe);

function TypeIcon({ type }: { type?: string }) {
  if (type === "success") {
    return (
      <svg width="20" height="20" viewBox="0 0 20 20" fill="none" aria-hidden="true">
        <circle cx="10" cy="10" r="7.5" stroke="currentColor" strokeWidth="1.5" />
        <path d="M7 10.2l2 2 4-4.4" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
      </svg>
    );
  }
  if (type === "error" || type === "warning") {
    return (
      <svg width="20" height="20" viewBox="0 0 20 20" fill="none" aria-hidden="true">
        <circle cx="10" cy="10" r="7.5" stroke="currentColor" strokeWidth="1.5" />
        <path d="M10 6.5v4.2M10 13.4v.1" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
      </svg>
    );
  }
  return (
    <svg width="20" height="20" viewBox="0 0 20 20" fill="none" aria-hidden="true">
      <circle cx="10" cy="10" r="7.5" stroke="currentColor" strokeWidth="1.5" />
      <path d="M10 9.4v4M10 6.6v.1" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
    </svg>
  );
}

function CloseIcon() {
  return (
    <svg width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true">
      <path d="M2.5 2.5l7 7m0-7l-7 7" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
    </svg>
  );
}

/**
 * The default queue, like Ark's `toaster`: call `toaster.success(...)`,
 * `toaster("Saved", { description })` or `toaster.dismiss(id)` from
 * anywhere. `createToaster()` makes another queue for a second region.
 */
export const toaster = createToaster();

/**
 * Toast — UI SDK's real toast queue: mount `<Toaster />` once and call
 * `toaster({ title, description, type })` from anywhere (no provider). The
 * region renders every queued toast through the toast slot recipe with
 * timers, pause on hover/focus, swipe-to-dismiss, Escape, and a11y
 * announcements handled by the engine. Each toast's type shows as
 * `data-type` and tints the indicator.
 */
export const Toast = {
  Viewport: withContext(ToastRegion, () => [chrome.viewport], "ToastViewport"),
  Root: withProvider(
    UiSdkToast,
    () => [...resolveSlotStyles(toastRecipe.slots.root, {}), chrome.root],
    "ToastRoot",
  ),
  Title: withContext(
    ToastTitle,
    () => [...resolveSlotStyles(toastRecipe.slots.title, {}), chrome.title],
    "ToastTitle",
  ),
  Description: withContext(ToastDescription, "description", "ToastDescription"),
  Indicator: withContext("span", "indicator", "ToastIndicator"),
  Action: withContext(
    ToastAction,
    () => [...resolveSlotStyles(toastRecipe.slots.actionTrigger, {}), chrome.actionTrigger],
    "ToastAction",
  ),
  Close: withContext(
    ToastClose,
    () => [...resolveSlotStyles(toastRecipe.slots.closeTrigger, {}), chrome.closeTrigger],
    "ToastClose",
  ),
  createToaster,
};

/**
 * Mount once: the bottom-end region showing `toaster`'s queue (or the
 * queue passed as `toaster`).
 */
export function Toaster({ toaster: queue = toaster }: { toaster?: ToasterQueue<React.ReactNode> }) {
  return (
    <Toast.Viewport toaster={queue} side="bottom" align="end">
      {(item) => (
        <Toast.Root style={typeColorFor(item.type)}>
          <Toast.Indicator>
            <TypeIcon type={item.type} />
          </Toast.Indicator>
          <div {...stylex.props(chrome.body)}>
            <Toast.Title />
            <Toast.Description />
          </div>
          {item.action ? <Toast.Action /> : null}
          <Toast.Close aria-label="Dismiss notification">
            <CloseIcon />
          </Toast.Close>
        </Toast.Root>
      )}
    </Toast.Viewport>
  );
}
Toaster.displayName = "Toaster";
```
