Docs

Main site

Installation Browser support Extend config MCP server
Validation Page speed testing Responsive design
Accordion Aspect Ratio Avatar Badge Banner Bento Grid Blockquote Breadcrumbs Button Callout Card Drawer Dropdown Link Modal Navbar Navblock Pagination Popover Progress Separator Tabs Timeline Toast Tooltip
Checkbox Datepicker File upload Form field Input Label OTP Radio Range Select Textarea Toggle
Header Footer
Accordion Auth Checkbox & Radio Content Drawers Features Modals Statistics & Metrics Teams Dropdowns
Address Contact number Currency symbol Date Emirates ID Name
Close
Home Documentation Components Toast

Toast

A Toast is a transient, non-blocking notification anchored to a corner of the viewport. Use it for asynchronous status updates such as "Application submitted", save confirmations, connection warnings, and undo affordances. For confirmations the user must acknowledge, use the modal component instead, and for inline page-level messages use the callout.

Feedback
Status
Active
Introduced
4.0.x
View source code

Anatomy

A toast is a small card with a coloured top border matching its variant, an optional icon and title, a description, an optional actions row, a dismiss button, and an optional progress bar. Multiple toasts at the same position share a single portal container appended to the end of document.body.

Image showing anatomy of a toast

Item Name Description
1 Top border 4px coloured strip indicating the variant (error/warning/success/info), or the neutral appearance border for default.
2 Icon Optional, user-provided via the icon slot. No icon ships by default.
3 Title Optional bold heading via the title slot.
4 Description The default slot — the toast's main message.
5 Actions Optional buttons or links via the actions slot — undo, retry, view details.
6 Dismiss button Closes the toast. Hidden when is-dismissible="false".
7 Progress bar Optional countdown strip shown when is-progress-enabled="true" and duration is greater than 0.

Basics

aegov-toast is most often used imperatively through a global helper installed at window.aegovToast. Calling .show(options) creates a toast, mounts it inside a per-position portal container at the end of document.body, and shows it — all in a single call, with no <aegov-toast> markup or ref required for the common case.

Submit application
<aegov-button id="trigger-toast" variant="primary">Submit application</aegov-button>

<script>
  document.getElementById('trigger-toast').addEventListener('click', () => {
    window.aegovToast.show({
      message: 'Application submitted successfully.',
      variant: 'success',
      position: 'top-right',
      duration: 4000,
    });
  });
</script>

Variants

variant sets the semantic colour of the 4px top border. default (no border colour) suits neutral confirmations; success, info, warning, and error add a coloured top border in the corresponding palette. error and warning are announced through the assertive live region — see Accessibility below.

Default Success Info Warning Error
<div class="flex flex-wrap gap-3">
  <aegov-button id="variant-default" appearance="outline">Default</aegov-button>
  <aegov-button id="variant-success" variant="primary">Success</aegov-button>
  <aegov-button id="variant-info" variant="secondary">Info</aegov-button>
  <aegov-button id="variant-warning" appearance="outline">Warning</aegov-button>
  <aegov-button id="variant-error" appearance="outline">Error</aegov-button>
</div>

<script>
  const map = {
    'variant-default': { variant: 'default', message: 'Your draft has been saved.' },
    'variant-success': { variant: 'success', message: 'Application submitted successfully.' },
    'variant-info': { variant: 'info', message: 'A new policy update is available.' },
    'variant-warning': { variant: 'warning', message: 'Your session expires in 5 minutes.' },
    'variant-error': { variant: 'error', message: 'Unable to save changes. Please try again.' },
  };
  Object.keys(map).forEach(id => {
    document.getElementById(id).addEventListener('click', () => {
      window.aegovToast.show({ ...map[id], position: 'top-right', duration: 4000 });
    });
  });
</script>

Appearance

appearance controls the surface treatment. soft (default) is a white background with dark text, suitable for most cases. solid is a dark background with white text, useful when a toast needs to read as a system-level message regardless of the page background.

Soft appearance Solid appearance
<aegov-button id="appearance-soft" appearance="outline">Soft appearance</aegov-button>
<aegov-button id="appearance-solid" variant="primary">Solid appearance</aegov-button>

<script>
  document.getElementById('appearance-soft').addEventListener('click', () => {
    window.aegovToast.show({ message: 'Application submitted.', variant: 'success', appearance: 'soft', position: 'top-right', duration: 4000 });
  });
  document.getElementById('appearance-solid').addEventListener('click', () => {
    window.aegovToast.show({ message: 'Application submitted.', variant: 'success', appearance: 'solid', position: 'top-right', duration: 4000 });
  });
</script>

Position

position anchors the toast to a corner or edge of the viewport. Each position has its own portal container, so a single page can run multiple stacks at once — for example a confirmation top-right and a connectivity warning bottom-center.

Value Anchor
top-right Default. Aligned to the inline-end of the viewport.
top-left Aligned to the inline-start of the viewport.
top-center Centred along the top edge.
bottom-right Aligned to the inline-end at the bottom.
bottom-left Aligned to the inline-start at the bottom.
bottom-center Centred along the bottom edge.
Top left Top center Top right Bottom left Bottom center Bottom right
<div class="grid grid-cols-3 gap-3 max-w-md">
  <aegov-button id="pos-tl" appearance="outline" size="sm">Top left</aegov-button>
  <aegov-button id="pos-tc" appearance="outline" size="sm">Top center</aegov-button>
  <aegov-button id="pos-tr" appearance="outline" size="sm">Top right</aegov-button>
  <aegov-button id="pos-bl" appearance="outline" size="sm">Bottom left</aegov-button>
  <aegov-button id="pos-bc" appearance="outline" size="sm">Bottom center</aegov-button>
  <aegov-button id="pos-br" appearance="outline" size="sm">Bottom right</aegov-button>
</div>

<script>
  const positions = {
    'pos-tl': 'top-left', 'pos-tc': 'top-center', 'pos-tr': 'top-right',
    'pos-bl': 'bottom-left', 'pos-bc': 'bottom-center', 'pos-br': 'bottom-right',
  };
  Object.keys(positions).forEach(id => {
    document.getElementById(id).addEventListener('click', () => {
      window.aegovToast.show({ message: 'Toast at ' + positions[id], variant: 'info', position: positions[id], duration: 4000 });
    });
  });
</script>

Duration and auto-dismiss

duration is the auto-dismiss timeout in milliseconds. Hovering the toast — or moving keyboard focus into it — pauses the timer; leaving resumes it from the exact remaining time. Set duration: 0 to disable auto-dismiss entirely, so the user must click the close button.

Quick (2s) Long (8s) Persistent
<aegov-button id="dur-fast" appearance="outline">Quick (2s)</aegov-button>
<aegov-button id="dur-long" appearance="outline">Long (8s)</aegov-button>
<aegov-button id="dur-persist" appearance="outline">Persistent</aegov-button>

<script>
  document.getElementById('dur-fast').addEventListener('click', () => {
    window.aegovToast.show({ message: 'Quick confirmation.', variant: 'success', duration: 2000, position: 'top-right' });
  });
  document.getElementById('dur-long').addEventListener('click', () => {
    window.aegovToast.show({ message: 'Document downloaded.', variant: 'success', duration: 8000, position: 'top-right' });
  });
  document.getElementById('dur-persist').addEventListener('click', () => {
    window.aegovToast.show({ message: 'You are offline. Some features may be unavailable.', variant: 'warning', duration: 0, position: 'top-right' });
  });
</script>

Progress bar

Set isProgressEnabled: true (is-progress-enabled attribute) to render a thin countdown bar across the bottom of the toast. It pauses whenever the auto-dismiss timer pauses — on hover or keyboard focus — and has no effect when duration is 0.

Submit with progress bar
<aegov-button id="show-progress" variant="primary">Submit with progress bar</aegov-button>

<script>
  document.getElementById('show-progress').addEventListener('click', () => {
    window.aegovToast.show({
      message: 'Application submitted to the Ministry of Interior.',
      variant: 'success',
      duration: 6000,
      isProgressEnabled: true,
      position: 'top-right',
    });
  });
</script>

Stack vs rack mode

When several toasts land at the same position, mode controls how they lay out. stack (default) shows every toast with a small gap between them. rack collapses them into a single deck — the newest is fully visible, older toasts peek behind it scaled and faded, and a count badge shows the total. Hovering or focusing the deck expands it back into a stack.

Fire 3 stacked toasts Fire 4 racked toasts
<aegov-button id="mode-stack" appearance="outline">Fire 3 stacked toasts</aegov-button>
<aegov-button id="mode-rack" variant="primary">Fire 4 racked toasts</aegov-button>

<script>
  document.getElementById('mode-stack').addEventListener('click', () => {
    ['Application received', 'Documents validated', 'Payment confirmed'].forEach((msg, i) => {
      setTimeout(() => window.aegovToast.show({ message: msg, variant: 'success', mode: 'stack', position: 'top-right', duration: 5000 }), i * 250);
    });
  });
  document.getElementById('mode-rack').addEventListener('click', () => {
    ['New application received', 'Document uploaded', 'Officer assigned', 'Status updated'].forEach((msg, i) => {
      setTimeout(() => window.aegovToast.show({ message: msg, variant: 'info', mode: 'rack', position: 'bottom-right', duration: 0 }), i * 200);
    });
  });
</script>

Title, icon, and actions slots

A toast can carry more than description text: title for a bold heading, icon for a custom leading icon (none ships by default), and actions for buttons or links such as an inline undo. These need real slotted markup, added before the toast is connected — slot presence and the announced text are both captured when the element loads. A toast declared in plain HTML stays hidden until show() runs, so pre-declared markup works. In a framework app, though, build the <aegov-toast> element in your click handler, not as pre-mounted JSX/template markup: show() moves the element out of the framework's tree and close() removes it from the DOM — construct it on demand instead, exactly as window.aegovToast.show() does internally.

Move to trash
<aegov-button id="show-undo">Move to trash</aegov-button>

<script>
  document.getElementById('show-undo').addEventListener('click', () => {
    const toast = document.createElement('aegov-toast');
    toast.variant = 'default';
    toast.duration = 6000;
    toast.innerHTML = `
      <svg slot="icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
        <polyline points="3 6 5 6 21 6"/>
        <path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/>
      </svg>
      <span slot="title">Application moved to trash</span>
      You can restore it within 30 days.
      <aegov-button slot="actions" appearance="link" size="sm">Undo</aegov-button>
    `;
    document.body.appendChild(toast);
    toast.show();
  });
</script>

RTL support

Toast containers use logical CSS properties, so a -right position resolves to the inline-end edge and a -left position to the inline-start edge under RTL. The container and each toast are appended straight to document.body, though — not left inside wherever the trigger button lives — so they only inherit dir from <html>/<body>, never from a wrapper placed around the trigger. For a whole Arabic page, set dir="rtl" on <html> and every toast mirrors automatically. For a single RTL toast on an otherwise-LTR page, set dir="rtl" directly on a declared <aegov-toast> element, as shown below — the value travels with the element when it moves into its portal container.

تم إرسال الطلب بنجاح. ستصلك رسالة نصية خلال 3 أيام عمل. إرسال الطلب
<aegov-toast id="rtl-toast" dir="rtl" variant="success" duration="0">
  تم إرسال الطلب بنجاح. ستصلك رسالة نصية خلال 3 أيام عمل.
</aegov-toast>

<aegov-button id="show-rtl-toast" variant="primary">إرسال الطلب</aegov-button>

<script>
  document.getElementById('show-rtl-toast').addEventListener('click', () => {
    document.getElementById('rtl-toast').show();
  });
</script>

Usage

Here is the recommended usage of a toast on any website or application. These are recommended usage guides, however the developer must use the best practices of web and application development to accurately use this component.

Use the imperative window.aegovToast.show() helper for the common case
It creates, mounts, and shows a toast in one call, without needing a ref or manual element management.

Set dir="rtl" on <html> for a fully Arabic page
Every toast then inherits it automatically, since the portal container lives inside <body>. Only reach for setting dir on an individual declared <aegov-toast> element when a single toast must render RTL on an otherwise-LTR page.

Set duration to at least 6000ms for a destructive undo affordance
Give the user enough time to notice an action-bearing toast such as "Moved to trash… Undo" before it disappears.

Reserve error/warning variants for genuinely urgent messages
They route through the assertive live region and interrupt the screen reader. Overusing them for routine confirmations desensitises users to real warnings.

Don't use a toast as the only place critical information appears
It can auto-dismiss, be dismissed by the user, or be missed entirely. For anything the user must acknowledge, use aegov-modal instead.

Don't rely on a dir="rtl" wrapper around the trigger button to RTL a toast
The toast and its container are appended straight to document.body, outside that wrapper, so it silently renders LTR. See the RTL support section for the pattern that actually works.

API reference

The following are the properties and references of a toast

aegov-toast properties

AttributeDescriptionTypeDefault

variant

Semantic colour. Sets the 4px coloured top border. default has no colour.

default | error | warning | success | info

default

appearance

Surface treatment. soft is a white/dark-text card; solid is a dark/white-text card.

soft | solid

soft

position

Viewport corner or edge to anchor to. Each position gets its own portal container appended to document.body.

top-right | top-left | top-center | bottom-right | bottom-left | bottom-center

top-right

duration

Auto-dismiss timeout in milliseconds. 0 disables auto-dismiss. Hovering or focusing the toast pauses the timer; leaving resumes it from the remaining time.

number

5000

is-dismissible

Whether to render the close button.

boolean

true

mode

stack shows every toast at a position with a gap between them. rack collapses them into a peeking deck with a count badge that expands on hover or keyboard focus.

stack | rack

stack

is-progress-enabled

When true and duration > 0, render a shrinking countdown bar along the bottom edge.

boolean

false

Slots

SlotDescription

(default)

The toast description text. Accepts inline HTML when passed through the message option of the imperative helper.

title

Bold heading rendered above the description.

icon

User-provided icon rendered at the inline start of the content (left in LTR, right in RTL); svg children are sized to 20px. No icon ships by default.

actions

Buttons or links rendered below the description — undo, retry, view details.

Events

EventDetailDescription

aegovToastOpen

void

Fired after the toast becomes visible (once the entry animation has been queued).

aegovToastClose

void

Fired at the end of the 300ms exit animation, immediately before the toast element is removed from the DOM. Fires for every close path — timer, dismiss button, or close().

aegovToastDismiss

void

Fired when the user clicks the dismiss button, before the exit animation — and so before aegovToastClose.

Methods

MethodReturnsDescription

show()

Promise<void>

Move the toast into its per-position portal container, run the entry animation, announce the message, and start the auto-dismiss timer. Does nothing while the toast is already visible.

close()

Promise<void>

Stop the timer, run the exit animation, fire aegovToastClose, and remove the toast from the DOM. Does nothing if the toast is not visible or is already closing.

Pass-through attributes

AttributeNotesForwards to

aria-*

Not forwarded — the component manages its own ARIA semantics (the dismiss button label, the live-region announcement). Apply directly to <aegov-toast> for anything beyond what it already sets.

host

data-*

Not forwarded. Apply directly to <aegov-toast>.

host

id

Apply directly to <aegov-toast> for a stable handle, or capture the element returned by window.aegovToast.show().

n/a

dir

A native global attribute, not a component Prop. Set it directly on <aegov-toast> for a toast that must render RTL — the element (and its portal container) move to document.body, so it will not inherit dir from a wrapper around the trigger.

host & container

class, style

Applied to the host element.

host

Notes

The following notes are applicable of this component.

Built-in accessibility

  • Two persistent, reused, visually-hidden live regions exist at the document level: a polite region (role="status", aria-live="polite", aria-atomic="true") for default, info, and success variants, and an assertive region (role="alert", aria-live="assertive", aria-atomic="true") for error and warning variants. show() selects the correct region automatically based on variant and announces the toast's text content as captured when the element loaded — so set the content before adding the toast to the page; text changed afterwards is shown but not announced.
  • The dismiss button carries a bilingual, variant-aware aria-label — e.g. "Close success notification" in English, "إغلاق إشعار نجاح" in Arabic — with no developer translation needed.
  • Both mouse hover and keyboard focus pause the auto-dismiss timer and progress bar; leaving either resumes it from the exact remaining time (SC 2.2.1) — confirmed live: a toast held past its duration while hovered remained on screen, then closed shortly after the pointer moved away.
  • In rack mode, the deck expands on hover or keyboard focus moving into any toast in the rack, so keyboard users can reach every stacked toast, and collapses only once both leave.
  • Multiple toasts at the same position are never removed from the DOM while stacked. In rack mode, the newest three stay readable (older ones peek behind, scaled and faded); toasts from the fourth onward are fully hidden and get aria-hidden="true" until the rack expands or newer toasts close. Each toast's live-region announcement still fires when it is shown.
  • A 300ms exit animation runs before aegovToastClose fires and the element is removed from the DOM.

Developer responsibilities

  • Keep toast text short and self-contained. Don't use a toast as the only place critical information appears — it can be missed or dismissed.
  • For confirmations the user must acknowledge, use aegov-modal instead.
  • Give any button placed in slot="actions" an actionable, descriptive label — "Undo", "View status", "Retry" — not a bare icon.
  • For a destructive undo affordance, set duration to at least 6000ms so the user has time to react.
  • Set dir="rtl" directly on a declared <aegov-toast> element for a single RTL toast — see RTL support above; it will not inherit dir from a wrapper around the trigger, since it and its container move to document.body.

Keyboard support

Key Action
Tab Move focus into the toast — its action button(s), then the dismiss button.
Shift + Tab Move focus to the previous focusable element.
Enter, Space Activate the focused button (an action button or the dismiss button).