Toast <l-toast>
Toasts are used to display brief, non-blocking notifications that auto-dismiss. Commonly used to confirm actions, report errors, or surface system messages without interrupting the user's workflow.
<l-toast>Options
Basic
Place a single <l-toast> element anywhere inside the <body>. Call toast() to display notifications.
Code
<button
class="l-button"
onclick="toast({ text: 'This is a toast notification!' })"
>
Show notification
</button>Variants
Pass variant in the options to apply accent colors: info, success, warning, danger.
Code
<div class="flex gap-2 flex-wrap">
<button
class="l-button"
onclick="toast({ text: 'Neutral message' })"
>
Neutral
</button>
<button
class="l-button"
onclick="toast({ text: 'Informational message', variant: 'info' })"
>
Info
</button>
<button
class="l-button"
onclick="toast({ text: 'Operation successful!', variant: 'success' })"
>
Success
</button>
<button
class="l-button"
onclick="toast({ text: 'Please be careful', variant: 'warning' })"
>
Warning
</button>
<button
class="l-button"
onclick="toast({ text: 'Something went wrong', variant: 'danger' })"
>
Danger
</button>
</div>Heading
Pass heading in the options to display a title above the message.
Code
<div class="flex gap-2 flex-wrap">
<button
class="l-button"
onclick="
toast({
text: 'Your changes have been saved.',
heading: 'Saved',
variant: 'success',
timer: true,
})
"
>
Success
</button>
<button
class="l-button"
onclick="
toast({
text: 'This action cannot be undone.',
heading: 'Warning',
variant: 'warning',
timer: true,
})
"
>
Warning
</button>
<button
class="l-button"
onclick="
toast({ text: 'Please try again later.', heading: 'Error', variant: 'danger', timer: true })
"
>
Error
</button>
</div>Icon
Pass icon with an Iconify icon name to replace the accent bar with an icon, colored by variant.
Code
<div class="flex gap-2 flex-wrap">
<button
class="l-button"
onclick="
toast({
text: 'Informational message',
heading: 'Info',
variant: 'info',
icon: 'lucide:info',
})
"
>
Info
</button>
<button
class="l-button"
onclick="
toast({
text: 'Operation successful!',
heading: 'Success',
variant: 'success',
icon: 'lucide:circle-check',
})
"
>
Success
</button>
<button
class="l-button"
onclick="
toast({
text: 'Please be careful',
heading: 'Warning',
variant: 'warning',
icon: 'lucide:triangle-alert',
})
"
>
Warning
</button>
<button
class="l-button"
onclick="
toast({
text: 'Something went wrong',
heading: 'Error',
variant: 'danger',
icon: 'lucide:circle-x',
})
"
>
Danger
</button>
</div>Duration
Control how long the toast stays visible. Set to 0 for persistent notifications that must be manually dismissed.
Code
<div class="flex gap-2 flex-wrap">
<button
class="l-button"
onclick="toast({ text: 'Closes in 3 seconds', duration: 3000 })"
>
3s
</button>
<button
class="l-button"
onclick="toast({ text: 'Closes in 10 seconds', duration: 10000 })"
>
10s
</button>
<button
class="l-button"
onclick="toast({ text: 'Stays until dismissed', duration: 0 })"
>
Persistent
</button>
<button
class="l-button"
onclick="toast({ text: 'With countdown bar', duration: 5000, timer: true })"
>
With timer
</button>
</div>Placement
Position the toast stack using the placement attribute.
Code
<div class="flex gap-2 flex-wrap">
<button
class="l-button"
onclick="
document.querySelector('l-toast').placement = 'top-start';
toast({ text: 'Top start' });
"
>
Top start
</button>
<button
class="l-button"
onclick="
document.querySelector('l-toast').placement = 'top-center';
toast({ text: 'Top center' });
"
>
Top center
</button>
<button
class="l-button"
onclick="
document.querySelector('l-toast').placement = 'top-end';
toast({ text: 'Top end' });
"
>
Top end
</button>
<button
class="l-button"
onclick="
document.querySelector('l-toast').placement = 'bottom-start';
toast({ text: 'Bottom start' });
"
>
Bottom start
</button>
<button
class="l-button"
onclick="
document.querySelector('l-toast').placement = 'bottom-center';
toast({ text: 'Bottom center' });
"
>
Bottom center
</button>
<button
class="l-button"
onclick="
document.querySelector('l-toast').placement = 'bottom-end';
toast({ text: 'Bottom end' });
"
>
Bottom end
</button>
</div>Programmatic API
import { toast } from 'luxen-ui/toast';
// Basic
toast({ text: 'Saved successfully!' });
// With variant
toast({ text: 'File uploaded', variant: 'success' });
// With heading and custom duration
toast({
text: 'Undo this action?',
heading: 'Warning',
variant: 'warning',
duration: 0,
});Features
- Function-based API — call
toast({ text: '...' })from anywhere, no component wiring needed - Timer pausing on hover & focus — countdown pauses when hovered or focused, resumes when the pointer or focus leaves
- Timer pausing on hidden tab — countdown pauses when the browser tab loses visibility, resumes with the remaining time when the user returns
- Swipe to dismiss — drag a toast horizontally to dismiss it; works with mouse, touch, and pen input
@starting-styleenter animations — smooth CSS entry transitions using the@starting-styleat-rule- Keyboard dismiss — press Escape to dismiss the most recent toast
- FLIP reorder animations — remaining toasts animate smoothly into their new positions when one is dismissed
Accessibility
Criteria
- Live region
Container uses
role="log"witharia-live="polite"for screen reader announcementsWCAG4.1.3RGAA7.5- Role
Items use
role="status"(role="alert"fordangervariant)WCAG4.1.2- Decorative elements
Icons, accent bar, and timer bar are hidden with
aria-hidden="true"WCAG1.1.1RGAA1.1- Timer pausing
Timer pauses on hover and focus, providing keyboard parity
WCAG2.2.1- Motion
Respects
prefers-reduced-motionWCAG2.3.3
Keyboard interactions
API reference
Importing
// Side-effect import (registers <l-toast> element)
import 'luxen-ui/toast';
// Or import the standalone function (auto-creates <l-toast>)
import { toast } from 'luxen-ui/toast';
toast({ text: 'Hello!' });@import 'luxen-ui/css/toast';
@import 'luxen-ui/css/close-button';Attributes & Properties
placementAttribute- Position of the toast stack:
top-start,top-center,top-end(default),bottom-start,bottom-center,bottom-end durationAttribute- Default auto-dismiss delay in ms. Default
5000. Set to0orInfinityto keep open until dismissed variantAttribute- Default variant for toast items:
info,success,warning,danger
Methods
toast()Method- Creates and shows a toast notification
ToastOptions
textProperty- The message text to display. Required unless
htmlis provided htmlProperty- HTML content for the message, sanitized via the Sanitizer API. Ignored if
textis provided headingProperty- Heading text displayed above the message
iconProperty- Iconify icon name (e.g.
lucide:check). Replaces the accent bar, colored by variant variantProperty- Override variant for this toast
durationProperty- Override auto-dismiss delay in ms.
0orInfinityto keep open until dismissed timerProperty- Show a countdown progress bar at the bottom
Events
l-showEvent- Emitted when a toast begins to show. Cancelable
l-after-showEvent- Emitted after the show animation completes
l-hideEvent- Emitted when a toast begins to hide. Cancelable
l-after-hideEvent- Emitted after the hide animation completes and toast is removed
CSS classes
l-toast-itemClass- Toast item custom element (generated internally)
.l-toast-accentClass- Left accent bar, colored by variant
.l-toast-contentClass- Content area
.l-toast-headingClass- Heading text
.l-toast-messageClass- Message text
.l-toast-timerClass- Countdown progress bar (auto-added for timed toasts)
CSS custom properties
--gapProperty- Gap between stacked items. Default
0.5rem --widthProperty- Width of the toast stack. Default
28rem --show-durationProperty- Show animation duration. Default
200ms --hide-durationProperty- Hide animation duration. Default
200ms