html css javascript accordion

Simple HTML, CSS, and JavaScript Accordion Program With Source Code. You must have seen accordion in many websites. Mostly website uses accordion in their FAQ section. This feature is pretty awesome because you can put text or info this these accordion box. But the text will be hidden, when the user wants to see this then it will be visible.

Today you will learn how to create a simple JavaScript accordion program. This program is in pure HTML, CSS, & JavaScript without any libraries or framework. You can use this accordion program on your website. Basically, this program has 3 boxes with texts,  but texts are hidden until you click on the box.

Preview Of This Accordion Program

If you have not idea about accordion lets see a preview, you will be understood the whole system. Then you will realize you had seen this before.

Now, You can see how this program looks. When I click on given tabs then the tabs become expand, & When I click on it again text will hide. This is a simple & clean program, you can use or place is anywhere as you want. If you want the source code of this program, Don’t worry because now time to provide code.

You May Also Like

Source Code Of JavaScript Accordion With HTML and CSS

Before sharing source code, First I want to say you in-depth about this javascript accordion program. I had created 4 divs,  1 main <div> and other 3 divs put on the main div. But the <p> under divs are hidden, when I click on div then the <p> paragraphs become visible using JavaScript. When height increasing there I put CSS transition transition: max-height 0.2s ease-in-out; for the animation effect. ( know about CSS transition )

You have to create 3 files for this program. One file for HTML, One for CSS, & Last file for JavaScript.

index.html

Create an HTML file named ‘index.html‘ or any name as you want & put these codes given below.

style.css

Now create a CSS file named ‘style.css‘ and copy & paste these code.

function.js

The last thing, You have to create a JavaScript file called ‘function.js‘ and put these codes.

That’s It. Now you have a successfully created Javascript accordion program. If you have any doubt or question comment down below.

Thanks For Visiting, Keep Visiting.

18 COMMENTS

  1. I’ve been surfing on-line more than three hours as
    of late, yet I by no means found any fascinating article like yours.
    It is lovely worth sufficient for me. In my view, if all webmasters and bloggers made good content material as you did, the net can be
    much more helpful than ever before. Ahaa, its fastidious conversation about this paragraph at this place at this website, I have read all that, so now me also commenting here.
    I couldn’t refrain from commenting. Very well written!

  2. It’s the best time to make some plans for
    the future and it is time to be happy. I have read this post and if I could I desire to suggest you some
    interesting things or advice. Maybe you could write next articles referring to this article.
    I wish to read more things about it! There’s definately a great deal to
    know about this issue. I really like all of the points you have made.
    I could not refrain from commenting. Perfectly written! http://samsung.com/

  3. Howdy! Someone in my Facebook group shared this website with us so I came to check it out.
    I’m definitely loving the information. I’m book-marking and will be tweeting this to my
    followers! Terrific blog and superb design. I am sure this
    article has touched all the internet people, its really really pleasant article on building up
    new website. It is the best time to make some plans for the
    future and it is time to be happy. I’ve read this publish and if
    I may just I desire to suggest you some attention-grabbing things
    or suggestions. Maybe you could write next articles
    regarding this article. I want to read more things about it!
    http://aoc.com/

  4. Hi, I have been using this accordion for my website. It works well.
    Could you please tell how can we keep a menu in collapsed/expanded state on page refresh? I have 3 accordions having filters inside them. On collapsing first two accordions and using filters on the third one, there is a search query which refreshes the page so my accordions gets expanded. I want the keep the accordions closed if user has collapsed them initially. Could you help.
    Thanks.

  5. Hi Shaan
    I was on your website(Webdevtrick.com) and I came across How to make an Accordian.
    I put all 3 files in a folder and name them as follows:
    1 index.html
    2 style.css
    3 function.js
    But I try to activate nothing happen, only the Html shows up.
    Any suggestion.
    Thanks.

  6. Hi – could you let me know how to keep just one accordion open automatically? I’m new to HTML so I apologize if this is super obvious.

LEAVE A REPLY

Please enter your comment!
Please enter your name here