Welcome to Vanilla Breeze
This bell pulls live notifications from /go/notify/messages — the same contract documented at /docs/concepts/service-contracts/. Static articles like this one are the no-JS / no-backend fallback.
This bell pulls live notifications from /go/notify/messages — the same contract documented at /docs/concepts/service-contracts/. Static articles like this one are the no-JS / no-backend fallback.
Toast patterns for non-blocking notifications with variants, positions, and JavaScript API.
The toast component uses the <toast-msg> web component to display non-blocking notifications. Toasts require JavaScript to show dynamically but provide a clean API for common use cases like form feedback and status updates.
Key features:
Click the buttons to see different toast variants in action.
Place a single toast container in your page, typically at the body level.
<!-- Place once in your page --><toast-msg id="notifications" position="top-end"></toast-msg>
Use the show() method to display toasts programmatically.
const toast = document.getElementById('notifications'); // Basic toasttoast.show({ message: 'This is a toast notification!', variant: 'info'}); // Success with custom durationtoast.show({ message: 'Settings saved successfully.', variant: 'success', duration: 3000 // Auto-dismiss after 3 seconds}); // Error with manual dismisstoast.show({ message: 'Failed to save changes. Please try again.', variant: 'error', duration: 0 // Must be manually dismissed});
async function handleSubmit(event) { event.preventDefault(); const toast = document.getElementById('notifications'); try { await submitForm(event.target); toast.show({ message: 'Form submitted successfully!', variant: 'success' }); } catch (error) { toast.show({ message: `Error: ${error.message}`, variant: 'error', duration: 0 }); }}
async function copyToClipboard(text) { const toast = document.getElementById('notifications'); try { await navigator.clipboard.writeText(text); toast.show({ message: 'Copied to clipboard!', variant: 'success', duration: 2000 }); } catch (error) { toast.show({ message: 'Failed to copy', variant: 'error' }); }}
window.addEventListener('online', () => { document.getElementById('notifications').show({ message: 'Connection restored', variant: 'success' });}); window.addEventListener('offline', () => { document.getElementById('notifications').show({ message: 'You are offline', variant: 'warning', duration: 0 });});
The <toast-msg> element accepts these attributes:
| Attribute | Values | Description |
|---|---|---|
position |
top-start top-center top-endbottom-start bottom-center bottom-end |
Screen position for toasts. Default is top-end. |
The show() method accepts an options object:
| Property | Type | Description |
|---|---|---|
message |
String | The notification text to display. |
variant |
info success warning error |
Visual style and semantic meaning. |
duration |
Number | Auto-dismiss time in ms. Default 5000. Use 0 for manual dismiss. |
top-end for most applications (top-right in LTR)Web component documentation
Blocking dialog patterns