Skip to Content
Component ExamplesToast Notifications

Overview

Toast notifications (also called snackbars) are brief, transient messages that appear temporarily to confirm an action or report status. They pose significant accessibility risks: screen reader users may never hear them if the toast has no ARIA live region, and auto-dismissing toasts that contain actions violate WCAG 2.2.1 if that action is not available through another path. The key rule — identical to live regions — is that the toast container element must exist in the DOM before content is injected into it.

WCAG Criteria:

Key requirements:

  • Use role="status" for most toasts (success, info, confirmations)
  • Use role="alert" only for urgent errors — overuse desensitizes users
  • The toast container must exist in the DOM before content is injected
  • Auto-dismissing toasts with actions are WCAG 2.2.1 failures if the action is unavailable elsewhere
  • If a toast has an action button, that action must be available through another path (e.g., an undo in a toolbar)
  • Include a dismiss button so users can clear the toast on their own terms

Status Toast

Silent Visual Toast vs. Announced Status Toast

Inaccessible
<!-- No ARIA — screen reader never announces the toast --> <button onclick=" var toast = document.getElementById('toast'); toast.style.display = 'flex'; setTimeout(function() { toast.style.display = 'none'; }, 3000); "> Save </button> <!-- Toast appears visually but is invisible to assistive technology --> <div id="toast" style=" display: none; position: fixed; bottom: 16px; right: 16px; "> Saved! </div>
Live Preview
Accessible
<button onclick=" var msg = document.getElementById('toast-msg'); msg.textContent = 'Saved successfully'; container.style.display = 'flex'; "> Save </button> <!-- Container exists in DOM on load — role="status" announces politely --> <div id="toast-container" style="position: fixed; bottom: 16px; right: 16px;"> <span id="toast-msg" role="status"></span> <button aria-label="Dismiss notification" onclick=" container.style.display = 'none'; msg.textContent = ''; "> &times; </button> </div>
Live Preview

What’s wrong with the silent visual toast?

  • No role="status" or aria-live attribute — the toast is completely invisible to screen readers
  • The text “Saved!” appears and disappears without any programmatic announcement
  • A screen reader user who clicked “Save” has no confirmation that the action succeeded
  • Auto-dismiss after 3 seconds gives no time for a screen reader to catch it even if it were announced

What the screen reader announces:

VersionAnnouncement after clicking Save
Inaccessible (no ARIA)Nothing — screen reader stays silent
Accessible (role=“status”)“Saved successfully” — announced politely after current speech

Why the dismiss button matters:

  • Users with cognitive disabilities may need more time to read the message
  • Screen magnifier users may not see the toast before it auto-dismisses
  • The dismiss button puts the user in control of when the toast disappears

Error Toast

Overused Alert Toasts vs. Targeted Error Toast

Inaccessible
<!-- Every action creates a new role="alert" element — overuse and dynamic creation --> <button onclick=" var toast = document.createElement('div'); toast.setAttribute('role', 'alert'); toast.textContent = 'Copied to clipboard'; document.body.appendChild(toast); setTimeout(function() { toast.remove(); }, 2000); ">Copy</button> <button onclick=" var toast = document.createElement('div'); toast.setAttribute('role', 'alert'); toast.textContent = 'Added to favorites'; document.body.appendChild(toast); setTimeout(function() { toast.remove(); }, 2000); ">Favorite</button> <button onclick=" var toast = document.createElement('div'); toast.setAttribute('role', 'alert'); toast.textContent = 'Failed to save'; document.body.appendChild(toast); setTimeout(function() { toast.remove(); }, 2000); ">Save</button>
Live Preview

Every action fires role="alert" — even non-errors. Dynamically created elements may not be announced.

Accessible
<!-- Pre-existing containers — role="alert" reserved for true errors --> <div id="error-toast" role="alert"></div> <div id="status-toast" role="status"></div> <button onclick=" statusToast.textContent = 'Copied to clipboard'; ">Copy</button> <button onclick=" statusToast.textContent = 'Added to favorites'; ">Favorite</button> <!-- Only genuine errors use role="alert" --> <button onclick=" errorToast.innerHTML = 'Failed to save &mdash; please try again ' + '<button>Retry</button>'; ">Save</button>
Live Preview

What’s wrong with overusing role="alert"?

  • Using role="alert" for every action (including success messages like “Copied”) desensitizes users — assertive announcements interrupt whatever the screen reader is currently saying
  • Dynamically creating an element with role="alert" and appending it to the DOM is unreliable — many screen readers do not pick up the live region property on newly created elements
  • Non-error messages should use role="status" (polite) so they queue after the current announcement

What the screen reader announces:

VersionAnnouncement
Overused alert (on Copy)May interrupt with “alert: Copied to clipboard” — or may announce nothing if dynamically created
Targeted roles (on Copy)“Copied to clipboard” — announced politely after current speech
Targeted roles (on Save fail)“Failed to save — please try again, Retry button” — interrupts immediately because it is a true error

When to use each role:

RoleUse caseBehavior
role="status"Success, info, confirmationsPolite — waits for current speech to finish
role="alert"Errors, urgent warningsAssertive — interrupts current speech immediately

Key teaching points:

  • Auto-dismissing toasts containing actions (like “Undo” or “Retry”) are WCAG 2.2.1 failures if the action is not available through another path in the UI
  • The toast container must exist in the DOM before content is injected — dynamically created live regions are unreliable
  • Reserve role="alert" for genuine errors; use role="status" for everything else
  • Always provide a dismiss button so users can clear the toast at their own pace

Resources