Skip to the content
Konstruktor UI

Feedback and overlays

Toast

A short message about something that just happened, shown in a corner and gone after six seconds. kui.toast({ title, message, tone, action, duration }) shows one. A danger toast and a toast with an action stay until they are dismissed.

<kui-toast-region> needs kui.js; the markup works without it as described below

Examples

Show a toast

Each button calls kui.toast with a different tone. Toasts appear at the bottom right; on a phone they run the full width at the bottom, above a tab bar if there is one.

HTML
<div class="kui-cluster">
  <button class="kui-button" type="button" data-example-toast data-tone="info" data-title="Report is being prepared" data-message="We will tell you when the PDF is ready.">Info</button>
  <button class="kui-button" type="button" data-example-toast data-tone="ok" data-title="Invoice sent" data-message="INV-2026-0142 was sent to računovodstvo@đorđević.rs.">Success</button>
  <button class="kui-button" type="button" data-example-toast data-tone="warn" data-title="Saved without the attachment" data-message="The file Jahresabschlussprüfungsbericht.pdf is larger than 20 MB.">Warning</button>
  <button class="kui-button" type="button" data-example-toast data-tone="danger" data-title="Payment failed" data-message="The bank refused the transfer of RSD 12,400.00. The toast stays until you close it.">Danger, stays</button>
  <button class="kui-button" type="button" data-example-toast data-tone="ok" data-title="3 tasks deleted" data-action="Undo" data-action-done="The 3 tasks are back">With an action</button>
</div>

The call

The same toasts in script. The call returns the toast’s element and a dismiss function.

kui.toast({ title: 'Invoice sent', message: 'INV-2026-0142 was sent.', tone: 'ok' });
kui.toast({ title: 'Payment failed', message: 'The bank refused the transfer.', tone: 'danger' }); // stays
const t = kui.toast({ title: '3 tasks deleted', tone: 'ok',
  action: { label: 'Undo', onClick: () => restoreTasks() } });   // stays
t.dismiss();                                                       // closes it from code
kui.toast('Copied');                                               // a string is the message
HTML
<div class="kui-codeblock"><pre tabindex="0" aria-label="Script that shows toasts"><code>kui.toast({ title: 'Invoice sent', message: 'INV-2026-0142 was sent.', tone: 'ok' });
kui.toast({ title: 'Payment failed', message: 'The bank refused the transfer.', tone: 'danger' }); // stays
const t = kui.toast({ title: '3 tasks deleted', tone: 'ok',
  action: { label: 'Undo', onClick: () =&gt; restoreTasks() } });   // stays
t.dismiss();                                                       // closes it from code
kui.toast('Copied');                                               // a string is the message</code></pre></div>

How each tone looks

The same markup the script makes, drawn in place with .kui-toast-region--inline. The message is cut after three lines; the whole text is in its title attribute and in the announcement.

Report is being prepared
We will tell you when the PDF is ready.
Invoice sent
INV-2026-0142 was sent to Đorđević i sinovi.
Saved without the attachment
The file Jahresabschlussprüfungsbericht.pdf is larger than 20 MB.
Payment failed
The bank refused the transfer of RSD 12,400.00.
3 tasks deleted
HTML
<div class="kui-toast-region kui-toast-region--inline">
  <div class="kui-toast kui-toast--info"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#info"></use></svg><div class="kui-toast__text"><div class="kui-toast__title">Report is being prepared</div><div class="kui-toast__message">We will tell you when the PDF is ready.</div></div><button class="kui-button kui-button--ghost kui-button--icon kui-button--sm kui-toast__close" type="button" aria-label="Dismiss"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#close"></use></svg></button></div>
  <div class="kui-toast kui-toast--ok"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#success"></use></svg><div class="kui-toast__text"><div class="kui-toast__title">Invoice sent</div><div class="kui-toast__message">INV-2026-0142 was sent to Đorđević i sinovi.</div></div><button class="kui-button kui-button--ghost kui-button--icon kui-button--sm kui-toast__close" type="button" aria-label="Dismiss"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#close"></use></svg></button></div>
  <div class="kui-toast kui-toast--warn"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#warning"></use></svg><div class="kui-toast__text"><div class="kui-toast__title">Saved without the attachment</div><div class="kui-toast__message">The file Jahresabschlussprüfungsbericht.pdf is larger than 20 MB.</div></div><button class="kui-button kui-button--ghost kui-button--icon kui-button--sm kui-toast__close" type="button" aria-label="Dismiss"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#close"></use></svg></button></div>
  <div class="kui-toast kui-toast--danger"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#error"></use></svg><div class="kui-toast__text"><div class="kui-toast__title">Payment failed</div><div class="kui-toast__message">The bank refused the transfer of RSD 12,400.00.</div></div><button class="kui-button kui-button--ghost kui-button--icon kui-button--sm kui-toast__close" type="button" aria-label="Dismiss"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#close"></use></svg></button></div>
  <div class="kui-toast kui-toast--ok"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#success"></use></svg><div class="kui-toast__text"><div class="kui-toast__title">3 tasks deleted</div><div class="kui-toast__actions"><button class="kui-button kui-button--sm" type="button">Undo</button></div></div><button class="kui-button kui-button--ghost kui-button--icon kui-button--sm kui-toast__close" type="button" aria-label="Dismiss"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#close"></use></svg></button></div>
</div>

Classes and attributes

kui.toast(options)
Shows a toast. Options: title, message, tone (info, ok, warn, danger), action ({ label, onClick }), duration in milliseconds (0 keeps it). Returns { element, dismiss }.
kui.toast("text")
A string is the message of an info toast.
<kui-toast-region>
The live region that holds the toasts. The first call adds one to the body. Put your own in the page to choose the place.
.kui-toast-region--inline
A region in the flow of the page instead of fixed in the corner.
.kui-toast, --ok, --warn, --danger
One toast and its tone. The children are made by the script: an icon, .kui-toast__text (__title, __message, __actions) and .kui-toast__close.
kui-dismiss
The event a toast sends when it closes.

Keyboard

Tab
Moves into a toast that has an action or a close button, like any other control.
Escape
With focus in a toast, dismisses it. Focus goes back where it was before.

Accessibility

  • The region is a named landmark (the keyed word “Notifications”). Its live text announces each toast once; a danger toast interrupts (assertive), the others wait (polite).
  • The timer pauses while the pointer is over a toast or focus is inside it (WCAG 2.2.1).
  • A toast with an action never closes by itself, so a person using a screen reader or a switch has time to reach it.
  • Focus is never moved into a toast. Anything a toast offers must also be possible elsewhere (Undo also in the menu, for example).
  • Each tone has its own icon; the title says the outcome in words.

Do and do not

Do

  • Confirm an action the person just took: “Invoice sent”.
  • Offer Undo in a toast after a delete, instead of asking first.
  • Keep the title to a few words and the message to one sentence.

Do not

  • Do not put an error that blocks the work in a toast; show an alert next to the form.
  • Do not show more than two or three toasts at once.
  • Do not use a toast for something the person must read to continue.