Toast
A brief report that something already happened. Covers toast and
toast-region.

dismiss,durationandactionLabelneed Alpine:dismisstakes an expression that removes the toast, and the other two run its timer and its action. Everything else works in a plain Blade view.
Put the region in your layout, once
{{-- resources/views/layouts/app.blade.php --}}
<x-ds::toast-region position="bottom-right" />
Always rendered, and empty most of the time. A live region only announces content that arrives after it is in the document — render the region together with the first toast and the first toast is silent, which is the one a reader most needs to hear.
Then add toasts
<x-ds::toast-region position="bottom-right">
@foreach ($toasts as $toast)
<x-ds::toast :tone="$toast->tone" :title="$toast->title" dismiss="…">
{{ $toast->body }}
</x-ds::toast>
@endforeach
</x-ds::toast-region>
A toast drawn by the server with the page is in the region from the start,
so it is not announced. For one that must be heard, use flash below,
or put it in with Alpine after the page has loaded.
A message flashed to the page load
The usual one: a form posts, the controller redirects back with
->with('status', 'Preferences saved.'), and the next page should say so.
Give the region the message:
{{-- in the layout, once --}}
<x-ds::toast-region :flash="session('status')" />
The toast is put in the region 200 ms after Alpine starts, so the region is already there and announces it, and a screen reader has started on the new page. With no message the region is exactly what it was. It needs Alpine: without it there is no toast, so a message that must not be missed belongs in an alert on the page as well. Both shell blocks do this.
The recipe it stands for, if you need your own markup:
<x-ds::toast-region>
@if (session('status'))
<div x-data="{ shown: false }" x-init="setTimeout(() => shown = true, 200)" class="contents">
<template x-if="shown">
<x-ds::toast tone="success" :duration="5000" dismiss="shown = false">{{ session('status') }}</x-ds::toast>
</template>
</div>
@endif
</x-ds::toast-region>
toast-region props
| Prop | Type | Default | What it does |
|---|---|---|---|
position | bottom-right top-right bottom-center top-center | bottom-right | |
label | string | Notifications | The region's name in a landmark list. |
flash | string | — | A message flashed to this page load, shown as a toast a moment after Alpine starts. See below. |
flashTone | success accent warning danger | success | The flashed toast's tone. |
flashTitle | string | — | Its bold first line. |
flashDuration | ms | 5000 | How long it stays. |
toast props
| Prop | Type | Default | What it does |
|---|---|---|---|
tone | neutral accent success warning danger | neutral | Lives in the icon. Resolved on the server — see below. |
title | string | — | Bold first line. |
icon | string | tone's default | |
dismiss | Alpine expression | — | Renders a close control that runs this. Also run when the toast times out or its action is pressed. |
duration | int (ms) | — | Goes by itself after this long, with a thin bar that empties. Paused on hover, on focus inside and while the page is hidden. At least 5000 when the toast has an action. Dispatches timeout. |
actionLabel | string | — | A built-in action button, "Undo". Dispatches action, then dismisses. |
shortcut | string | — | A key hint beside the action, mod+z, drawn as kbd draws one. A hint only: bind the key yourself. |
Plus an action slot, for an action of your own that you wire yourself.
| Event | When |
|---|---|
action | The actionLabel button was pressed. |
timeout | duration ran out. |
Both bubble from the toast, so listen on it: x-on:action="…", x-on:timeout="…".
A dynamic list of toasts
A toast list is inherently dynamic, which makes this the component where the limitation below bites hardest and is most natural to walk into.
toneresolves to classes on the server. They are chosen when the view renders, so binding it to Alpine state does nothing. See Driving components from client-side state.
{{-- Renders every toast neutral, whatever item.tone says --}}
<template x-for="item in toasts" :key="item.id">
<x-ds::toast ::tone="item.tone" ::title="item.title" />
</template>
::tone sets a tone attribute on the rendered element. Nothing reads it — the
icon and its colour were decided before the browser saw the markup.
If the toasts come from the server, which is the common case, nothing is
wrong: render the region in the response, or from a Livewire component, and each
toast gets its tone the ordinary way. That is the @foreach at the top of this
page.
If the list lives only in the browser, use one <template x-for> per tone
over a filtered list:
<x-ds::toast-region position="bottom-right">
@foreach (['success', 'danger', 'warning', 'neutral'] as $tone)
<template x-for="item in toasts.filter(t => t.tone === '{{ $tone }}')" :key="item.id">
<x-ds::toast tone="{{ $tone }}" ::title="item.title"
dismiss="toasts = toasts.filter(t => t.id !== item.id)" />
</template>
@endforeach
</x-ds::toast-region>
That is correct and it has a real cost: toasts group by tone rather than by arrival order. Four successes and one failure show the failure in tone order, not last. If arrival order matters more than tone — and for a failure it usually does — render the region from the server instead.
Why tone is not a data attribute
The obvious fix is to make the toast take data-tone and drive the icon colour
from CSS, so a single x-for would work. It has not been done, and the reason is
worth writing down rather than rediscovering:
- The tone does not only pick a colour. It picks the icon —
check-circlefor success,exclamation-trianglefor warning — and an icon is markup that CSS cannot swap. A data-attribute toast would still need a bound:nameon the icon, so it would solve half the problem and add a second styling mechanism to the system for it. - It would be the only component styled that way.
badge,alertandsheet-itemhave the same shape, and one exception that behaves differently from its three siblings is worse than a limitation all four share. - CSS driven from a data attribute is invisible to Tailwind's scanner in exactly the way this system spends most of its effort avoiding.
If a tone-per-item toast becomes the common case rather than the occasional one,
the honest answer is a toast-list component that takes an array and renders it
server-side — not a second way to style one toast.
Toast or alert
Anything the reader must act on is not a toast. It is on screen for a few seconds, somewhere their eyes are not, and on a phone it may be under a thumb.
A failure that needs a retry belongs in an alert next to the thing that failed.
Undo: a toast with an action and a countdown
<x-ds::toast icon="archive-box" :duration="8000" actionLabel="Undo" shortcut="mod+z"
dismiss="toasts = toasts.filter(t => t.id !== item.id)"
x-on:action="restore(item.id)"
x-on:timeout="purge(item.id)">
Message archived.
</x-ds::toast>
- The bar along the bottom is the timer. It is a CSS animation, and the toast goes when it ends, so the two never disagree.
- It pauses while the pointer is over the toast, while focus is inside it, and while the tab is in the background: someone moving to press Undo never watches it disappear, and a toast is never used up while nobody can see it.
- With reduced motion the bar is not drawn and the time is the same.
- With an action,
durationis never under 5 seconds (WCAG 2.2.1): "Undo" on a 3-second timer is a button that is gone before the reader has finished the sentence offering it. Give it 8 or more where you can. - Pressing Undo dispatches
actionand then runsdismiss. Running out dispatchestimeoutand then runsdismiss. Withoutdismissthe toast removes its own element; in anx-for, passdismissso Alpine's list is what changes.
The soft delete, in Livewire
Delete for real only on timeout. Until then the record is soft-deleted, so
Undo is a restore, not a re-create:
use Livewire\Component;
class Inbox extends Component
{
/** @var array<int, string> message id => subject, the toasts on screen */
public array $undoable = [];
public function archive(int $id): void
{
$message = auth()->user()->messages()->findOrFail($id);
$message->delete(); // SoftDeletes
$this->undoable[$id] = $message->subject;
}
public function restore(int $id): void
{
auth()->user()->messages()->withTrashed()->findOrFail($id)->restore();
unset($this->undoable[$id]);
}
public function purge(int $id): void
{
auth()->user()->messages()->onlyTrashed()->find($id)?->forceDelete();
unset($this->undoable[$id]);
}
public function forget(int $id): void
{
unset($this->undoable[$id]);
}
}
<x-ds::toast-region>
@foreach ($undoable as $id => $subject)
<x-ds::toast wire:key="undo-{{ $id }}" icon="archive-box" :duration="8000"
actionLabel="Undo"
x-on:action="$wire.restore({{ $id }})"
x-on:timeout="$wire.purge({{ $id }})"
dismiss="$wire.forget({{ $id }})">
“{{ $subject }}” archived.
</x-ds::toast>
@endforeach
</x-ds::toast-region>
dismiss is forget, not purge: it also runs after Undo, and closing the
toast with ✕ is not a decision to delete for good. A row closed that way, or
left behind by a reader who closed the tab, stays soft-deleted, so purge old
soft-deleted rows on a schedule as well (model:prune with
MassPrunable). The toast is the fast path, never the only one.
Reaching Undo from the keyboard
The toast does not take focus when it appears: a reader in the middle of typing must not be pulled away. It is reachable three ways:
- Tab: the action is an ordinary button, in the document where the region is. Put the region near the end of the layout's body so it comes after the page's own controls, and the timer pauses as soon as focus is inside.
- Landmarks: the region is a named landmark ("Notifications"), so a screen reader jumps to it from its landmarks list.
- A shortcut:
shortcut="mod+z"shows the key beside the action. Bind it yourself, for as long as the toast is there:
<div x-data x-on:keydown.window.ctrl.z.prevent="restore(item.id)" x-on:keydown.window.meta.z.prevent="restore(item.id)">…</div>
Timing, without duration
The component holds no timer unless you give it one. What to aim for:
- ~5 seconds for a plain confirmation.
- Longer, or never, when the toast has an action.
- Pause on hover and on focus, or someone moving to click Undo watches it
disappear under the pointer.
durationdoes all three.
Accessibility
The region is aria-live="polite" — never assertive. A toast reports something
that already happened, and interrupting someone to say a thing they just did
worked is exactly the rudeness polite exists to avoid.
Don't
- Don't stack more than about three. Four is a log, and a log belongs on a page.
- Don't put a form in one. It can vanish mid-typing.
- Don't use one for a validation error. The field needs the message.
- Don't put the only copy of an "Undo" behind a timer. Keep a permanent route to the same thing (a Trash folder, a Restore button).
- Don't move focus to a toast when it appears.
- Don't delete for good on
actionor on dismiss. Onlytimeoutmeans the reader let it go.
More in specs/toast.md.
From the package repo: edit this page on GitHub.