HTML code
Clean, semantic HTML that powers this Bootstrap 4.0.0-beta snippet. Copy and paste it into your page (with Bootstrap loaded) to reproduce the exact layout shown in the preview.
Download<div class="row">
<div class="col-sm-12">
<h4>How to create an accordion from scratch</h4>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<h6>Simple Accordion</h6>
<button class="accordion"> Section 1</button>
<div class="panel">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</div>
<button class="accordion"> Section 1</button>
<div class="panel">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</div>
<button class="accordion"> Section 1</button>
<div class="panel">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</div>
</div>
<div class="col-sm-6">
<h6>Animated Accordion (slide Down)</h6>
</div>
</div>CSS code
Scoped CSS that styles the component. Paste it after Bootstrap 4.0.0-beta to keep the design, spacing, and responsiveness consistent.
Downloadbody{margin-top:20px; background: #e6e6ff}
h4, h6{
padding: 10px;
}
/* Simple Accordion Block */
.accordion{
margin: 10px;
background: #3399ff;
border: none;
outline: none;
width: 100%;
transition: 0.4s;
cursor: pointer;
text-align: left;
}
.active, .accrodion:hover{
color: #fff;
background: #0066cc;
}
.panel{
padding: 0px 10px;
}
/* Animated Accordion Block */FAQ
How do I use this snippet?
Include Bootstrap 4.0.0-beta, paste the HTML, add the CSS block, and include the JS (if any) to mirror the live preview.
Can I use it in commercial projects?
Yes. It’s free for personal and commercial work; check the snippets license for details.
Is it responsive?
Yes. It inherits the responsive grid and components from Bootstrap 4.0.0-beta.

About this bootstrap example/template
This free Bootstrap 4.0.0-beta snippet, How to create an accordion from scratch, was published on Jan 6th 2018, 15:10 by Bettaibi Nidhal.
Optimized for copy‑paste: clean HTML, scoped CSS, and minimal JS so you can ship production‑ready UI faster and keep designs consistent.
Mobile‑first and responsive by default. Tested across modern browsers to reduce polish time on your project.
Already trusted in 1.1K+ views. Reuse this snippet to speed up landing pages, dashboards, or onboarding flows.
Bootstrap 4.0.0-beta
<link rel='stylesheet' href='https://netdna.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css'>
<script src='https://netdna.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js'></script>
This code example is based on bootstrap 4.0.0-beta and the grid system of this framework
Responsive
Based on bootstrap framework makes all the layouts perfectly responsive for all devices
Crossbrowser compatibility
Tested on all major browsers, it works smoothly on all of them
semantic html 5
Built on html / css3 the code quality is really amazing
Simple Integration
This code example can be simply integrated on existing sites and new ones too, all you need to do is copy the code and start working