Back to Snippets

Toast Notifications Snippet.

A lightweight, fully self-contained toast notification system with four types; success, error, warning, and info. Toasts slide in from the bottom-right, stack cleanly, and auto-dismiss after 3 seconds with a progress bar.

How to Use?
Drop the HTML container and CSS into your page, include the JS, then call showToast('Your message', 'success') anywhere in your code. Valid types are success, error, warning, and info.

Credits
Built with pure JS DOM manipulation and CSS animations, zero dependencies.

<!-- Toast Container: place once near end of <body> -->
<div id="toast-container"></div>

<!-- Example trigger buttons -->
<div class="demo-buttons">
  <button onclick="showToast('Changes saved successfully!', 'success')">Success</button>
  <button onclick="showToast('Something went wrong.', 'error')">Error</button>
  <button onclick="showToast('Please review your input.', 'warning')">Warning</button>
  <button onclick="showToast('New update available.', 'info')">Info</button>
</div>