All TalkersCode Topics

Follow TalkersCode On Social Media

Cool And Simple Vertical Accordian Menu Using jQuery CSS and HTML

Last Updated : Apr 15, 2022

IN - jQuery CSS HTML

Accordion menu is a great way to display content whenever there is less space in web page user can view all the content simply by clicking on heading tab.

In this tutorial we will create a simple and cool Vertical Accordion Menu using jQuery,CSS and HTML. You may also like html5 toggle menu.

Cool And Simple Vertical Accordian Menu Using jQuery CSS and HTML

To create a Vertical Accordion Menu it takes only two steps:-

  1. Make a HTML file and define markup and script for Accordion Menu
  2. Make a CSS file and define styling for Accordion Menu

Step 1. Make a HTML file and define markup and script for Accordion Menu

We make a HTML file and save it with a name menu.html

<html>
<head>
  <link rel="stylesheet" type="text/css" href="menu_style.css">
  <script type="text/javascript" src="jquery.js"></script>
  <script type="text/javascript">
    function paragraph(id)
    {
	   $("#"+id+"-para").slideToggle();
    }
  </script>
</head>

<body>
  <h1>Accordion Menu Using jQuery And CSS</h1>
  <div>

    <li id="li-one" onclick="paragraph(this.id);">First Para Info</li>
    <p id="li-one-para">
      This is just an example of Simple Accordion
      This is just an example of Simple Accordion
      This is just an example of Simple Accordion
    </p>
	
    <li id="li-two" onclick="paragraph(this.id);">Second Para Info</li>
    <p id="li-two-para">
      This is just an example of Simple Accordion
      This is just an example of Simple Accordion
      This is just an example of Simple Accordion
    </p>

    <li id="li-third" onclick="paragraph(this.id);">Third Para Info</li>
    <p id="li-third-para">
      This is just an example of Simple Accordion
      This is just an example of Simple Accordion
      This is just an example of Simple Accordion
    </p>

    <li id="li-fourth" onclick="paragraph(this.id);">Third Para Info</li>
    <p id="li-fourth-para">
      This is just an example of Simple Accordion
      This is just an example of Simple Accordion
      This is just an example of Simple Accordion
    </p>

  </div>
  
</body>
</html>

In this step we define all the markups for Accordion Menu and we use jQuery slideToggle() function to show and hide the content with animation. You may also like floating navigation menu.

Step 2. Make a CSS file and define styling for Accordion Menu

We make a CSS file and save it with name menu_style.css.

body
{
	background-color:#CED8F6;
	font-family:helvetica;
}
h1
{
	text-align:center;
	color:blue;
	margin-top:100px;
}
div
{
	margin:0px auto; 
	width:250px;
}	
div li
{
	background-color:#2E64FE;
	font-size:20px;
	color:white;
	padding:10px;
	cursor:pointer;
	border:1px solid #A4A4A4;
}
div p
{
	display:none;
	background-color:#F2F2F2;
	color:#585858;
	font-size:18px;
	margin:0px;
	padding:10px;
}

Thats all, this is how to create a Accordion Menu using jQuery,CSS and HTML. You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.

Latest Tutorials