Toast
A short message in the bottom end corner of the screen.
Single toast
Make the toast a manual popover, so it stays until it is closed. A button with
popovertarget opens it, and a .close button inside
dismisses it. From a script, call showPopover() and
hidePopover().
Your changes were saved.
Colors
A color class sets the color. Without one the toast uses the contrast color.
Link copied.
The upload failed.
Stacked toasts
To show several at once, add and remove .toast elements inside a
.toasts live region. Screen readers announce each new toast.
<div class="toasts" aria-live="polite"></div>
<script>
function toast(message, color = "") {
const item = document.createElement("div");
item.className = `toast ${color}`;
item.textContent = message;
document.querySelector(".toasts").append(item);
setTimeout(() => item.remove(), 4000);
}
toast("Saved", "success");
</script>
Variables
| Variable | Default |
|---|---|
--i-toast-max-width | 24rem |
--i-toast-offsetDistance from the edges of the viewport | var(--i-spacing) |
--i-toast-gap | calc(var(--i-spacing) * 0.5) |
--i-toast-padding-block | calc(var(--i-spacing) * 0.75) |
--i-toast-padding-inline | var(--i-spacing) |
--i-toast-duration | 0.3s |
--i-toast-z-index | 1000 |