In the previous section, I taught you a pretty simple way to use the Collapse component. The same component can be used to create a more complex version, which is the Accordion. Let's take a look at the basic code to create an Accordion:
<div id="accordion">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headerOne">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#sectionOne" aria-expanded="true" aria-controls="sectionOne">
Section #1
</a>
</h4>
</div>
<div id="sectionOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headerOne">
This is the first section.
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headerTwo">
<h4 class="panel-title">
<a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#sectionTwo" aria-expanded="false" aria-controls="sectionTwo">
Section #2
</a>
</h4>
</div>
<div id="sectionTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headerTwo">
This is the second section.
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headerThree">
<h4 class="panel-title">
<a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#sectionThree" aria-expanded="false" aria-controls="sectionThree">
Section #3
</a>
</h4>
</div>
<div id="sectionThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="sectionThree">
This is the third section.
</div>
</div>
</div>
Now that might look like a ton of code, but it's actually a repeating pattern that is pretty easy to put together once you understand it. Let me breakdown everything that is happening here:
<div> with an ID on it. In this case, I'm using #accordion.<div> with a class of .panel on it. I've also included the .panel-default class to just do the most basic styling.<div> with a class of .panel-heading on it. Also include the role attribute with a value of tab and you need to give your header a unique ID, in this case, #headerOne.<h4>, with a class of .panel-title..collapsed is required for the Accordion component.data-toggle is also required.data-parent should be the same ID that you set on the first <div> for the accordion.href will be a link to the body of the section that will be collapsable. In this case, it is called sectionOne.aria-expanded should be set to true because we want this section to be open on page load. The other links should be set to false, unless you want them to be open on page load.aria-controls should also match the ID name of the corresponding section.
<div> with an ID of #sectionOne on it. It should also have a class of .panel-collapse and .collapse on it. Include the attribute role with a value of tabpanel on it. Finally, include aria-labelled by attribute with the value of sectionOne.<div> include the content of the section that you want to display.For the next sections, you need to repeat what you did for the first panel. Simply copy and paste and then you need to change a few things:
headerOne to headerTwosectionOne to sectionTwoDo the same for the third section, and then the Accordion component is done. Once you're done, this is what it should look like in the browser:

That completes the Collapse and Accordion components. We have one more to go, which is the Carousel component.