---
title: "Toast"
description: "Toast component - ephemeral notifications using popover API."
slug: "toast"
---

import { DocPage, PageHeader, SkillPanel, Example, ExampleLabel, ExampleHint, ExampleCode, SourceFiles, SourceNote, StatesSection, CodeBlock, Demo, DemoCode, ChangelogEntries, ArchBody, StatsClaim, StatsCards, PageOverlay, DocText, DocLink, H2, SkillField, SkillText, SkillRow, SkillGrid, Variant, ApiPill, Dim, CodeCard, TableCard, ApiSection } from "../../lib/components/index";

<DocPage meta={meta}>

<PageHeader slug="toast" title="Toast" component="toast">
  Transient notification using <code>popover="manual"</code>. Imperative <code>\df$.shadcn.toast.show()</code> API with auto-dismiss, stacking, destructive variant, and action buttons.
</PageHeader>

<SkillPanel component="toast">
  <SkillField label="Native basis">
<SkillText><code>popover</code> API for top-layer rendering and non-modal behavior.</SkillText>
  </SkillField>

  <SkillField label="Web Platform APIs">
<SkillRow>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/API/Popover_API" title="top-layer rendering without light-dismiss for persistent notifications"><code>Popover API (popover="manual")</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-live" title="announces toast content changes to screen readers"><code>aria-live regions</code></ApiPill>
  </SkillRow>
  </SkillField>

  <SkillField label="Classes">
<SkillRow>
    <code>.toast-container</code>
    <code>.toast</code>
    <code>.toast-description</code>
    <code>.toast-icon</code>
    <code>.toast-content</code>
    <code>.toast-text</code>
    <code>.toast-title</code>
    <code>.toast-close</code>
    <code>.toast-actions</code>
  </SkillRow>
  </SkillField>

  <SkillField label="Variants (data-variant)">
<SkillGrid>
    <Variant name="destructive" description="Alternate background styling" />
    <Variant name="success" description="Color variation" />
    <Variant name="warning" description="Color variation" />
    <Variant name="info" description="Color variation" />
  </SkillGrid>
  </SkillField>

  <SkillField label="Data attributes">
<SkillText dense>• <code>data-position</code> - values: <code>bottom-right</code>, <code>bottom-left</code>, <code>top-right</code>, <code>top-left</code>, <code>top-center</code>, <code>bottom-center</code></SkillText>
  <SkillText dense>• <code>data-toast-close</code></SkillText>
  <SkillText>• <code>data-toast-action</code></SkillText>
  </SkillField>

  <SkillField label="Wiring conventions">
<SkillText dense>• <code>data-toast-close</code> on any element inside - closes the component</SkillText>
  <SkillText>• <code>data-toast-action</code> identifies an interactive action element</SkillText>
  </SkillField>

  <SkillField label="Notes">
<SkillText dense>• The toast container should be a direct child of <code>&lt;body&gt;</code></SkillText>
  <SkillText dense>• Toasts use <code>popover="manual"</code> so they don't auto-dismiss on outside click</SkillText>
  <SkillText dense>• The stacking order is newest on top (CSS <code>flex-direction: column-reverse</code> for bottom positions)</SkillText>
  <SkillText dense>• Maximum visible toasts defaults to 3 - older toasts are dismissed</SkillText>
  <SkillText dense>• Swipe-to-dismiss can be added with touch event handling but is not required for MVP</SkillText>
  <SkillText dense>• For forms, show success/error toasts after submission rather than inline messages</SkillText>
  <p class="text-muted-foreground m-0">• The <code>toast()</code> API is imperative - call it from any event handler</p>
  </SkillField>
</SkillPanel>

```html example label="Default" hint="Basic toast with title and description via df$.shadcn.toast.show()." height="20"
<button
  class="btn"
  data-variant="default"
  onclick="df$.shadcn.toast.show({ title: 'Event created', description: 'Monday, January 3rd at 6:00pm' })"
>
  Show Toast
</button>
```

```html example label="Variants" hint="Semantic variants add a colored border and icon. Use df$.shadcn.toast.success(), df$.shadcn.toast.warning(), df$.shadcn.toast.info(), or df$.shadcn.toast.error()." height="20"
<button
  class="btn"
  data-variant="outline"
  onclick="df$.shadcn.toast.success({ title: 'Success', description: 'Your changes have been saved.' })"
>
  Success
</button>
<button
  class="btn"
  data-variant="outline"
  onclick="df$.shadcn.toast.warning({ title: 'Warning', description: 'Your session will expire in 5 minutes.' })"
>
  Warning
</button>
<button
  class="btn"
  data-variant="outline"
  onclick="df$.shadcn.toast.info({ title: 'Info', description: 'A new version is available for download.' })"
>
  Info
</button>
<button
  class="btn"
  data-variant="destructive"
  onclick="df$.shadcn.toast.error({ title: 'Error', description: 'Something went wrong. Please try again.' })"
>
  Error
</button>
```

```html example label="With Description" hint="Pass a description for a secondary line of detail below the title." height="20"
<button
  class="btn"
  data-variant="outline"
  onclick="
    df$.shadcn.toast.show({ title: 'Scheduled', description: 'Your report will be generated at 9:00 AM tomorrow.' })
  "
>
  Show Toast
</button>
```

```html example label="With Action" hint="Add an action object with label and onClick to render an action button inside the toast." height="20"
<button
  class="btn"
  data-variant="outline"
  onclick="
    df$.shadcn.toast.show({
      title: 'Changes saved',
      description: 'Your profile has been updated.',
      action: { label: 'Undo', onClick: () => df$.shadcn.toast.show('Undone!') },
    })
  "
>
  Show Toast
</button>
```

```html example label="Stacked toasts" hint="configure({ stack: 'pile' }): the newest toast stays in front and the older ones wait behind it as the Stacks sheets (shapes.css stack-top - tapered sheets) with a +n badge; hover or focus the pile and it fans out into a list, leave it and it folds back. Send a few - then switch to a list for comparison." height="30"
<div class="flex flex-wrap gap-2">
  <button class="btn" id="pile-send">Send 3 notifications</button>
  <button class="btn" data-variant="outline" id="pile-mode" aria-pressed="true">Mode: pile</button>
</div>
<script>
  // the toast module is a deferred module script - wait until it has run
  addEventListener('DOMContentLoaded', () => {
    const t = df$.shadcn.toast;
    t.configure({ stack: 'pile', position: 'bottom-right' });
    const news = [
      { title: 'Build passed', description: 'main · 2m 14s', variant: 'success' },
      { title: 'New comment', description: 'Sofia replied to your review.' },
      { title: 'Deploy queued', description: 'production · waiting for approval', variant: 'info' },
      { title: 'Invoice paid', description: 'INV-2291 · €1,200.00', variant: 'success' },
    ];
    let n = 0;
    document.getElementById('pile-send').addEventListener('click', () => {
      for (let i = 0; i < 3; i++) setTimeout(() => t.show({ ...news[n++ % news.length], duration: 12000 }), i * 350);
    });
    const mode = document.getElementById('pile-mode');
    mode.addEventListener('click', () => {
      const pile = mode.getAttribute('aria-pressed') !== 'true';
      t.configure({ stack: pile ? 'pile' : 'list' });
      mode.setAttribute('aria-pressed', String(pile));
      mode.textContent = 'Mode: ' + (pile ? 'pile' : 'list');
    });
  });
</script>
```

```html example label="Animations" hint="animation: { in, out, direction } plays any df$.anim pair on the toast - slide from the edge it lives at, pop, flip, blur, zoom, wipe. Dismiss (× or the timer) runs the exit." height="26"
<div class="flex flex-wrap gap-2">
  <button
    class="btn"
    data-variant="outline"
    onclick="
      df$.shadcn.toast.show({
        title: 'Slide in',
        description: 'From the east edge, out the same way.',
        animation: { in: 'slideIn', out: 'slideOut', direction: 'east' },
      })
    "
    >Slide</button
  >
  <button
    class="btn"
    data-variant="outline"
    onclick="
      df$.shadcn.toast.success({
        title: 'Pop',
        description: 'A springy scale-in.',
        animation: { in: 'popIn', out: 'popOut' },
      })
    "
    >Pop</button
  >
  <button
    class="btn"
    data-variant="outline"
    onclick="
      df$.shadcn.toast.info({
        title: 'Flip',
        description: 'Turns in on its axis.',
        animation: { in: 'flipIn', out: 'flipOut' },
      })
    "
    >Flip</button
  >
  <button
    class="btn"
    data-variant="outline"
    onclick="
      df$.shadcn.toast.show({
        title: 'Blur',
        description: 'Comes into focus.',
        animation: { in: 'blurIn', out: 'blurOut' },
      })
    "
    >Blur</button
  >
  <button
    class="btn"
    data-variant="outline"
    onclick="
      df$.shadcn.toast.warning({
        title: 'Zoom',
        description: 'Grows from the corner.',
        animation: { in: 'zoomIn', out: 'zoomOut' },
      })
    "
    >Zoom</button
  >
  <button
    class="btn"
    data-variant="outline"
    onclick="
      df$.shadcn.toast.show({
        title: 'Wipe',
        description: 'Revealed edge to edge.',
        animation: { in: 'wipeIn', out: 'wipeOut', direction: 'west' },
      })
    "
    >Wipe</button
  >
</div>
```

```html example label="Aura" hint="aura: true (or a style: 'rainbow', 'gold', 'holo', 'dual') turns the toast into a ring of animated light (shapes.css .aura) - for the one notification that must not be missed." height="26"
<div class="flex flex-wrap gap-2">
  <button
    class="btn"
    onclick="
      df$.shadcn.toast.show({
        title: 'You are live',
        description: 'Your stream started - 128 viewers.',
        aura: true,
        animation: { in: 'popIn', out: 'fadeOut' },
      })
    "
    >Aura</button
  >
  <button
    class="btn"
    data-variant="outline"
    onclick="
      df$.shadcn.toast.success({
        title: 'Achievement unlocked',
        description: '100 deploys without a rollback.',
        aura: 'rainbow',
        animation: { in: 'zoomIn', out: 'zoomOut' },
      })
    "
    >Rainbow</button
  >
  <button
    class="btn"
    data-variant="outline"
    onclick="df$.shadcn.toast.show({ title: 'Welcome to Pro', description: 'Your upgrade is active.', aura: 'gold' })"
    >Gold</button
  >
</div>
```

```html example label="Size & Density" hint="size scales the width envelope (sm / md / lg, md matches the unsized default), density the padding and content gap (compact / comfortable / spacious) - pass either option to show() and it lands as the matching data-* attribute on the toast." height="20"
<div class="flex flex-wrap gap-2">
  <button
    class="btn"
    data-variant="outline"
    onclick="df$.shadcn.toast.show({ title: 'Narrow toast', description: 'Width envelope sm.', size: 'sm' })"
    >Size sm</button
  >
  <button
    class="btn"
    data-variant="outline"
    onclick="df$.shadcn.toast.show({ title: 'Wide toast', description: 'Width envelope lg.', size: 'lg' })"
    >Size lg</button
  >
  <button
    class="btn"
    data-variant="outline"
    onclick="
      df$.shadcn.toast.show({ title: 'Compact toast', description: 'Tighter padding and gap.', density: 'compact' })
    "
    >Density compact</button
  >
  <button
    class="btn"
    data-variant="outline"
    onclick="
      df$.shadcn.toast.show({ title: 'Spacious toast', description: 'Roomier padding and gap.', density: 'spacious' })
    "
    >Density spacious</button
  >
</div>
```

<StatesSection>
  <p class="text-sm text-muted-foreground m-0 mb-3">The named-state API is bound to the region container (<code>#toast-container</code>):</p>
  <ul class="text-sm text-muted-foreground m-0 mb-3 ps-5">
    <li><code>default</code> - no visible toasts: <code>setState('default')</code> dismisses everything (the same path as <code>window.\df$.shadcn.toast.dismiss()</code>); <code>getState().config.count</code> reports the live number of visible toasts</li>
  </ul>
  <p class="text-sm text-muted-foreground">The region element carries <code>data-state-demo</code>; <code>bun run screenshots</code> drives it via <code>el.api.setState(name)</code>.</p>

Machine contract - verified against <a class="link" href="../schemas/toast.schema.json"><code>toast.schema.json</code></a> by <code>bun run verify</code>:


```states
| State | Type | Values | Default | Description |
| --- | --- | --- | --- | --- |
```

</StatesSection>

<ApiSection component="toast" />

<SourceFiles component="toast" section="css" />

<SourceFiles component="toast" section="js">
  <SourceNote for="js">Imperative <code>\df$.shadcn.toast.show()</code> API with auto-dismiss, stacking (max 3 visible), variant icons, and action buttons. Container is auto-created if not present in the DOM.</SourceNote>
</SourceFiles>

</DocPage>
