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>

Bootstrap Toast Notification Stack — Free Snippet

Bootstrap Toast Notification Stack · Modals · Plain HTML, CSS & JS · Live preview

What's included

Features

Real Bootstrap 5.3 Toast component, using its own built-in auto-dismiss delay, not setTimeout
Toasts are created fresh on each trigger and genuinely stack — any number can be visible at once
Removes each toast's DOM element only after Bootstrap's own hidden.bs.toast event fires
Three ready-made message types (success, danger, info) driven by one small config object
Manual dismiss (×) and auto-dismiss both work correctly without any custom timer logic
No memory leak from accumulating hidden-but-undeleted toast elements over a long session

About this UI Snippet

Bootstrap Toast Notification Stack — HTML, CSS & JavaScript

Screenshot of the Bootstrap Toast Notification Stack snippet rendered live

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:

text
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

  1. 1
    Load the snippetClick the snippet in the sidebar Library tab. The preview loads three trigger buttons.
  2. 2
    Click "Trigger success"A real Bootstrap toast slides in at the bottom-right corner and auto-dismisses after 4 seconds.
  3. 3
    Click multiple triggers quicklySeveral toasts stack vertically in the corner, each running its own independent 4-second timer.
  4. 4
    Dismiss one earlyClick a toast's × button — it closes immediately rather than waiting for its timer.
  5. 5
    Customize the messageEdit the MESSAGES object in the JS panel to change icons, colors, and text per type.

Real-world uses

Common Use Cases

Save confirmations and background action feedback
The standard place for "saved," "sent," or "uploaded" confirmations that shouldn't interrupt what the user is doing.
Learning to create Bootstrap components dynamically
Most Bootstrap component demos show static markup — this is the pattern for genuinely creating and mounting instances at runtime.
Error and status messaging in dashboards
Pair with a real API call's success/error handlers to surface backend responses without a full-page alert.
Any app with background or async operations
File uploads, autosave, sync status — anywhere a brief, non-blocking notification is the right amount of interruption.

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.