Toasts
Transient notifications anchored to the viewport.
Setup
Toast styles are included in Manifest CSS or a standalone stylesheet, both referencing theme variables.
Toast functionality is included in manifest.js with all core plugins, or it can be selectively loaded.
<!-- Manifest CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/mnfst@latest/lib/manifest.min.css" />
<!-- Manifest JS -->
<script src="https://cdn.jsdelivr.net/npm/mnfst@latest/lib/manifest.min.js"></script>
Default
Toasts can be triggered from any element using the x-toast directive, with its value being the content. They automatically disappear after 3 seconds, though the timer will pause on hover. Toasts will stack if multiple are triggered concurrently.
<button x-toast="This is a basic toast notification">Show Toast</button>
Modifiers
Colors
Color modifiers provide unique visual context.
<button x-toast="Default toast notification">Default</button>
<button x-toast.brand="Brand toast notification">Brand</button>
<button x-toast.accent="Accent toast notification">Accent</button>
<button x-toast.positive="Operation completed successfully">Positive</button>
<button x-toast.negative="Something went wrong">Negative</button>
Duration
A number sets how long the toast remains visible in milliseconds. The long modifier doubles the default to 6 seconds.
<button x-toast.1000="Dismisses after 1 second">1 Second</button>
<button x-toast="Default 3 seconds">Default</button>
<button x-toast.5000="Dismisses after 5 seconds">5 Seconds</button>
<button x-toast.long="Dismisses after 6 seconds">Long</button>
Dismiss
The dismiss modifier enables manual closing.
<button x-toast.dismiss="Can be manually dismissed">Dismissible</button>
<button x-toast.positive.dismiss="Positive with dismiss button">Positive Dismissible</button>
<button x-toast.negative.dismiss="Negative with dismiss button">Negative Dismissible</button>
Fixed
The fixed modifier prevents the default auto-dismiss behavior and adds the dismiss button by default.
<button x-toast.fixed="Stays until manually closed">Fixed</button>
<button x-toast.positive.fixed="Fixed positive notification">Fixed Positive</button>
<button x-toast.negative.fixed="Fixed negative notification">Fixed Negative</button>
Combined
Combine different modifiers for complex toast behaviors.
<button x-toast.negative.dismiss.2000="Negative toast with 2s duration and dismiss button">Negative + Dismiss + 2s</button>
<button x-toast.positive.fixed="Positive toast that stays until dismissed">Positive + Fixed</button>
Magic Method
Use the $toast magic method for programmatic toast creation. Messages show as plain text; pass { html: true } to render your own markup, as in $toast('Saved <b>draft</b>', { html: true }).
<button @click="$toast('Programmatic toast')">Basic Magic</button>
<button @click="$toast.brand('Brand via magic method')">Brand Magic</button>
<button @click="$toast.positive('Positive via magic method')">Positive Magic</button>
<button @click="$toast.negative('Negative via magic method')">Negative Magic</button>
<button @click="$toast.negative.fixed('Fixed negative toast')">Fixed Negative Magic</button>
Each method takes an options object as its second argument.
| Option | Default | Purpose |
|---|---|---|
duration |
3000 |
Milliseconds before the toast closes |
dismissible |
false |
Adds a dismiss button |
fixed |
false |
Stays until dismissed, with a dismiss button |
icon |
none | Icon name shown before the message |
html |
false |
Renders the message as HTML |
<button @click="$toast.positive('Saved', { duration: 5000, icon: 'lucide:check' })">Save</button>
Rich Content
Markup written directly in x-toast renders as HTML, including icons.
<button x-toast.fixed="<span x-icon='lucide:info'></span>Hello <b>bold</b> and <em>italic</em> world">Rich Content</button>
Dynamic Expressions
Toast content can be any Alpine.js expression, evaluated each time the toast is triggered. Plain text that isn't an expression, like Hello world or Don't save, displays exactly as written.
<button x-data="{ count: 0 }" @click="count++; $toast(`Button clicked ${count} times`)">
Dynamic Count (<span x-text="count"></span>)
</button>
<button x-toast="`Current time: ${new Date().toLocaleTimeString()}`">
Current Time
</button>
<button x-data="{ pending: ['Draft', 'Review'] }" x-toast="pending.length ? 'Pending: ' + pending.join(', ') : 'Nothing pending'">
Pending
</button>
A single word displays as text unless it names a value in scope, so x-toast="count" shows the current count while x-toast="Saved" shows Saved. Loop variables from x-for work the same way, as in x-toast="item.message". Expressions read state after the element's click handlers run, so give x-for rows a :key when a click reorders or removes items. An expression that resolves to an empty string, false, or null shows no toast.
Expression results show as plain text, so values from users or data sources can't inject markup. Add the .html modifier to render a result you control as HTML, as in x-toast.html="draft.summary".
Data Sources
Toasts can retrieve content from data sources using the $x syntax.
<button x-toast="$x.example.toast">Data Source Toast</button>
Styles
Theme
Default toasts use the following theme variables:
| Variable | Purpose |
|---|---|
--color-popover-surface |
Default toast background color |
--color-line |
Default toast border color |
--color-field-surface |
Colored toast background (brand, positive, etc.) |
--color-field-inverse |
Colored toast text and dismiss icon color |
--shadow-lg |
Toast shadow |
--spacing |
Base spacing unit for gaps and padding |
--radius |
Border radius for toast corners (doubled) |
Dismiss Button Icon
The dismiss button icon is an encoded SVG in the --icon-dismiss variable, which is shared with the remove buttons in forms. Overriding it on :root changes both; set it on .toast to change toasts only. To modify it:
- Choose a desired icon from Iconify or other SVG icon source.
- Copy the encoded SVG string (in Iconify, go to an icon's CSS tab and find the
--svgvalue). Otherwise, use an SVG encoder. - Overwrite the
--icon-dismissvariable value with the encoded SVG string.
Default toast dismiss icon :root {
--icon-dismiss: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M18 6L6 18M6 6l12 12'/%3E%3C/svg%3E")
}
Customization
Modify styles with custom CSS for various toast classes.
/* Parent wrapper for multiple toasts */
.toast-container {
top: 3rem;
bottom: auto;
left: auto;
right: 3rem;
transform: none;
flex-direction: column;
}
/* Toast */
.toast {
background: var(--color-surface-1);
/* Content area */
.toast-content {
font-size: 1rem;
}
/* Dismiss button */
.toast-dismiss-button {
opacity: 0.6;
}
}
/* Entry animation */
.toast-entry {
opacity: 1;
}
/* Exit animation */
.toast-exit {
opacity: 0;
}
Article does not exist
There is no documentation at this path.