Bootstrap snippet and html example. How to create an accordion from scratch

Bootstrap 4.0.0-beta snippet "How to create an accordion from scratch" with HTML, CSS, and JS. Copy, paste, and customize this responsive UI component for your project.
Tags: accordion,javascript,css,animated accordion,simple accordion,bootstrap accordion,bs4,bs4 accordion

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.

<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.

body{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 */

Similar snippets

Bootstrap example and template. bs4 shop page

bs4 shop page

Bootstrap example and template. Nice modal

Nice modal

Bootstrap example and template. bs4 Task Board page

bs4 Task Board page

Bootstrap example and template. user profile details

user profile details

Bootstrap example and template. project cards

project cards

Bootstrap example and template. Bootstrap accordion Start Templates

Bootstrap accordion Start Templates

Bootstrap example and template. footer with background

footer with background

Bootstrap example and template. edit profile form

edit profile form

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.

Bootstrap example and template. How to create an accordion from scratch

About this bootstrap example/template

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