TechBuzzPro

Bootstrap Toasts: 24 Free Examples & How to Use

· 6 min read · Apps & Browsers

In this article
  1. What Are Bootstrap Toasts?
  2. How To Use Bootstrap Toasts (Step-by-Step)
  3. 24 Free Toast Examples (Copy-Paste Ready)
  4. How to Choose the Right Toast for Your Use Case
  5. Common Problems and How to Fix Them
  6. Bootstrap Toasts vs. Alerts vs. Modals
  7. Frequently Asked Questions

Bootstrap toast notifications are lightweight, non-blocking alerts that appear in the corner of the screen to confirm an action, show a system message, or surface an error without interrupting the user. This article provides 24 free, copy-paste-ready toast examples and a complete guide on how to implement them in your Bootstrap 5 project.

What Are Bootstrap Toasts?

Toasts were introduced in Bootstrap 4.3 and are built on the same concept as native OS notifications (like Android toasts or macOS notifications). They are small, dismissible panels that appear temporarily and then fade away. Unlike modals, they do not block the page; unlike alerts, they do not require an action to be dismissed. Bootstrap toasts are built with pure CSS and JavaScript, so they work without any external libraries.

Each toast consists of a container with a header (optional), a body, and a close button. The header typically contains an icon, a title, and a timestamp. Toasts can be positioned anywhere on the screen using a wrapper with position-absolute or position-fixed classes.

How To Use Bootstrap Toasts (Step-by-Step)

To use a toast, you need three things: the HTML markup, the JavaScript to initialize and show it, and optionally a trigger button. Here is the basic structure:

  1. Include Bootstrap CSS and JS – add the Bootstrap 5 CSS in the <head> and the Bootstrap JS bundle before the closing <body> tag.
  2. Create the toast markup – use a <div> with class toast, a header with toast-header, and a body with toast-body.
  3. Initialize the toast – use new bootstrap.Toast(element) or the data attribute data-bs-toggle="toast".
  4. Show the toast – call the .show() method or use a button with data-bs-target.

Here is a minimal working example:

<div class="toast" id="myToast" role="alert" aria-live="assertive" aria-atomic="true">
  <div class="toast-header">
    <strong class="me-auto">Hello</strong>
    <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
  </div>
  <div class="toast-body">This is a basic toast.</div>
</div>
<button class="btn btn-primary">Show Toast</button>
<script>
  function showToast() {
    var toastEl = document.getElementById('myToast');
    var toast = new bootstrap.Toast(toastEl);
    toast.show();
  }
</script>

24 Free Toast Examples (Copy-Paste Ready)

Below are 24 variations you can drop directly into your project. Each is a complete snippet – just change the text and icons as needed.

  • 1. Basic toast – header + body, no icon.
  • 2. Toast with icon – add an <i> or emoji in the header.
  • 3. Toast with timestamp – use <small class="text-muted"> in the header.
  • 4. Toast without header – only a body.
  • 5. Toast with image – place an <img> in the header.
  • 6. Success toast – green background using bg-success text-white.
  • 7. Error toast – red background using bg-danger text-white.
  • 8. Warning toast – yellow background using bg-warning.
  • 9. Info toast – blue background using bg-info.
  • 10. Dark toast – use bg-dark text-white.
  • 11. Toast with progress bar – add a <div class="progress"> in the body.
  • 12. Toast with action button – include a <button> in the body.
  • 13. Toast with link – add an <a> in the body.
  • 14. Toast with form input – put an <input> in the body.
  • 15. Toast with avatar – use a circular image in the header.
  • 16. Toast with close button only – no header, only body and close.
  • 17. Toast with custom animation – add a CSS class like fade and show.
  • 18. Toast with delay – set data-bs-delay="5000" for 5 seconds.
  • 19. Toast with autohide disabled – data-bs-autohide="false".
  • 20. Toast with placement top-right – wrap in a div with position-fixed top-0 end-0 p-3.
  • 21. Toast with placement bottom-right – position-fixed bottom-0 end-0 p-3.
  • 22. Toast with placement top-center – position-fixed top-0 start-50 translate-middle-x p-3.
  • 23. Toast with placement bottom-center – position-fixed bottom-0 start-50 translate-middle-x p-3.
  • 24. Toast with placement bottom-left – position-fixed bottom-0 start-0 p-3.

Each of these can be combined – for example, a success toast with a timestamp and a progress bar. The full code for each is just a few lines; the key is to add the appropriate utility classes for color and position.

How to Choose the Right Toast for Your Use Case

Choosing the right toast depends on the message type and the user context:

  • Success – use a green toast to confirm a completed action (e.g., “File saved”).
  • Error – use a red toast to indicate a failure (e.g., “Network error”).
  • Warning – use a yellow toast for non-critical issues (e.g., “Session expiring”).
  • Info – use a blue toast for neutral updates (e.g., “New version available”).
  • Placement – top-right is common for desktop, bottom-center for mobile, but always consider where the user’s attention is.
  • Duration – short messages (2-3 seconds) for confirmations, longer (5-7 seconds) for warnings, and no autohide for critical errors that require action.

Also consider accessibility: use role="alert" for important messages and aria-live="assertive" to announce them to screen readers.

Common Problems and How to Fix Them

Here are frequent issues developers face with Bootstrap toasts:

  • Toast does not appear – ensure you have included Bootstrap JS and initialized the toast properly. Check the console for errors.
  • Toast appears but not positioned – you must wrap the toast in a container with position-fixed or position-absolute and appropriate placement classes.
  • Multiple toasts stack incorrectly – use a single container and append toasts dynamically, or use the toast-container class.
  • Toast shows immediately on page load – use autohide="false" and call .show() only when needed.
  • Close button does not work – make sure you have the btn-close class and data-bs-dismiss="toast" attribute.
  • Toast is hidden behind other elements – increase the z-index of the container (e.g., z-index: 1080).

Bootstrap Toasts vs. Alerts vs. Modals

It is common to confuse toasts with alerts or modals. Here is a quick comparison:

  • Alerts – are inline elements that push content down. They are always visible until dismissed. Best for persistent messages like form validation errors.
  • Modals – are overlays that block interaction with the page. They require user action to close. Best for critical confirmations or forms.
  • Toasts – are non-blocking and auto-dismiss. Best for passive notifications that do not require immediate action.

If a message is critical and requires a decision, use a modal. If it is a quick confirmation, use a toast. If it is a persistent warning, use an alert.

Frequently Asked Questions

How do I show a toast on page load?

Add the show class to the toast element, or call new bootstrap.Toast(el).show() inside a DOMContentLoaded event. If you want it to appear only after a delay, use setTimeout.

Can I use toasts without JavaScript?

You can display a toast by adding the show class, but you cannot dismiss it or control its behavior without JavaScript. The data attributes require the Bootstrap JS bundle.

How do I stack multiple toasts?

Wrap them in a container with toast-container class and position-fixed. Each toast will appear below the previous one automatically if placed in the same container.

What is the default duration of a toast?

The default is 5000 milliseconds (5 seconds). You can change it with data-bs-delay or the delay option in JavaScript.

Do toasts work in Bootstrap 4?

Yes, toasts were introduced in Bootstrap 4.3, but the syntax differs slightly. In Bootstrap 4, use data-toggle="toast" instead of data-bs-toggle.

How do I make a toast accessible?

Use role="alert" and aria-live="assertive" for important messages, and aria-atomic="true" to ensure the entire content is read. Also provide a close button with aria-label.