Lesson 26: Toast in Bootstrap 5

Toast is also a fun component, similar to notifications on websites and apps. Here's how to create a toast in Bootstrap 5.

Toast is also a fun component, similar to notifications on websites and apps. Here's how to create a toast in Bootstrap 5 .

 

What is toast on the web?

A toast is a component similar to an alert box, but it only appears for a few seconds when something happens. For example, when a user clicks a button, submits a form, etc.

How to create a toast in Bootstrap 5

To create a toast, use the class and .toastadd it inside..toast-header.toast-body

Note: The toast is hidden by default. Use the class .showif you want to show it. To close it, use the element.and add data-bs-dismiss="toast":

 Toast Header  Some text inside the toast body 

For example:

 Bootstrap Example 

Example of toast on TipsMake.com.com

Toast is like a quick notification box, appearing for only a few seconds when a particular task occurs.

This example uses .show to default to always displaying the toast. Close it by clicking the x in the toast header.

 QuanTriMang.com 

The leading technology news channel in Vietnam.

 

Picture 1 of Lesson 26: Toast in Bootstrap 5

Open a toast

To display a quick toast alert with a single button click, you must launch it using JavaScript: select the specified element and call the toast() method .

The following code will display all toasts in the document when you click a button:

 

For example:

 Bootstrap Example 

Examples of toast

This example uses a button to display the toast.

  TipsMake.com 

Welcome to QuanTriMang.com

Picture 2 of Lesson 26: Toast in Bootstrap 5

Above are the things you need to know about creating toasts in Bootstrap 5. It's quite similar to a tooltip or notification box, but it only displays for a few seconds. Hopefully, this Bootstrap tutorial is helpful to you.

You've just finished reading the article "Lesson 26: Toast in Bootstrap 5" edited by the TipsMake team. You can save lesson-26-toast-in-bootstrap-lyola.pdf to your computer here to read later or print it out. We hope this article has provided you with many useful tech tips and tricks. You can search for similar articles on tips and guides. Thank you for reading and for following us regularly.

« PREV Lesson 25: Popovers in Bootstrap 5
NEXT » Lesson 27: Scrollspy in Bootstrap 5