Bootstrap Tutorial - Bootstrap Accordion








The collapse plugin is also known as an "accordion" plugin on the Web.

Accordion houses multiple vertically stacked tabs, but can open only one tab at a time.

In Bootstrap, a Accordion is created by housing multiple panel components together in a single container.

A panel has two components: the panel-heading and panel-body.

To create a collapse, we need a group of panels contained inside a container.

This container is created using a div element with the class panel-group. It should also have an ID associated with it.

<div class="panel-group" id="accordion"></div>




Example

<!DOCTYPE html>
<html lang="en">
<head>
<script type='text/javascript'
  src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<link rel="stylesheet"
  href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet"
  href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<script
  src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script
  src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</head><!--from  w  w w  . ja  va 2 s.co  m-->
  <body style='margin:30px'>
<div class="panel-group" id="accordion">
    <!-- Panel  1 -->
    <div class="panel panel-default">
        <div class="panel-heading">
            <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
                Collapsible Group  Item #1
                </a>
            </h4>
        </div>
        <div id="collapseOne" class="panel-collapse collapse in">
            <div class="panel-body">
                Lorem  ipsum  dolor  sit amet,  consectetur ...
            </div>
        </div>
    </div>   
    <!-- Panel  2 -->
    <div class="panel panel-default">
        <div class="panel-heading">
            <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion"
                    href="#collapseTwo">
                Collapsible Group  Item #2
                </a>
            </h4>
        </div>
        <div id="collapseTwo" class="panel-collapse collapse">
            <div class="panel-body">
                Lorem  ipsum  dolor  sit amet,  consectetur ...
            </div>
        </div>
    </div>
    <!-- Panel  3 -->
    <div class="panel panel-default">
        <div class="panel-heading">
            <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion"
                    href="#collapseThree">
                Collapsible Group  Item #3
                </a>
            </h4>
        </div>
        <div id="collapseThree" class="panel-collapse collapse">
            <div class="panel-body">
                Lorem  ipsum  dolor  sit amet,  consectetur ...
            </div>
        </div>
    </div>
</div>



  </body>
</html>

Click to view the demo