Navigation✨ Premium

Toast Success

A green notification slides in from the right, stays 3 seconds and disappears — instant, non-blocking success feedback.

JSAnimationFeedback

You'll get access to the interactive demo with a free account.

This effect is part of Effect.Labs — 811 vanilla effects, some free, some premium. Navigation has 36 effects, including 4 free. Explore the category →

3 usage examples

Settings form — Save confirmation — Toast Success example 1

① Settings form — Save confirmation

WhenThe user clicks Save on a profile or configuration form and the server responds with 200.
WhyThe non-blocking toast confirms the action without closing the form or opening a modal — the user sees the confirmation immediately and keeps working.
SettingsshowToast('success', 'Settings saved'); default colors (green #10b981 → #059669); 3 s duration.
Report export — CSV file ready — Toast Success example 2

② Report export — CSV file ready

WhenA background export job finishes; the front end detects it via polling or webhook and notifies the user without redirecting them.
WhyThe toast signals the file is available without interrupting navigation — the user keeps filtering data while the feedback appears quietly in the corner.
SettingsshowToast('success', 'Export ready — 1,247 rows'); min-width: 320px for longer messages; 3 s duration.
Upload dropzone — Image uploaded — Toast Success example 3

③ Upload dropzone — Image uploaded

WhenThe upload completes server-side and the endpoint returns the stored image URL.
WhyThe lateral slide draws attention without covering the dropzone or blocking a follow-up upload — the user chains files without interruption.
SettingsshowToast('success', 'Image uploaded successfully'); toasts stack automatically if multiple uploads finish at once.

How it works

The global function showToast(type, message) targets #toastContainer via getElementById, creates a <div class="toast {type}"> and injects it into the container. The SVG icon (checkmark, cross, or info dot) is generated inline based on the type parameter — no external resource is loaded.

The toastSlideIn entry animation slides the toast from translateX(100%) to its resting position in 0.4 s using cubic-bezier(0.4, 0, 0.2, 1) — a Material Design-inspired easing that accelerates then decelerates. After 3,000 ms a setTimeout adds the .hiding class which triggers toastSlideOut (0.3 s ease to translateX(100%)). A second 300 ms setTimeout then removes the node from the DOM via toast.remove().

The .toast-container is position: fixed; top: 20px; right: 20px; z-index: 9999 — anchored to the top-right corner regardless of scroll. Successive calls to showToast() stack toasts vertically via flex-direction: column; gap: 10px; each manages its own dismissal timer independently.

Accessibility

  • No prefers-reduced-motion support: toastSlideIn and toastSlideOut always run. Add @media (prefers-reduced-motion: reduce) { .toast { animation: none; } } to disable them.
  • The #toastContainer has no aria-live attribute in the provided code — toasts are not announced to screen readers. Add aria-live="polite" aria-atomic="true" to the container to fix this.
  • White text on green background (#059669): contrast ratio ≥ 4.5:1, WCAG AA compliant.
  • No keyboard dismiss mechanism — no Close button and no Escape key handler in the provided JS.
  • Inline SVG icons carry neither aria-hidden nor aria-label — add aria-hidden="true" to each SVG to prevent screen readers from verbalising them.

Browser compatibility

Requires createElement, classList, and CSS animations — supported in all modern browsers.

Chrome 110+✓ Full
Firefox 110+✓ Full
Safari 16+✓ Full
Edge 110+✓ Full
Mobile iOS✓ Full
Android Chrome✓ Full

Without CSS the toast renders as plain text in the flow — no JS errors. If <code>getElementById('toastContainer')</code> finds no container, the function returns silently.

The code

HTML structure to paste into your page (CSS + JS available with a premium account):

index.html — structure
<div class="toast-container" id="toastContainer"></div>

<!-- Trigger button (place it anywhere in your UI) -->
<button class="toast-trigger" onclick="showToast('success', 'Action completed!')">
  Trigger toast
</button>
🔒 Unlock the full code — from €2.99 the first month

Full HTML + CSS + JS, copy-paste ready — with hundreds of premium effects.

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
.toast.success background linear-gradient(135deg, #10b981, #059669) Toast background color — swap in your brand gradient.
.toast-container top / right 20px / 20px Container anchor position. To move to bottom-right: top: auto; bottom: 20px;.
.toast min-width 280px Minimum toast width — increase to 320–360 px for longer messages without line breaks.
.toast border-radius 12px Corner rounding. 0 for a square look, 24 px for a pill style.
setTimeout delay (3e3) 3000 ms Display duration before dismissal — edit the constant inside showToast.
toastSlideIn duration 0.4s Entry animation speed — lower to 0.2 s for snappier feedback.
.toast font-size / font-weight 0.95rem / 500 Message text size and weight — adjust to match your typography.
.toast gap 12px Spacing between the SVG icon and the message text.

FAQ

Yes. Every call to showToast() adds a new <div> to #toastContainer — they stack vertically via flex-direction: column; gap: 10px. Add a JS counter and skip the call if a cap is reached to avoid visual overload.
Update the .toast-container properties: top: auto; bottom: 20px; right: auto; left: 20px;. For a left-side slide, also swap translateX(100%) to translateX(-100%) in both toastSlideIn and toastSlideOut keyframes.
Not by default. Add aria-live="polite" aria-atomic="true" to the <div id="toastContainer"> element so assistive technologies automatically read each message as it is inserted into the DOM.