Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Bootstrap toasts let you show lightweight notifications in response to an action, place them around the viewport, and stack several together. In Bootstrap v5.3, a toast will not appear until you initialize its JavaScript plugin and call show(). These instructions follow the official v5.3 documentation, which identifies the release as v5.3.8; check your project’s installed version before using the snippets.

What you need before adding a toast

  • Bootstrap v5.3 markup and CSS in your page.
  • The Bootstrap JavaScript toast plugin, loaded as a compiled bundle or imported according to your build setup. Do not load both bootstrap.js and bootstrap.min.js.
  • A live region already present in the page if assistive technology should announce notifications that are inserted or updated dynamically.

Bootstrap describes toasts as opt-in: “Toasts are opt-in for performance reasons, so you must initialize them yourself.” See the Bootstrap v5.3 toast documentation and its JavaScript setup guidance.

Add a toast and show it from a button

Use a header and body for a standard toast, and include a dismiss control so the user can close it without waiting for auto-hide. The toast starts hidden; the button handler below gets its Bootstrap instance and calls show().

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<button type="button" id="showToast" class="btn btn-primary">Show notification</button>

<div class="position-fixed top-0 end-0 p-3" style="z-index: 11">
  <div id="exampleToast" class="toast" role="status" aria-live="polite" aria-atomic="true">
    <div class="toast-header">
      <strong class="me-auto">Notification</strong>
      <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
    </div>
    <div class="toast-body">Your changes have been saved.</div>
  </div>
</div>

<script>
  const toastElement = document.getElementById('exampleToast');
  const toast = bootstrap.Toast.getOrCreateInstance(toastElement);

  document.getElementById('showToast').addEventListener('click', () => {
    toast.show();
  });
</script>

The example assumes Bootstrap’s JavaScript bundle is available globally as bootstrap. If your project imports Bootstrap modules instead, import the toast plugin using the approach documented for your build. The data-bs-dismiss="toast" attribute connects the close button to Bootstrap’s dismissal behavior.

Choose auto-hide or manual dismissal

Bootstrap v5.3 documents three toast options. The defaults are animation: true, autohide: true, and delay: 5000 milliseconds. The delay is an API default, not a recommended duration for every message.

Option Default Effect
animation true Uses the toast transition animation.
autohide true Hides the toast automatically after its delay.
delay 5000 milliseconds Sets the wait before auto-hide when auto-hide is enabled.

Pass options when creating an instance if you want different behavior:

const toast = bootstrap.Toast.getOrCreateInstance(toastElement, {
  autohide: false
});

With auto-hide disabled, the user can close the notification using its dismiss button, or your code can hide it with toast.hide(). Bootstrap also provides show, hide, and transition events. Method calls start transitions and return before those transitions finish, so use the events when subsequent work depends on a transition having completed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For data attributes, option names use kebab case—for example, data-bs-autohide="false". See the complete option and event reference in the toast API documentation.

Position one toast or stack several

Place a single toast

Position the toast or a wrapper with CSS or Bootstrap positioning utilities. In the example above, position-fixed top-0 end-0 p-3 places a wrapper near the top-right edge and adds padding so it does not touch the viewport. Other combinations can place it at the top or bottom and at the start or end. Choose a location that suits your interface; Bootstrap does not prescribe one universally best position.

Stack notifications in a container

Put multiple toast elements inside one .toast-container and position that container. Bootstrap’s v5 pattern is container-based: the migration notes record that v5 added positioning through .toast-container and positioning utilities. Add spacing around the container and between notifications so the stack remains separate from page content.

<div class="toast-container position-fixed bottom-0 end-0 p-3">
  <div id="toastOne" class="toast" role="status" aria-live="polite" aria-atomic="true">
    <div class="toast-body">First notification</div>
  </div>
  <div id="toastTwo" class="toast" role="status" aria-live="polite" aria-atomic="true">
    <div class="toast-body">Second notification</div>
  </div>
</div>

Initialize and show each toast separately. The full set of placement examples is in the official Bootstrap v5.3 toast guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Make toast announcements accessible

Place a toast in a live region so assistive technologies can announce content that appears or changes without moving keyboard focus. Bootstrap recommends aria-atomic="true" so the full toast is announced as one unit. The live region should exist before the toast content is generated or updated; inserting the region and toast simultaneously may mean the update is not announced.

  • Use an appropriate live-region priority, such as aria-live="polite" for a routine status message.
  • Keep a clear, usable close button and label it for assistive technology.
  • Do not use a transient toast for information someone must act on or retain to complete a task. Bootstrap specifically recommends an alert for important process information such as form errors.
  • Check contrast and interaction in your own design. Bootstrap warns that accessibility depends substantially on author markup, styling, and scripting, and some default color combinations may have insufficient contrast against light backgrounds.

Bootstrap’s accessibility guidance explains why using the framework alone does not guarantee an accessible result.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Using Bootstrap toasts with React, Vue, or Angular

Bootstrap warns that its JavaScript plugins manipulate the DOM and are not fully compatible with frameworks such as React, Vue, and Angular. In a framework app, consider a framework-specific package or integration rather than letting Bootstrap’s plugin and the framework independently control the same elements. If you do use Bootstrap’s plugin, make sure its DOM changes fit the framework’s lifecycle and rendering model. The caveat is covered in Bootstrap’s JavaScript documentation.

Check the version before copying older snippets

This guide uses Bootstrap v5.3; its official component page identifies the current v5.3 release as v5.3.8. That does not establish a Bootstrap 2026 release. Confirm the version installed in your project and follow documentation for that version. In particular, do not assume older v4 toast examples use the v5 container-based positioning pattern or its documented five-second default duration. See Bootstrap’s v5 migration notes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.