Accordion.JS is lightweight, easily configurable and multilevel supported responsive accordion plugin. The plugin is automatically adjustable on mobile devices no extra coding is required for mobile devices. It will work perfectly on all mobile devices and browsers. It can be configured directly using options and HTML5 data-* attributes.

Features:

Install with npm

npm install accordionjs --save

Install with yarn

yarn add accordionjs

How to use it:

1. Include the Javascript accordion.min.js at the bottom of the web page.

<script src="path/to/accordion.min.js"></script>

2. Include the CSS accordion.css in the header of the page.

<link rel="stylesheet" href="path/to/accordion.css">

3. Add the basic HTML to the page.

<ul id="my-accordion" class="accordionjs">

    <!-- Section 1 -->
    <li>
        <div>Section 1 title</div>
        <div>
            <!-- Section content here. -->
        </div>
    </li>

    <!-- Section 2 -->
    <li>
        <div>Section 2 title</div>
        <div>
            <!-- Section content here. -->
        </div>
    </li>

    <!-- Section 3 -->
    <li>
        <div>Section 3 title</div>
        <div>
            <!-- Section content here. -->
        </div>
    </li>

</ul>

4. Initialize the plugin and we're ready to go.

jQuery(document).ready(function($){
  $("#my-accordion").accordionjs();
});

Plugin's default options:

Name Default Description
closeAble false Allow self close.(data-close-able)
closeOther true Close other sections.(data-close-other)
slideSpeed 150 Animation Speed.(data-slide-speed)
activeIndex 1 The section open on first init. A number from 1 to X or false.(data-active-index)
openSection function( section ){} Callback when a section is open
beforeOpenSection function( section ){} Callback before a section is open
$("#my-accordion").accordionjs({
    closeAble   : false,
    closeOther  : true,
    slideSpeed  : 150,
    activeIndex : 1,
    openSection: function( section ){},
    beforeOpenSection: function( section ){},
});

Default example

  • Section 1 title
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  • Section 2 title
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  • Section 3 title
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

HTML structure

<ul class="demo-accordion accordionjs">

    <!-- Section 1 -->
    <li>
        <div>Section 1 title</div>
        <div>
            <!-- Section content here. -->
        </div>
    </li>

    <!-- Section 2 -->
    <li>
        <div>Section 2 title</div>
        <div>
            <!-- Section content here. -->
        </div>
    </li>

    <!-- Section 3 -->
    <li>
        <div>Section 3 title</div>
        <div>
            <!-- Section content here. -->
        </div>
    </li>

</ul>

Script

jQuery(document).ready(function($){
   $(".demo-accordion").accordionjs();
});

Second section active

  • Section 1 title
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  • Section 2 title
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  • Section 3 title
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

HTML structure

<ul class="demo-accordion accordionjs" data-active-index="2">

    <!-- Section 1 -->
    <li>
        <div>Section 1 title</div>
        <div>
            <!-- Section content here. -->
        </div>
    </li>

    <!-- Section 2 -->
    <li>
        <div>Section 2 title</div>
        <div>
            <!-- Section content here. -->
        </div>
    </li>

    <!-- Section 3 -->
    <li>
        <div>Section 3 title</div>
        <div>
            <!-- Section content here. -->
        </div>
    </li>

</ul>

Script

jQuery(document).ready(function($){
   $(".demo-accordion").accordionjs();
});

No active section

  • Section 1 title
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  • Section 2 title
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  • Section 3 title
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

HTML structure

<ul class="demo-accordion accordionjs" data-active-index="false">

    <!-- Section 1 -->
    <li>
        <div>Section 1 title</div>
        <div>
            <!-- Section content here. -->
        </div>
    </li>

    <!-- Section 2 -->
    <li>
        <div>Section 2 title</div>
        <div>
            <!-- Section content here. -->
        </div>
    </li>

    <!-- Section 3 -->
    <li>
        <div>Section 3 title</div>
        <div>
            <!-- Section content here. -->
        </div>
    </li>

</ul>

Script

jQuery(document).ready(function($){
   $(".demo-accordion").accordionjs();
});

Nested accordions

  • Section 1 title
    • Section 1
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
    • Section 2
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
    • Section 3
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
  • Section 2 title
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  • Section 3 title
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

HTML structure

<ul class="demo-accordion accordionjs">

    <!-- Section 1 -->
    <li>
        <div>Section 1 title</div>
        <div>
          <ul class="demo-accordion accordionjs">
            <li>
              <div>Nested Section 1</div>
              <div>
                <!-- Nested content here. -->
              </div>
            </li>
            <li>
              <div>Nested Section 2</div>
              <div>
                <!-- Nested content here. -->
              </div>
            </li>
            <li>
              <div>Nested Section 3</div>
              <div>
                <!-- Nested content here. -->
              </div>
            </li>
          </ul>
        </div>
    </li>

    <!-- Section 2 -->
    <li>
        <div>Section 2 title</div>
        <div>
            <!-- Section content here. -->
        </div>
    </li>

    <!-- Section 3 -->
    <li>
        <div>Section 3 title</div>
        <div>
            <!-- Section content here. -->
        </div>
    </li>

</ul>

Script

jQuery(document).ready(function($){
   $(".demo-accordion").accordionjs();
});

Multiple sections open by default

  • Section 1 title
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  • Section 2 title
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  • Section 3 title
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

HTML structure

<ul class="demo-accordion accordionjs" data-active-index="[1, 3]">

    <!-- Section 1 -->
    <li>
        <div>Section 1 title</div>
        <div>
            <!-- Section content here. -->
        </div>
    </li>

    <!-- Section 2 -->
    <li>
        <div>Section 2 title</div>
        <div>
            <!-- Section content here. -->
        </div>
    </li>

    <!-- Section 3 -->
    <li>
        <div>Section 3 title</div>
        <div>
            <!-- Section content here. -->
        </div>
    </li>

</ul>

Script

jQuery(document).ready(function($){
   $(".demo-accordion").accordionjs();
});