Push notifications to your visitors with a toast, a lightweight and easily customizable
alert message.
Examples
Basic
To encourage extensible and predictable toasts, we recommend a header and body. Toast headers use
display: flex, allowing easy alignment of content thanks to our margin and flexbox
utilities.
Toasts are as flexible as you need and have very little required markup. At a minimum, we require a
single element to contain your “toasted” content and strongly encourage a dismiss button.
Bootstrap
11 mins ago
Hello, world! This is a toast message.
<divclass="toast"role="alert"aria-live="assertive"aria-atomic="true"><divclass="toast-header"><imgsrc="..."class="rounded me-2"alt="..."><strongclass="me-auto">Bootstrap</strong><small>11 mins ago</small><buttontype="button"class="btn-close"data-bs-dismiss="toast"aria-label="Close"></button></div><divclass="toast-body">
Hello, world! This is a toast message.
</div></div>
Translucent
Toasts are slightly translucent, too, so they blend over whatever they might appear over. For
browsers that support the backdrop-filter CSS property, we’ll also attempt to blur the
elements under a toast.
Bootstrap
11 mins ago
Hello, world! This is a toast message.
<divclass="toast"role="alert"aria-live="assertive"aria-atomic="true"><divclass="toast-header"><imgsrc="..."class="rounded me-2"alt="..."><strongclass="me-auto">Bootstrap</strong><smallclass="text-muted">11 mins ago</small><buttontype="button"class="btn-close"data-bs-dismiss="toast"aria-label="Close"></button></div><divclass="toast-body">
Hello, world! This is a toast message.
</div></div>
Stacking
You can stack toasts by wrapping them in a toast container, which will vertically add some
spacing.
Bootstrap
just now
See? Just like this.
Bootstrap
2 seconds ago
Heads up, toasts will stack automatically
<divclass="toast-container"><divclass="toast"role="alert"aria-live="assertive"aria-atomic="true"><divclass="toast-header"><imgsrc="..."class="rounded me-2"alt="..."><strongclass="me-auto">Bootstrap</strong><smallclass="text-muted">just now</small><buttontype="button"class="btn-close"data-bs-dismiss="toast"aria-label="Close"></button></div><divclass="toast-body">
See? Just like this.
</div></div><divclass="toast"role="alert"aria-live="assertive"aria-atomic="true"><divclass="toast-header"><imgsrc="..."class="rounded me-2"alt="..."><strongclass="me-auto">Bootstrap</strong><smallclass="text-muted">2 seconds ago</small><buttontype="button"class="btn-close"data-bs-dismiss="toast"aria-label="Close"></button></div><divclass="toast-body">
Heads up, toasts will stack automatically
</div></div></div>
Custom content
Customize your toasts by removing sub-components, tweaking with utilities, or adding your own markup.
Here we’ve created a simpler toast by removing the default .toast-header, adding a
custom hide icon
from Bootstrap Icons, and using some flexbox utilities to adjust the layout.
Hello, world! This is a toast message.
<divclass="toast d-flex align-items-center"role="alert"aria-live="assertive"aria-atomic="true"><divclass="toast-body">
Hello, world! This is a toast message.
</div><buttontype="button"class="btn-close ms-auto me-2"data-bs-dismiss="toast"aria-label="Close"></button></div>
Alternatively, you can also add additional controls and components to toasts.
Hello, world! This is a toast message.
<divclass="toast"role="alert"aria-live="assertive"aria-atomic="true"><divclass="toast-body">
Hello, world! This is a toast message.
<divclass="mt-2 pt-2 border-top"><buttontype="button"class="btn btn-primary btn-sm">Take action</button><buttontype="button"class="btn btn-secondary btn-sm"data-bs-dismiss="toast">Close</button></div></div></div>
Color schemes
Building on the above example, you can create different toast color schemes with our color utilities.
Here we’ve added
.bg-primary and .text-white to the .toast, and then added
.text-white to our close button. For a crisp edge, we remove the default border with
.border-0.
Hello, world! This is a toast message.
<divclass="toast d-flex align-items-center text-white bg-primary border-0"role="alert"aria-live="assertive"aria-atomic="true"><divclass="toast-body">
Hello, world! This is a toast message.
</div><buttontype="button"class="btn-close btn-close-white ms-auto me-2"data-bs-dismiss="toast"aria-label="Close"></button></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.
Bootstrap
11 mins ago
Hello, world! This is a toast message.
<form><divclass="form-group mb-3"><labelfor="selectToastPlacement">Toast placement</label><selectclass="form-select mt-2"id="selectToastPlacement"><optionvalue=""selected>Select a position...</option><optionvalue="top-0 start-0">Top left</option><optionvalue="top-0 start-50 translate-middle-x">Top center</option><optionvalue="top-0 end-0">Top right</option><optionvalue="top-50 start-0 translate-middle-y">Middle left</option><optionvalue="top-50 start-50 translate-middle">Middle center</option><optionvalue="top-50 end-0 translate-middle-y">Middle right</option><optionvalue="bottom-0 start-0">Bottom left</option><optionvalue="bottom-0 start-50 translate-middle-x">Bottom center</option><optionvalue="bottom-0 end-0">Bottom right</option></select></div></form><divaria-live="polite"aria-atomic="true"class="bg-dark position-relative bd-example-toasts"><divclass="toast-container position-absolute p-3"id="toastPlacement"><divclass="toast"><divclass="toast-header"><imgsrc="..."class="rounded me-2"alt="..."><strongclass="me-auto">Bootstrap</strong><small>11 mins ago</small></div><divclass="toast-body">
Hello, world! This is a toast message.
</div></div></div></div>
For systems that generate more notifications, consider using a wrapping element so they can easily stack.
Bootstrap
just now
See? Just like this.
Bootstrap
2 seconds ago
Heads up, toasts will stack automatically
<divaria-live="polite"aria-atomic="true"class="position-relative"><!-- Position it: --><!-- - `.toast-container` for spacing between toasts --><!-- - `.position-absolute`, `top-0` & `end-0` to position the toasts in the upper right corner --><!-- - `.p-3` to prevent the toasts from sticking to the edge of the container --><divclass="toast-container position-absolute top-0 end-0 p-3"><!-- Then put toasts within --><divclass="toast"role="alert"aria-live="assertive"aria-atomic="true"><divclass="toast-header"><imgsrc="..."class="rounded me-2"alt="..."><strongclass="me-auto">Bootstrap</strong><smallclass="text-muted">just now</small><buttontype="button"class="btn-close"data-bs-dismiss="toast"aria-label="Close"></button></div><divclass="toast-body">
See? Just like this.
</div></div><divclass="toast"role="alert"aria-live="assertive"aria-atomic="true"><divclass="toast-header"><imgsrc="..."class="rounded me-2"alt="..."><strongclass="me-auto">Bootstrap</strong><smallclass="text-muted">2 seconds ago</small><buttontype="button"class="btn-close"data-bs-dismiss="toast"aria-label="Close"></button></div><divclass="toast-body">
Heads up, toasts will stack automatically
</div></div></div></div>
You can also get fancy with flexbox utilities to align toasts horizontally and/or vertically.
Bootstrap
11 mins ago
Hello, world! This is a toast message.
<!-- Flexbox container for aligning the toasts --><divaria-live="polite"aria-atomic="true"class="d-flex justify-content-center align-items-center w-100"><!-- Then put toasts within --><divclass="toast"role="alert"aria-live="assertive"aria-atomic="true"><divclass="toast-header"><imgsrc="..."class="rounded me-2"alt="..."><strongclass="me-auto">Bootstrap</strong><small>11 mins ago</small><buttontype="button"class="btn-close"data-bs-dismiss="toast"aria-label="Close"></button></div><divclass="toast-body">
Hello, world! This is a toast message.
</div></div></div>