Skip to content

Toast

A short message in the corner after an action, like "Saved". It goes away by itself. Same markup and props in every style: switch the style in the header to see it change.

Basic

Press the button. In HTML, add data-vin-toast="Title" to a button, or call VinUI.toast({ title }).

toast-basic.html
<button type="button" class="vin-btn vin-btn--outline" data-vin-toast="Changes saved">Save changes</button>

Success, error and action

Icons for success and errors, and an action such as Undo.

toast-variants.html
<button type="button" class="vin-btn vin-btn--outline" data-vin-toast="Payment received" data-vin-toast-description="We've emailed your receipt." data-vin-toast-variant="success">Success</button>
<button type="button" class="vin-btn vin-btn--outline" data-vin-toast="Upload failed" data-vin-toast-description="The file is larger than 10 MB." data-vin-toast-variant="danger">Error</button>
<button type="button" class="vin-btn vin-btn--outline" data-vin-toast="Message archived" data-vin-toast-action="Undo">With action</button>

How it looks

The same toast shown inline, for reference.

Payment received

We've emailed your receipt.

Message archived

toast-appearance.html
<div style="display: grid; gap: 10px; width: 100%; max-width: 360px">
  <div class="vin-toast vin-toast--success">
    <svg class="vin-toast__icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="m8.5 12 2.5 2.5 4.5-5"/></svg>
    <div class="vin-toast__content">
      <p class="vin-toast__title">Payment received</p>
      <p class="vin-toast__description">We've emailed your receipt.</p>
    </div>
    <button type="button" class="vin-btn vin-btn--ghost vin-btn--icon vin-toast__close" aria-label="Close"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg></button>
  </div>
  <div class="vin-toast">
    <div class="vin-toast__content">
      <p class="vin-toast__title">Message archived</p>
      <div class="vin-toast__actions">
        <button type="button" class="vin-btn vin-btn--outline vin-btn--sm">Undo</button>
      </div>
    </div>
    <button type="button" class="vin-btn vin-btn--ghost vin-btn--icon vin-toast__close" aria-label="Close"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg></button>
  </div>
</div>

Installation

React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:

Terminal
npx @vinish/ui add toast
React
import { Toaster, Toast, toast, dismissToast } from "@/components/vin/toast";
Vue
import Toaster, { Toast, toast, dismissToast } from "@/components/vin/toast.vue";
Svelte
import Toast, { toast, dismissToast, toasts } from "$lib/components/vin/toast.svelte";
import Toaster from "$lib/components/vin/toast-toaster.svelte";

The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.

Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.

API

From spec/toast.json, which every framework version is tested against.

PropValuesDefaultIn HTML
toast(options)
Shows a toast: { title, description?, variant?, action?: { label, onClick }, duration? }. Returns an id for dismiss(id).
function—VinUI.toast({ … }) or data-vin-toast="Title" on a button (with data-vin-toast-description, -variant)
variantdefaultsuccessdangerdefaultvin-toast--{value}
duration
Milliseconds before it closes. Hovering or focusing it pauses the timer.
number5000—
Toaster
Put it once in your app; toasts appear in it.
component—section.vin-toaster (vinui.js makes it)
Toast
The toast itself, if you want to show one inline.
component—.vin-toast

Parts

React, Vue, SvelteHTML classes
<Toaster><Toast>.vin-toaster.vin-toast.vin-toast--success.vin-toast--danger.vin-toast__icon.vin-toast__content.vin-toast__title.vin-toast__description.vin-toast__actions.vin-toast__close

Accessibility

  • Each toast is a status message (role="status"), so screen readers read it without moving focus. Errors use role="alert".
  • Toasts sit in a landmark named "Notifications", so keyboard users can find them.
  • The timer pauses while the pointer or focus is on a toast, and every toast has a close button (WCAG 2.2.1).
  • Don't put the only way to do something in a toast: it goes away.