Toasts: Notification Messages
What is a Toast?
A toast is a small message that pops up for a few seconds, like the notification when you save a file or send a message. It does not block the page, unlike a modal.
Basic Toast
html
<button class="btn btn-primary" id="showToast">Show toast</button>
<div class="toast-container position-fixed bottom-0 end-0 p-3">
<div id="myToast" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<strong class="me-auto">My App</strong>
<small>just now</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
Your changes were saved.
</div>
</div>
</div>
<script>
document.getElementById('showToast').addEventListener('click', () => {
const toast = new bootstrap.Toast(document.getElementById('myToast'));
toast.show();
});
</script>
Result
Clicking the button shows a small message in the bottom-right corner, which disappears after a few seconds.
Key Points
- Toasts are hidden by default, and you must show them with JavaScript
toast-containerplus position classes place them on the screen- Multiple toasts in one container stack automatically
role="alert"andaria-livehelp screen readers announce the message
Options
| Option | Meaning |
|---|---|
autohide | true by default, hides after the delay |
delay | Time in milliseconds before hiding (default 5000) |
animation | Apply a fade transition |
javascript
const toast = new bootstrap.Toast(el, { delay: 2000, autohide: true });
toast.show();
Colored Toast
html
<div class="toast align-items-center text-bg-success border-0" role="alert">
<div class="d-flex">
<div class="toast-body">Saved successfully!</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"></button>
</div>
</div>
Conclusion
Toasts give friendly feedback without interrupting the user. Use them for success messages and short updates.
Quick Summary: toast-container places toasts, new bootstrap.Toast(el).show() displays them, and delay controls how long they stay.

