Bootstrap, a popular CSS framework, simplifies responsive web development by providing pre-defined classes and components. One such component is the toast, a lightweight notification that appears briefly at the bottom of the screen. Let's explore a Bootstrap toast example using CodePen, a web development editor that allows real-time collaboration and sharing.

Before diving into the CodePen example, ensure you have a basic understanding of Bootstrap's grid system and components. Familiarize yourself with the Bootstrap documentation to grasp the framework's fundamentals.

Setting Up the Bootstrap Toast Example on CodePen
To get started, sign up for a free CodePen account and create a new Pen. CodePen provides a simple, three-panel interface: the editor (HTML, CSS, and JavaScript), the preview, and the settings panel.

For this example, we'll use the Bootstrap 5 CDN links provided by the Bootstrap official website. Add the following lines in the
section of the HTML panel:```html ```
Creating the Toast Notification

Now, let's create a simple toast notification using Bootstrap's toast component. In the HTML panel, add the following code within the
section:```html
In this example, we've created a button that triggers the toast notification. The toast itself is hidden by default and positioned at the bottom-right corner of the screen. The toast header contains the title and a close button, while the toast body holds the notification message.
Initializing the Toast and Adding Event Listener

Next, we'll initialize the toast using JavaScript and add an event listener to the button. In the JavaScript panel, add the following code:
```javascript const toastTrigger = document.getElementById('showToastBtn') const toastLiveExample = document.getElementById('liveToast') if (toastTrigger) { toastTrigger.addEventListener('click', () => { const toast = new bootstrap.Toast(toastLiveExample) toast.show() }) } ```
Here, we're selecting the button and toast elements using their IDs. When the button is clicked, we create a new toast instance and call the show() method to display the toast.
Customizing the Toast Notification

Bootstrap toasts are highly customizable. You can change their appearance, delay, and behavior using various options and data attributes. Let's explore some customization options.
Changing the Toast Header and Body




















To modify the toast header and body content, simply update the toast-header and toast-body elements in the HTML. For example, change the title and message as follows:
```html
Adjusting the Toast Delay and Autohiding
By default, toasts are displayed for 5 seconds and then automatically hide. You can adjust the delay or prevent the toast from hiding automatically using the data-bs-delay and data-bs-autohide attributes. Update the toast element as follows:
```html
```In this example, the toast will remain visible for 3 seconds (3000 milliseconds) and won't hide automatically. To hide the toast manually, add an event listener for the close button:
```javascript document.querySelector('.toast .btn-close').addEventListener('click', () => { toastLiveExample.classList.add('hide') }) ```
Now that you've learned how to create and customize Bootstrap toasts using CodePen, you can integrate this functionality into your web projects. Experiment with different toast options and data attributes to create engaging and informative notifications for your users.
Happy coding! Don't forget to share your Bootstrap toast creations on CodePen and showcase your skills to the web development community.