Toasts
Push notifications to your visitors with a toast, a lightweight and easily customizable alert message.
Bootstrap Toasts documentationBasic example
Bob Dean
11 mins ago
Hello, world! This is a toast message.
<!-- Toast -->
<div class="toast toast-show fade show" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<div class="d-flex align-items-center flex-grow-1">
<div class="flex-shrink-0">
<img class="avatar avatar-sm avatar-circle" src="../assets/img/160x160/img4.jpg" alt="图片描述内容">
</div>
<div class="flex-grow-1 ms-3">
<h5 class="mb-0">Bob Dean</h5>
<small class="ms-auto">11 mins ago</small>
</div>
<div class="text-end">
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
</div>
<div class="toast-body">
Hello, world! This is a toast message.
</div>
</div>
<!-- End Toast -->
Live
Click the button the below to show as toast (positioning with our utilities in the lower right corner) that has been hidden by default with .hide
.
Bob Dean
11 mins ago
Hello, world! This is a toast message.
<!-- Toast Luncher -->
<button id="liveToastBtn" class="btn btn-primary">Toast</button>
<!-- Toast -->
<div id="liveToast" class="position-fixed toast hide" role="alert" aria-live="assertive" aria-atomic="true" style="top: 20px; right: 20px; z-index: 1000;">
<div class="toast-header">
<div class="d-flex align-items-center flex-grow-1">
<div class="flex-shrink-0">
<img class="avatar avatar-sm avatar-circle" src="../assets/img/160x160/img4.jpg" alt="图片描述内容">
</div>
<div class="flex-grow-1 ms-3">
<h5 class="mb-0">Bob Dean</h5>
<small class="ms-auto">11 mins ago</small>
</div>
<div class="text-end">
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
</div>
<div class="toast-body">
Hello, world! This is a toast message.
</div>
</div>
<!-- End Toast -->
<script>
// INITIALIZATION OF LIVE TOAST
// =======================================================
const liveToast = new bootstrap.Toast(document.querySelector('#liveToast'))
document.querySelector('#liveToastBtn').addEventListener('click', () => liveToast.show())
</script>
Stacking
When you have multiple toasts, we default to vertically stacking them in a readable manner.
Bob Dean
11 mins ago
See? Just like this.
Ella Lauda
20 mins ago
Heads up, toasts will stack automatically
<div class="toast-container">
<!-- Toast -->
<div class="toast toast-show fade show" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<div class="d-flex align-items-center flex-grow-1">
<div class="flex-shrink-0">
<img class="avatar avatar-sm avatar-circle" src="../assets/img/160x160/img4.jpg" alt="图片描述内容">
</div>
<div class="flex-grow-1 ms-3">
<h5 class="mb-0">Bob Dean</h5>
<small class="ms-auto">11 mins ago</small>
</div>
<div class="text-end">
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
</div>
<div class="toast-body">
See? Just like this.
</div>
</div>
<!-- End Toast -->
<!-- Toast -->
<div class="toast toast-show fade show" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<div class="d-flex align-items-center flex-grow-1">
<div class="flex-shrink-0">
<img class="avatar avatar-sm avatar-circle" src="../assets/img/160x160/img9.jpg" alt="图片描述内容">
</div>
<div class="flex-grow-1 ms-3">
<h5 class="mb-0">Ella Lauda</h5>
<small class="ms-auto">20 mins ago</small>
</div>
<div class="text-end">
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
</div>
<div class="toast-body">
Heads up, toasts will stack automatically
</div>
</div>
<!-- End Toast -->
</div>
Placement
Place toasts with custom CSS as you need them. The top right is often used for notifications, as is the top middle. If you’re only ever going to show one toast at a time, put the positioning styles right on the .toast
.
Bob Dean
11 mins ago
Hello, world! This is a toast message.
<!-- Toast -->
<div aria-live="polite" aria-atomic="true" style="position: relative; min-height: 200px;">
<div class="toast toast-show fade show" role="alert" aria-live="assertive" aria-atomic="true" style="position: absolute; top: 0; right: 0;">
<div class="toast-header">
<div class="d-flex align-items-center flex-grow-1">
<div class="flex-shrink-0">
<img class="avatar avatar-sm avatar-circle" src="../assets/img/160x160/img4.jpg" alt="图片描述内容">
</div>
<div class="flex-grow-1 ms-3">
<h5 class="mb-0">Bob Dean</h5>
<small class="ms-auto">11 mins ago</small>
</div>
<div class="text-end">
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
</div>
<div class="toast-body">
Hello, world! This is a toast message.
</div>
</div>
</div>
<!-- End Toast -->