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());
});
});Bootstrap Toast Notification Stack — Free Snippet
Bootstrap Toast Notification Stack · Modals · Plain HTML, CSS & JS · Live preview
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.
Build with AI
Build, Understand, Optimize, and Extend It With AI
Hand this snippet's HTML, CSS, and JS to an AI coding assistant like Claude and ask it to add a progress-bar countdown inside each toast showing time remaining before auto-dismiss, or to limit the stack to a maximum of 3 visible toasts, queuing the rest. It's also a good exercise to ask the assistant to wire one of the trigger types to a real fetch() call's success/error branches.
Prompt to recreate it
Copy this into your AI assistant of choice to build the effect from scratch, or as a jumping-off point for your own variant:
Build a Bootstrap 5.3 stacking toast notification system, using the real Bootstrap CDN framework (bootstrap.min.css and bootstrap.bundle.min.js), not custom CSS made to resemble Bootstrap.
Requirements:
- A fixed-position Bootstrap toast-container in a screen corner, and at least three trigger buttons for different notification types (e.g. success, error, info), each with its own icon, background color, and message text driven by a small config object.
- Each button click must create a brand-new toast DOM element, append it to the container, and initialize it as a real bootstrap.Toast instance with a 4-second auto-dismiss delay — do not reuse or mutate a single static toast element.
- Multiple toasts triggered in quick succession must all be visible and stacked simultaneously, each running its own independent dismiss timer.
- After a toast is dismissed (either automatically or via its close button), remove its DOM element entirely once Bootstrap's own hidden.bs.toast event confirms the hide animation has finished — do not leave hidden toast elements accumulating in the DOM.Want to tighten it up first? Run this prompt through the AI Prompt Studio to score it across 8 quality dimensions, catch anti-patterns, and tune the wording for Claude, ChatGPT, or Gemini before you paste it in.
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.