WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Bootstrap 4 - Collapse


Add collapsible content material effortlessly with Bootstrap's .Fall apart and related lessons.

You could make your content collapsible by way of adding information-toggle="crumble" to both a button or a hyperlink.

The button or hyperlink references the ID of the content material to collapse.

Collapse the usage of Link

You can crumble the content with <a> tag by the usage of href value of the ID of the content to collapse.

The following example demonstrates this −

Example

<html lang = "en">
   <head>
      <!-- Meta tags -->
      <meta charset = "utf-8">
      <meta call = "viewport" content material = "width = device-width, initial-scale = 1, cut back-to-healthy = no">
      
      <!-- Bootstrap CSS -->
      <link rel = "stylesheet" 
         href = "https://stackpath.Bootstrapcdn.Com/bootstrap/4.1.3/css/bootstrap.Min.Css" 
         integrity = "sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" 
         crossorigin = "nameless">
      
      <name>Bootstrap four Example</title>
   </head>
   
   <frame>
      <div class = "field">
         <h2>Collapse with Link</h2>
         <p>
            <a elegance = "btn btn-info" records-toggle = "crumble" 
               href = "#collapsewithlink" position = "button" aria-accelerated = "fake" 
               aria-controls = "collapsewithlink">Click Me</a>
         </p>
         
         <div class = "disintegrate" identity = "collapsewithlink">
            <div elegance = "card card-body">
               Lorem ipsum dolor take a seat amet, consectetur adipiscing elit, sed do eiusmod 
               tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim 
               veniam, quis nostrud exercitation.
            </div>
         </div>
      </div>
      
      <!-- jQuery first, then Popper.Js, then Bootstrap JS -->
      <script src = "https://code.Jquery.Com/jquery-three.Three.1.Narrow.Min.Js" 
         integrity = "sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" 
         crossorigin = "nameless">
      </script>
      
      <script src = "https://cdnjs.Cloudflare.Com/ajax/libs/popper.Js/1.14.3/umd/popper.Min.Js" 
         integrity = "sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" 
         crossorigin = "nameless">
      </script>
      
      <script src = "https://stackpath.Bootstrapcdn.Com/bootstrap/four.1.3/js/bootstrap.Min.Js" 
         integrity = "sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" 
         crossorigin = "nameless">
      </script>
      
   </frame>
</html>
It will produce the subsequent result −

Output

Collapse the use of Button

You can disintegrate the content material with <button> tag via the usage of facts-goal attribute with cost of the ID of the content to crumble.

The following instance demonstrates this −

Example

<html lang = "en">
   <head>
      <!-- Meta tags -->
      <meta charset = "utf-8">
      <meta call = "viewport" content = "width = tool-width, preliminary-scale = 1, cut back-to-healthy = no">
      
      <!-- Bootstrap CSS -->
      <hyperlink rel = "stylesheet" 
         href = "https://stackpath.Bootstrapcdn.Com/bootstrap/four.1.Three/css/bootstrap.Min.Css"
         integrity = "sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" 
         crossorigin = "anonymous">
      <title>Bootstrap four Example</title>
   </head>
   
   <frame>
      <div elegance = "box">
         <h2>Collapse with Button</h2>
         <p>
            <button class = "btn btn-indo" type = "button" records-toggle = "fall apart" 
               information-goal = "#collapsewithbutton" aria-multiplied = "false" 
               aria-controls = "collapsewithbutton">Click Me</button>
         </p>
         
         <div magnificence = "crumble" identity = "collapsewithbutton">
            <div class = "card card-frame">
               Lorem ipsum dolor take a seat amet, consectetur adipiscing elit, sed do eiusmod 
               tempor incididunt ut labore et dolore magna aliqua. Ut enim advert minim 
               veniam, quis nostrud exercitation.
            </div>
         </div>
      </div>
      
      <!-- jQuery first, then Popper.Js, then Bootstrap JS -->
      <script src = "https://code.Jquery.Com/jquery-3.3.1.Slim.Min.Js" 
         integrity = "sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" 
         crossorigin = "nameless">
      </script>
      
      <script src = "https://cdnjs.Cloudflare.Com/ajax/libs/popper.Js/1.14.3/umd/popper.Min.Js" 
         integrity = "sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" 
         crossorigin = "nameless">
      </script>
      
      <script src = "https://stackpath.Bootstrapcdn.Com/bootstrap/four.1.3/js/bootstrap.Min.Js" 
         integrity = "sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" 
         crossorigin = "nameless">
      </script>
      
   </body>
</html>

It will produce the subsequent end result −

Output

Accordion

You can use collapsible content material to make an accordion which is regularly used for content material which include FAQs, overviews, etc.

The beneath instance specifies a simple accordion via extending the cardboard element −

Example

<html lang = "en">
   <head>
      <!-- Meta tags -->
      <meta charset = "utf-8">
      <meta call = "viewport" content = "width = device-width, initial-scale = 1, shrink-to-fit = no">
      
      <!-- Bootstrap CSS -->
      <hyperlink rel = "stylesheet" 
         href = "https://stackpath.Bootstrapcdn.Com/bootstrap/four.1.3/css/bootstrap.Min.Css" 
         integrity = "sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" 
         crossorigin = "nameless">
      
      <title>Bootstrap 4 Example</title>
   </head>
   
   <body>
      <div magnificence = "field">
         <h2>Accordion </h2>
         <div identification = "accordion">
            <div elegance = "card">
               <div elegance = "card-header">
                  <a magnificence = "card-hyperlink" data-toggle = "disintegrate" href = "#collapseOne">
                     Accordion #1
                  </a>
               </div>
               
               <div identity = "collapseOne" magnificence = "collapse display" facts-determine = "#accordion">
                  <div magnificence = "card-frame">Content for Accordion #1.</div>
               </div>
            </div>
            
            <div magnificence = "card">
               <div elegance = "card-header">
                  <a class = "collapsed card-hyperlink" information-toggle = "fall apart" href = "#collapseTwo">
                     Accordion #2
                  </a>
               </div>
               
               <div identification = "collapseTwo" elegance = "fall apart" statistics-figure = "#accordion">
                  <div magnificence = "card-body">Content for Accordion #2.</div>
               </div>
            </div>
            
            <div class = "card">
               <div elegance = "card-header">
                  <a elegance = "collapsed card-hyperlink" facts-toggle = "disintegrate" href = "#collapseThree">
                     Accordion #3
                  </a>
               </div>
               
               <div identity = "collapseThree" magnificence = "crumble" statistics-parent = "#accordion">
                  <div magnificence = "card-body"> Content for Accordion #three.</div>
               </div>
            </div>
            
         </div>
      </div>
    
      <!-- jQuery first, then Popper.Js, then Bootstrap JS -->
      <script src = "https://code.Jquery.Com/jquery-three.3.1.Slim.Min.Js" 
         integrity = "sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" 
         crossorigin = "nameless">
      </script>
      
      <script src = "https://cdnjs.Cloudflare.Com/ajax/libs/popper.Js/1.14.Three/umd/popper.Min.Js" 
         integrity = "sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" 
         crossorigin = "anonymous">
      </script>
      
      <script src = "https://stackpath.Bootstrapcdn.Com/bootstrap/4.1.3/js/bootstrap.Min.Js" 
         integrity = "sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" 
         crossorigin = "anonymous">
      </script>
      
   </frame>
</html>

It will produce the following result −

Output