Bootstrap Toast Notification Stack — Free Snippet
Bootstrap Toast Notification Stack · Modals · Plain HTML, CSS & JS · Live preview
Copy & paste
Source Code
<div class="container py-5 text-center">
<div class="d-flex gap-2 justify-content-center flex-wrap">
<button class="btn btn-success btn-sm" data-type="success">Trigger success</button>
<button class="btn btn-danger btn-sm" data-type="danger">Trigger error</button>
<button class="btn btn-secondary btn-sm" data-type="info">Trigger info</button>
</div>
<p class="text-muted small mt-3">Toasts stack, each auto-dismisses after 4s, or click × to close early.</p>
</div>
<div class="toast-container position-fixed bottom-0 end-0 p-3" id="bstoastContainer"></div>.bstoast-item { min-width: 260px; }const container = document.getElementById('bstoastContainer');
const MESSAGES = {
success: { icon: '✓', bg: 'text-bg-success', text: 'Changes saved successfully.' },
danger: { icon: '✕', bg: 'text-bg-danger', text: 'Something went wrong — try again.' },
info: { icon: 'i', bg: 'text-bg-secondary', text: 'A new version is available.' },
};
// Each click creates and mounts a brand-new toast element, then hands it to
// a fresh bootstrap.Toast instance — stacking is just normal DOM flow inside
// the fixed container, so any number can be visible/queued at once.
document.querySelectorAll('[data-type]').forEach(btn => {
btn.addEventListener('click', () => {
const cfg = MESSAGES[btn.dataset.type];
const el = document.createElement('div');
el.className = 'toast bstoast-item align-items-center border-0 ' + cfg.bg;
el.setAttribute('role', 'alert');
el.innerHTML =
'<div class="d-flex">' +
'<div class="toast-body"><strong>' + cfg.icon + '</strong> ' + cfg.text + '</div>' +
'<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>' +
'</div>';
container.appendChild(el);
const toast = new bootstrap.Toast(el, { delay: 4000 });
toast.show();
// Bootstrap hides the element on timeout/dismiss but never removes it —
// clean up the DOM once its own hide animation has actually finished.
el.addEventListener('hidden.bs.toast', () => el.remove());
});
});Extend with AI
Take This Snippet Further With AI
The AI prompt for this one is for Patreon supporters ($3 a month), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.
What's included
Features
About this UI Snippet
Bootstrap Toast Notification Stack — HTML, CSS & JavaScript

Bootstrap's real Toast component only shows one static example in most demos — this snippet shows the pattern a real app actually needs: creating a new toast on demand and letting several stack in the corner at once. Each button click builds a fresh <div class="toast"> element from a small message config, appends it into a .toast-container, and hands it to a new bootstrap.Toast instance with a 4-second delay — Bootstrap's own auto-dismiss timer, not a custom setTimeout.
One detail matters for anything beyond a single toast: Bootstrap hides a toast on dismiss but never removes its element from the DOM. Left unhandled, that would silently leave an invisible element behind after every notification. This snippet listens for Bootstrap's own hidden.bs.toast event — fired once the hide animation genuinely finishes — and removes the element then, so triggering dozens of toasts over a session never leaks stale nodes.
Step by step
How to Use
- 1Load the snippetClick the snippet in the sidebar Library tab. The preview loads three trigger buttons.
- 2Click "Trigger success"A real Bootstrap toast slides in at the bottom-right corner and auto-dismisses after 4 seconds.
- 3Click multiple triggers quicklySeveral toasts stack vertically in the corner, each running its own independent 4-second timer.
- 4Dismiss one earlyClick a toast's × button — it closes immediately rather than waiting for its timer.
- 5Customize the messageEdit the MESSAGES object in the JS panel to change icons, colors, and text per type.
Real-world uses
Common Use Cases
Got questions?
Frequently Asked Questions
Real Bootstrap 5.3 — every toast is a genuine bootstrap.Toast instance using the actual component's show/hide/delay behavior, loaded from the real CDN.
Yes — Bootstrap only hides a dismissed toast, it never removes the element. This snippet listens for the hidden.bs.toast event (fired once the hide animation completes) and removes the element then, so nothing accumulates in the DOM.
Yes — each click creates and mounts an entirely new toast element into the shared .toast-container, so triggering several in a row shows them all stacked, each running its own independent dismiss timer.
Change the delay: 4000 value (in milliseconds) passed to new bootstrap.Toast(el, { delay: ... }).
Yes — add a new key to the MESSAGES object with its own icon, Bootstrap background class (bg), and text, then trigger it from a button with the matching data-type attribute.