Toasts are lightweight, non-disruptive push notifications designed to mimic smartphone push alerts. They float in the corner of the viewport (typically top-right or bottom-right), automatically dismiss after a configurable timeout, and stack neatly when multiple notifications arrive.
Place toasts inside a fixed .toast-container positioned at the top-right corner:
<!-- Toast Container (Positioned Top Right) -->
<div class="toast-container position-fixed top-0 end-0 p-3" style="z-index: 1090;">
<div id="liveToast" class="toast" role="alert" aria-live="assertive" aria-atomic="true" data-bs-delay="5000">
<div class="toast-header bg-primary text-white">
<strong class="me-auto"><i class="fa fa-bell"></i> System Notice</strong>
<small>Just now</small>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body bg-white">
Class 33 practice exercises have been unlocked!
</div>
</div>
</div>
<button type="button" class="btn btn-primary" id="toastTriggerBtn">Show Live Toast</button>
<script>
const triggerBtn = document.getElementById('toastTriggerBtn');
const toastEl = document.getElementById('liveToast');
if (triggerBtn) {
triggerBtn.addEventListener('click', () => {
const toast = bootstrap.Toast.getOrCreateInstance(toastEl);
toast.show();
});
}
</script>
Strengthen your responsive web design mastery by studying these connected classes:
Choose between inline persistent alerts and floating auto-dismissing toasts.
Trigger a success toast after a modal form is successfully submitted.
Programmatically create, show, and auto-dismiss toast notifications.
Configure role='status' and aria-live='polite' for screen reader alerts.
data-bs-autohide='false' to the .toast element.
data-bs-delay='8000'.
.toast elements inside a single .toast-container automatically stacks them vertically.
Advance your practical frontend engineering skills with the next topic in our synchronized curriculum.
Continue to Class 34: Spacing (m-* & p-*) → Previous: ← Class 32: Tooltips & Popovers | Full Syllabus