multi level accordion menu

How we can create multilevel accordion dropdown items? Solution: See this Multi Level Accordion Menu Using jQuery and CSS, Multilevel Dropdown Items.

Previously I have shared some accordion programs, but this is a multi level accordion menu with dropdown items. Basically, accordion is a graphical control element comprising a vertically stacked list of items. Each item can be “expanded” or “collapsed” to show the content associated with that. Mostly we use accordion in the FAQ section because it takes less space and users can see only the answer they want.

Today you will learn to create a Multilevel Dropdown Accordion program. Basically, there are 4 items with title and icon, and 4 items contain some subitems. One of these items has multilevel sub-items, which item contains sub-items that have an arrow icon on the right side. When you will click on that to see sub accordion items, the items will visible and the arrow icons will down facing. There the toggle feature to open and close a list, when you will click on another item then the current item’s dropdown will be closed.

So, Today I am sharing Multi Level Accordion Menu Using jQuery and CSS. There I have used HTML to create the structure, CSS for styling, and jQuery for functioning. It is a JS library that’s why I am putting this post in the JavaScript category. You can use this accordion as a menu in the sidebar, you just have to change text and put links.

If you are thinking now how this accordion menu actually is, then see the preview given below.

Preview Of Multilevel Dropdown Accordion Items

See this video preview to getting an idea of how this accordion looks like.

Live Demo

Now you can see this program visually, also you can see it live by pressing the button given above. If you like this, then get the source code of its.

You May Also Like:

jQuery CSS Multi Level Accordion Menu Source Code

Before sharing source code, let’s talk about it. First I have created the main div with ID name “accordion” and placed lists inside it. I have placed a list to create the accordion items, I have used HTML list tags <ul> & <li>  for creating the multilevel sub-items. There I have used the font-awesome library to place the icons. Also in the HTML file, I have linked external files like CSS, JS, and jQuery CDN.

Now using CSS I have placed all the items in the right place, as you can see in the preview. With CSS I have only done basic works like gave size, position, margin, padding, color values to the elements. There I have used CSS transition command for the animation effect. Also used :after command for placing the arrow to show this item has sub-items.

jQuery handling here the toggle show and hide feature in the program. First, jQuery fetched the list items and active class and stored in variables. After that, used .addClass and .removeClass commands to show and hide items according to action. Left all other things you will understand after getting the codes, I can’t explain all in writing.

For creating this program you have to create 3 files. First file for HTML, second file for CSS, and the third file for JavaScript. Follow the steps to creating this program without any error.

index.html

Create an HTML file named ‘index.html‘ and put these codes given below.

style.css

Now create a CSS file named ‘style.css‘ and put these codes given here.

function.js

The final step, create a JavaScript file named ‘function.js‘ and put the codes.

That’s It. Now you have successfully created Multi Level Accordion Menu Using jQuery and CSS, Multilevel Dropdown Items. If you have any doubt or question comment down below.

Thanks For Visiting, Keep Visiting.

11 COMMENTS

  1. hello, lovely demo, I am trying to tweak it on my side to use this accordeon menu for my RPG games, rather then using tons of paper that is not very organised in game.

    I am a real beginner (started 2 days ago with html) to be honest but trying to tweak the code on Atom by adding sub-menus, changing a few stuff.
    I am more or less advancing… :=)
    I have one or two questions that are probably very basic for you. So for the moment I have worked localy on my PC (Win), I would like to be able to run this mage once made in my browser, on my pc and Android tablet. What should I do?
    Sorry if this seems “stupid”.

  2. Shaan, very nice design !

    For a table of contents navigation, I added a “Collapse All” tab by adding:
    Collapse All
    in the top level block.
    Is it possible to create an “Expand All” tab that would activate all elements ?

  3. Shaan, very nice design !

    For a table of contents navigation, I added a “Collapse All” tab by adding:
    <li><h3><a href=”#”><i class=”fa fa-lg”></i>Collapse All</a></h3></li>
    in the top level block.
    Is it possible to create an “Expand All” tab that would activate all elements ?

  4. Thank you shaan for this nice content, but I have a question.
    Menu works fine when I expand main manus and submenus i.e: “Dashboard”, “Techologies”, “Codes” or “JavaScript”. But when I put a content and make separate htmls for subpages like “Reports”, “Search”, “Tech List” – I would like to stay it open after clicing on the page, but all is automatically collapsing to the first stage. How to make pages open after clicing on them? Many thanks.

  5. Great code! Thank you very much.
    In order to have the menu available even when (for any reason) Javascript is not enabled, I’ve deleted the rule
    #accordian ul ul {display:none;}
    from the css file and have it included via a “document.write” function in the html page soon after the “link stylesheet” lines
    In this way, when JS is not available, the menu is fully opened and all links are available – even if the result is really ugly.
    Whilst, when JS is enabled, the menu runs as in the example.

LEAVE A REPLY

Please enter your comment!
Please enter your name here