Bootstrap 5 Toasts hide() Method Last Updated : 30 Jul, 2024 Comments Improve Suggest changes Like Article Like Report Bootstrap 5 Toasts are a type of alert box that is used to show a message or an update to the user. For example, submitting a form, clicking a button, or maybe a push notification inside the website. The alert box type of toast is shown for a couple of seconds. The hide() method is used to hide the toast from the display.Syntax:toast.hide()Return Value: This method returns to the caller before the toast has actually been hidden.Example 1: The example below demonstrates the usage of the Toasts hide() Method using buttons that hides/closes the toast. HTML <!DOCTYPE html> <html lang="en"> <head> <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity= "sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity= "sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"> </script> </head> <body> <div class="container mt-3"> <h1 class="text-success"> GeeksforGeeks </h1> <h3>Bootstrap 5 Toasts hide() Method</h3> <p class="mt-4"> The button below is used to trigger the toast. </p> <button type="button" class="btn btn-success" id="toastbtn">Show Toast</button> <button type="button" class="btn btn-danger" id="ctoastbtn">Hide Toast</button> <div class="toast"> <div class="toast-header"> <img src= "https://media.geeksforgeeks.org/wp-content/cdn-uploads/gfg_200x200-min.png" class="img-thumbnail rounded me-2" width="40px" alt="GFG Logo"> <strong class="me-auto"> Welcome to GeeksforGeeks </strong> <button type="button" class="btn-close" data-bs-dismiss="toast"></button> </div> <div class="toast-body"> <p>This is a computer science portal for geeks.</p> </div> </div> </div> <script> document.getElementById("toastbtn") .onclick = function () { var toastElList = [].slice.call( document.querySelectorAll('.toast')) var toastList = toastElList.map(function (toastEl) { return new bootstrap.Toast(toastEl) }) toastList.forEach(toast => toast.show()) } document.getElementById("ctoastbtn") .onclick = function () { var toastElList = [].slice.call( document.querySelectorAll('.toast')) var toastList = toastElList.map(function (toastEl) { return new bootstrap.Toast(toastEl) }) toastList.forEach(toast => toast.hide()) } </script> </body> </html> Output: Example 2: The example below demonstrates the usage of the Bootstrap 5 Toasts hide() Method using buttons and with the stacking of the toasts. HTML <!DOCTYPE html> <html lang="en"> <head> <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity= "sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity= "sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"> </script> </head> <body> <div class="container mt-3"> <h1 class="text-success">GeeksforGeeks</h1> <h3>Bootstrap 5 Toasts hide() Method</h3> <p class="mt-4"> The button below is used to trigger the toast. </p> <button type="button" class="btn btn-success mb-3" id="toastbtn-1">Show Toast 1</button> <button type="button" class="btn btn-danger mb-3" id="ctoastbtn-1">Close Toast 1</button> <br> <button type="button" class="btn btn-success" id="toastbtn-2">Show Toast 2</button> <button type="button" class="btn btn-danger" id="ctoastbtn-2">Close Toast 2</button> <div class="toast-container"> <div class="toast" id="toast-1"> <div class="toast-header"> <img src= "https://media.geeksforgeeks.org/wp-content/cdn-uploads/gfg_200x200-min.png" class="img-thumbnail rounded me-2" width="40px" alt="GFG Logo"> <strong class="me-auto"> Welcome to GeeksforGeeks </strong> <button type="button" class="btn-close" data-bs-dismiss="toast"></button> </div> <div class="toast-body"> <p> This is a computer science portal for geeks. </p> </div> </div> <div class="toast" id="toast-2"> <div class="toast-header"> <img src= "https://media.geeksforgeeks.org/wp-content/cdn-uploads/gfg_200x200-min.png" class="img-thumbnail rounded me-2" width="40px" alt="GFG Logo"> <strong class="me-auto"> This is GeeksforGeeks </strong> <button type="button" class="btn-close" data-bs-dismiss="toast"></button> </div> <div class="toast-body"> <p> This is a place to get quality informative articles. </p> </div> </div> </div> </div> <script> document.getElementById("toastbtn-1") .onclick = function () { let toastElList = [].slice.call( document.querySelectorAll('#toast-1')) let toastList = toastElList.map(function (toastEl) { return new bootstrap.Toast(toastEl) }) toastList.forEach(toast => toast.show()) } document.getElementById("toastbtn-2") .onclick = function () { let toastElList = [].slice.call( document.querySelectorAll('#toast-2')) let toastList = toastElList.map(function (toastEl) { return new bootstrap.Toast(toastEl) }) toastList.forEach(toast => toast.show()) } document.getElementById("ctoastbtn-1") .onclick = function () { let toastElList = [].slice.call( document.querySelectorAll('#toast-1')) let toastList = toastElList.map(function (toastEl) { return new bootstrap.Toast(toastEl) }) toastList.forEach(toast => toast.hide()) } document.getElementById("ctoastbtn-2") .onclick = function () { let toastElList = [].slice.call( document.querySelectorAll('#toast-2')) let toastList = toastElList.map(function (toastEl) { return new bootstrap.Toast(toastEl) }) toastList.forEach(toast => toast.hide()) } </script> </body> </html> Output: Reference: https://getbootstrap.com/docs/5.0/components/toasts/#hide Comment More infoAdvertise with us T triashabiswas Follow Improve Article Tags : Web Technologies Bootstrap Bootstrap-5 Similar Reads Bootstrap 5 Toasts Bootstrap 5 Toasts are notifications or messages which the users receive whenever they perform certain actions. They can easily be customized. Overview: Toasts need to be initialized. Apply autohide: false so that the toasts don't automatically hide.Placement: You can place toasts as you want. The t 3 min read Bootstrap 5 Toasts Basic Bootstrap 5 Toasts Basic feature showcases brief alert notifications, resembling mobile and desktop push notifications. It elaborates on fundamental toast functionality, providing a user-friendly way to display important information to users.Bootstrap 5 Toasts Basic Class: No special classes are use 2 min read Bootstrap 5 Toasts Live Bootstrap 5 Toasts Live is used to show the alert notifications. Toasts are brief alerts designed to resemble the push notifications made popular by mobile and desktop operating systems. The Toasts Live feature is used to show a toast in the lower corners of the web page.Toasts Live Classes: No spec 2 min read Bootstrap 5 Toasts Translucent Bootstrap 5 provides the Toasts which are used to show the alert notifications. Toasts are brief alerts designed to resemble the push notifications made popular by mobile and desktop operating systems. The Toast translucent feature is used to be slightly translucent to blend in with the content belo 2 min read Bootstrap 5 Toasts Stacking Bootstrap 5 Toasts Stacking feature is used to wrap multiple toasts in a toast container which will increase the vertical spacing. Toasts Stacking Classes: No special classes are used in Toasts Stacking, you just need to have knowledge of Bootstrap 5 Toasts. Syntax: <div class="toast-container" 2 min read Bootstrap 5 Toasts Custom content Bootstrap 5 Toasts Custom content is used to add your own markup by removing sub-components. Users can easily Customize toasts by adding their own content or by adding other bootstrap components inside toast. There are no predefined classes for toast custom content. You can custom-create them by giv 2 min read Bootstrap 5 Toasts Color Schemes Toasts are a type of alert box that is used to show a message or an update to the user. You can use bootstrap 5 color and background utilities to create different color schemes and customize your toasts. Bootstrap 5 Toasts Color Schemes Classes: We can use the Bootstrap 5 Color classes to color the 2 min read Bootstrap 5 Toasts Placement Bootstrap 5 Toasts which are used to show the alert notifications. Toasts are brief alerts designed to resemble the push notifications made popular by mobile and desktop operating systems. The Toast Placement feature is used to set the position of the toast on the web page. Bootstrap 5 Toasts Placem 4 min read Bootstrap 5 Toasts Accessibility Toasts are the basic push notifications sent to the user its similar to the alert box. To create a basic toast we have to use the class name "toast" inside the toast class we can also add the class "toast-header" and add the header for the toast body, the "toast-body" class can be used. We can also 2 min read Bootstrap 5 Toasts SASS Bootstrap 5 Toasts SASS has a set of variables with default values that can be changed to customize the toasts. Default values of SASS variables of Toasts: $toast-max-width: 350px; $toast-padding-x: 0.75rem; $toast-padding-y: 0.5rem; $toast-font-size: 0.875rem; $toast-color: null; $toast-background- 3 min read Like