Loading lessons...
Toasts
Toasts
Toasts are small notifications that appear in the corner of the screen, similar to push notifications. They need JavaScript to show and dismiss.
Basic toast
<div class="toast show">
<div class="toast-header">
<strong class="me-auto">Bootstrap</strong>
<button type="button" class="btn-close" data-bs-dismiss="toast"></button>
</div>
<div class="toast-body">
Hello, world! This is a toast message.
</div>
</div>
The key classes
.toastis the base class..toast-headerholds the title and close button..toast-bodyholds the message..showdisplays the toast.data-bs-dismiss="toast"closes it..me-autopushes the close button to the right.
Showing toasts with JavaScript
Toasts usually start hidden. Use JavaScript to show them:
var toastEl = document.getElementById("myToast");
var toast = new bootstrap.Toast(toastEl);
toast.show();
Toast container
Position toasts with a container and utilities. A common pattern places them in the top right:
<div class="position-fixed top-0 end-0 p-3">
<div id="myToast" class="toast" role="alert">
<div class="toast-body">A new message arrived!</div>
</div>
</div>
Options
data-bs-delaysets how long a toast stays visible (in milliseconds).data-bs-autohidecontrols whether the toast hides itself.
TL;DR
- Toasts are small notification boxes.
.toast+.toast-header+.toast-bodybuild one.- Use JavaScript to show and hide them.
position-fixed+top-0+end-0position them in a corner.