Skip to content

Bootstrap Toast Stack

Bootstrap 5 toast notifications in a corner stack: success, info, warning and error buttons, selectable corner, auto-hide with a progress bar and a stack limit.

Also known as: toast notifications, snackbar notifications, notification popup stack, stacked toast messages

Bootstrap 5 Toasts Responsive #alert #dark #notification #stack #toast

Bootstrap Toast Stack live demo

Open in new tab

Bootstrap 5 code (HTML, CSS, JS)

A Bootstrap 5 toast stack that collects notifications in one corner of the screen. Four buttons create success, info, warning and error toasts, a segmented control moves the stack to any corner, and timed toasts show a shrinking progress bar. Use it for save confirmations, upload errors and other short status messages in dashboards and web apps.

How it works

The root .tst-root contains a control panel (.tst-panel) and a fixed .toast-container with the extra class .tst-stack. The panel buttons carry data-tst-type with success, info, warning or error. On click the script clones the toast from the .tst-template element, adds the modifier class such as .tst-toast--error, fills the icon, title and message from the MESSAGES object and creates it with bootstrap.Toast. Each modifier sets the --tst-tone color used by the icon tile, the close button focus ring and the .tst-toast__bar progress line.

When the "Hide automatically" switch (#tst-autohide) is on, the toast gets .tst-toast--timed and a CSS animation scales the bar to zero over the delay. Bootstrap pauses the timer on hover and focus, so the bar pauses too and restarts when the pointer or focus leaves. Toasts listen for hidden.bs.toast and remove themselves from the DOM. If more than data-tst-max toasts are open, the oldest ones close first. The radios named tst-position switch the container between the top-0, bottom-0, start-0 and end-0 utilities and reverse the order so the newest toast stays next to the corner. "Dismiss all" (.tst-clear) hides every open toast. The two toasts in the markup start visible with data-bs-autohide="false".

Customization

  • data-tst-max on .tst-root: change how many toasts stay visible before the oldest one closes (default 4).
  • data-tst-delay on .tst-root: set the auto-hide delay in milliseconds; the progress bar uses the same value.
  • --tst-success, --tst-info, --tst-warning and --tst-error in .tst-root: recolor each toast type and its trigger icon.
  • --tst-toast-bg and --tst-toast-text in .tst-root: switch the dark toasts to a light surface.
  • --tst-toast-width in .tst-root: make the toasts wider or narrower.
  • The MESSAGES object in script.js: change titles, texts and Bootstrap Icons, or add a new type together with a .tst-toast--{type} rule.
  • Change the default corner by moving checked to another tst-position radio and updating the position utilities on .tst-stack.

Use cases

  • Dashboards: success toasts confirm saved changes without interrupting the user
  • Upload and form screens: error toasts report failures and are announced to screen readers
  • Web apps: the toast stack can sit in any corner and limits how many messages show at once
  • Admin tools: a shrinking progress bar shows when each timed message will disappear

Accessibility

The stack has aria-live="polite", so new toasts are announced. Success, info and warning toasts use role="status", while error toasts get role="alert" to be read immediately. Every toast has a labelled close button, and the corner control is a fieldset with a legend, made of real radio inputs with visible focus outlines. Timed toasts do not close while hovered or focused. Under prefers-reduced-motion: reduce the progress bar does not animate and Bootstrap disables the fade.

Usage notes

Requires the Bootstrap 5 bundle and Bootstrap Icons. Use one stack per page; the container is fixed, and the radio name tst-position and the #tst-autohide id must be unique.

Bootstrap Toast Stack at a glance

Framework
Bootstrap 5
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Bootstrap 5, Bootstrap Icons
Layout
Responsive, works on mobile
Category
Toasts
License
Free for personal and commercial use

Questions about this template

Can I use the Bootstrap Toast Stack code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Bootstrap 5 and Bootstrap Icons from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
  • <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
Bootstrap Toast Stack – free Bootstrap 5 toast template
Bootstrap Toast Stack · free Bootstrap 5 toast template

More Toasts

Toast with Progress Bar – free Pure CSS toast template

Toast with Progress Bar

Stacked toast notifications with a CSS countdown progress bar that pauses on hover or focus and closes the toast when it runs out.

Toast Notifications – free Tailwind CSS toast template

Toast Notifications

Stacking Tailwind CSS toast notifications for success, error and info with auto-dismiss countdown, pause on hover and accessible live region.