Skip to content

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.

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

VariableDefault
--i-toast-max-width24rem
--i-toast-offsetDistance from the edges of the viewportvar(--i-spacing)
--i-toast-gapcalc(var(--i-spacing) * 0.5)
--i-toast-padding-blockcalc(var(--i-spacing) * 0.75)
--i-toast-padding-inlinevar(--i-spacing)
--i-toast-duration0.3s
--i-toast-z-index1000