Toasts display brief, non-blocking notifications that appear temporarily above the page content.
Show notification
<divid="toast-basic"><wa-buttonappearance="filled">Show notification</wa-button><wa-toast></wa-toast></div><script>const container = document.getElementById('toast-basic');const toast = container.querySelector('wa-toast');const button = container.querySelector('wa-button');
button.addEventListener('click',()=>{
toast.create('This is a toast notification!');});</script>
Now Available in Web Awesome Core
Toast moved over from Pro in 3.11.0. On an earlier Core version? Upgrade to use it.
Adding a single <wa-toast> element to the page gives you the ability to dispatch notifications at any time. Toast notifications appear in a stack that renders in the top layer, showing above everything else on the page.
You can put the <wa-toast> element anywhere in the DOM, as long as it's somewhere inside the <body>. In most apps, a single toast element is optimal.
Toasts carry unique accessibility challenges. Read the accessibility considerations before using them — thoughtful implementation can mitigate the issues.
Overlapping toasts on this page are intentional, not a bug.
This page has many <wa-toast> elements to show off the component — most apps need only one.
Examples
Link to This Section
Variant
Link to This Section
Set the variant option to brand, success, warning, danger, or neutral to change the type of notification.
Pass an icon option to display an icon at the start of the toast item. You can pass a simple string for the icon name, or an object with additional options like library, family, and variant.
Show notification with icon
<divid="toast-icons"><wa-buttonappearance="filled">Show notification with icon</wa-button><wa-toast></wa-toast></div><script>const container = document.getElementById('toast-icons');const toast = container.querySelector('wa-toast');const button = container.querySelector('wa-button');
button.addEventListener('click',()=>{
toast.create('Your message has been sent successfully!',{variant:'success',icon:'paper-plane',});});</script>
For more control over the icon, pass an object with name and optional library, family, or variant properties.
Duotone iconBrand icon
<divid="toast-icons-advanced"><divclass="wa-cluster wa-gap-xs"><wa-buttonappearance="filled">Duotone icon</wa-button><wa-buttonappearance="filled">Brand icon</wa-button></div><wa-toast></wa-toast></div><script>const container = document.getElementById('toast-icons-advanced');const toast = container.querySelector('wa-toast');const buttons = container.querySelectorAll('wa-button');
buttons[0].addEventListener('click',()=>{
toast.create('This uses a duotone icon!',{variant:'brand',icon:{name:'bell',family:'duotone',variant:'solid',},});});
buttons[1].addEventListener('click',()=>{
toast.create('Follow us on GitHub!',{variant:'neutral',icon:{name:'github',family:'brands',},});});</script>
Duration
Link to This Section
Set the duration option to control how long notifications show before disappearing. The value is in milliseconds and defaults to 5000 (5 seconds). A value of 0 will keep the notification open until the user dismisses it.
3 seconds10 secondsUntil dismissed
<divid="toast-duration"><divclass="wa-cluster wa-gap-xs"><wa-buttonappearance="filled"data-duration="3000">3 seconds</wa-button><wa-buttonappearance="filled"data-duration="10000">10 seconds</wa-button><wa-buttonappearance="filled"data-duration="0">Until dismissed</wa-button></div><wa-toast></wa-toast></div><script>const container = document.getElementById('toast-duration');const toast = container.querySelector('wa-toast');
container.addEventListener('click',event=>{const button = event.target.closest('[data-duration]');if(!button)return;const duration =parseInt(button.getAttribute('data-duration'));
toast.create(duration >0?`This will disappear in ${duration /1000} seconds`:'Dismiss me manually!',{
duration,variant:'brand',});});</script>
Placement
Link to This Section
Use the placement attribute to set the position of the toast stack on the screen.
top-starttop-centertop-endbottom-startbottom-centerbottom-end Show notification
Toast items automatically pause their countdown timer when you hover over them or when the close button receives focus. This gives users more time to read the content before it disappears. When the mouse leaves or focus moves away, the timer resets and starts counting down again.
Show notification (hover to pause)
<divid="toast-pause"><wa-buttonappearance="filled">Show notification (hover to pause)</wa-button><wa-toast></wa-toast></div><script>const container = document.getElementById('toast-pause');const toast = container.querySelector('wa-toast');const button = container.querySelector('wa-button');
button.addEventListener('click',()=>{
toast.create('Hover over me to pause the countdown timer!',{duration:5000,variant:'brand',icon:'clock',});});</script>
Using HTML Content
Link to This Section
Set allowHtml to true to render HTML content in notifications. Make sure you trust the content to avoid XSS vulnerabilities.
Show notification with HTML
<divid="toast-html"><wa-buttonappearance="filled">Show notification with HTML</wa-button><wa-toast></wa-toast></div><script>const container = document.getElementById('toast-html');const toast = container.querySelector('wa-toast');const button = container.querySelector('wa-button');
button.addEventListener('click',()=>{
toast.create(`
<wa-icon slot="icon" name="bell"></wa-icon>
<strong>New message!</strong><br>
You have <em>3 unread messages</em> in your inbox.
`,{allowHtml:true,variant:'brand',duration:0,},);});</script>
Responding to Custom Buttons
Link to This Section
You can add custom buttons or other interactive elements to a toast item using allowHtml. Use the returned toast item reference to query for your elements and attach event listeners.
Show notification with button
<divid="toast-custom-button"><wa-buttonappearance="filled">Show notification with button</wa-button><wa-toast></wa-toast></div><script>const container = document.getElementById('toast-custom-button');const toast = container.querySelector('wa-toast');const showButton = container.querySelector('wa-button');
showButton.addEventListener('click',async()=>{const toastItem =await toast.create(`
<wa-icon slot="icon" name="gift"></wa-icon>
You have a new reward!
<div style="margin-block-start: var(--wa-space-xs);">
<wa-button class="claim-button" variant="brand" size="s">Claim</wa-button>
<wa-button class="dismiss-button" appearance="filled" size="s">No Thanks</wa-button>
</div>
`,{allowHtml:true,variant:'brand',duration:0,},);const claimButton = toastItem.querySelector('.claim-button');const dismissButton = toastItem.querySelector('.dismiss-button');// When the claim button is clicked
claimButton.addEventListener('click',()=>{//// Add custom claim logic here//
toastItem.hide();});// When the dismiss button is clicked
dismissButton.addEventListener('click',()=>{
toastItem.hide();});});</script>
Responding to Events
Link to This Section
The create() method returns a promise that resolves to the generated toast item. You can use this reference to add event listeners.
Show notification
<divid="toast-events"><wa-buttonappearance="filled">Show notification</wa-button><wa-toast></wa-toast></div><script>const container = document.getElementById('toast-events');const toast = container.querySelector('wa-toast');const button = container.querySelector('wa-button');
button.addEventListener('click',async()=>{const toastItem =await toast.create('Click me or let me disappear...',{variant:'brand',icon:'hand-pointer',});
toastItem.addEventListener('click',()=>{
console.log('Toast item was clicked!');});
toastItem.addEventListener('wa-after-hide',()=>{
console.log('Toast item was dismissed');});});</script>
Creating Toast Items Manually
Link to This Section
While toast.create() is the easiest way to show notifications, you can also create <wa-toast-item> elements manually. This approach gives you full control over the toast item's content and is useful when you need to add custom elements or complex layouts.
Toasts have a number of accessibility limitations. For example:
Due to their transient nature, toasts can be missed entirely by screen magnifier users and difficult to perceive for others depending on their visual and cognitive abilities.
Due to their DOM placement and vague position in a page's reading order, toasts can be difficult for keyboard users to navigate to.
Due to their positioning on the page, toasts can obscure other essential elements, especially for users who use browser or OS zooming features.
Rarely will toasts offer the best usability for all of your users, so consider if other UX patterns, like dialogs or inline messages, offer a better experience. If toasts are the right fit for your use case, consider these tips:
Keep toasts short and sweet.
Set the duration to 5000 ms (5 seconds) or longer to give users enough time to locate and understand the toast item.
Consider allowing users to adjust the timing. While the duration of a toast item resets on hover (see Hover & Focus Behavior), a setting in your application can allow users to control the timing of toasts to best suit their needs and abilities.
Choose a consistent placement for toasts in your application and stick with it. Otherwise, users need to guess where transient notifications will appear and risk missing them entirely.
If a transient toast item contains an action, ensure that action is available elsewhere on the page. This ensures that users can still execute the action even if they miss the toast.
API
Link to This Section
Importing
Link to This Section
If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To
cherry-pick a component manually, use one of the following snippets.