How to create an accordion from scratch

Bootstrap snippet. How to create an accordion from scratch, this snippet was created to help web designers,
front-end developers and back-end developer save time. Use it in your project and build your app faster,
You can also download the HTML, CSS, and JS code.
tags: accordion,javascript,css,animated accordion,simple accordion,bootstrap accordion,bs4,bs4 accordion

HTML code

Copy, paste, change, customize and run the following HTML code to get a result like the one shown in the preview selection

<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

Copy, paste, change, customize and run the following CSS code to get a result Like the one shown in the preview selection

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 snippet bs4 Accordion form Wizard

bs4 Accordion form Wizard

View

Bootstrap snippet bs4 profile detail page

bs4 profile detail page

View

Bootstrap snippet bs4 social profile

bs4 social profile

View

About this snippet

Creator: Bettaibi Nidhal

Bootstrap version: 4.0.0-beta

Created: Jan 6th 2018, 15:10

Views: 175