How TO - Collapsibles/Accordion
How TO - Collapsibles/Accordion
asp
How TO - Collapsibles/Accordion
❮ Previous Next ❯
Accordion
Accordions are useful when you want to toggle between hiding and showing large
amount of content:
Section 1 +
Section 2 +
Section 3 +
Try it Yourself »
1 of 8 1/25/2022, 11:43 PM
How To Create an Accordion https://www.w3schools.com/howto/howto_js_accordion.asp
Example
Example
/* Style the buttons that are used to open and close the accordion panel */
.accordion {
background-color: #eee;
color: #444;
cursor: pointer;
padding: 18px;
width: 100%;
text-align: left;
2 of 8 1/25/2022, 11:43 PM
How To Create an Accordion https://www.w3schools.com/howto/howto_js_accordion.asp
border: none;
HTML
outline: none;
CSS JAVASCRIPT SQL
transition: 0.4s;
}
Example
3 of 8 1/25/2022, 11:43 PM
How To Create an Accordion https://www.w3schools.com/howto/howto_js_accordion.asp
} else {
HTML CSS JAVASCRIPT
panel.style.display = "block";
SQL
}
});
}
Try it Yourself »
Then, use JavaScript to slide down the content by setting a calculated max-height ,
depending on the panel's height on different screen sizes:
Example
<style>
.panel {
padding: 0 18px;
background-color: white;
max-height: 0;
overflow: hidden;
transition: max-height 0.2s ease-out;
}
</style>
<script>
var acc = document.getElementsByClassName("accordion");
var i;
4 of 8 1/25/2022, 11:43 PM
How To Create an Accordion https://www.w3schools.com/howto/howto_js_accordion.asp
panel.style.maxHeight = null;
} HTML
else {
CSS JAVASCRIPT SQL
panel.style.maxHeight = panel.scrollHeight + "px";
}
});
}
</script>
Try it Yourself »
Add Icons
Add a symbol to each button to indicate whether the collapsible content is open or
closed:
Example
.accordion:after {
content: '\02795'; /* Unicode character for "plus" sign (+) */
font-size: 13px;
color: #777;
float: right;
margin-left: 5px;
}
.active:after {
content: "\2796"; /* Unicode character for "minus" sign (-) */
}
Try it Yourself »
❮ Previous Next ❯
5 of 8 1/25/2022, 11:43 PM
How To Create an Accordion https://www.w3schools.com/howto/howto_js_accordion.asp
NEW
We just launched
W3Schools videos
Explore now
COLOR PICKER
Get certified
by completing
a course today!
school
w3 s
2
CE
02
TI 2
R
FI .
ED
6 of 8 1/25/2022, 11:43 PM
How To Create an Accordion https://www.w3schools.com/howto/howto_js_accordion.asp
CODE GAME
Play Game
7 of 8 1/25/2022, 11:43 PM
How To Create an Accordion https://www.w3schools.com/howto/howto_js_accordion.asp
HTML CSS
Top Examples JAVASCRIPT SQL Web Courses
HTML Examples HTML Course
CSS Examples CSS Course
JavaScript Examples JavaScript Course
How To Examples Front End Course
SQL Examples SQL Course
Python Examples Python Course
W3.CSS Examples PHP Course
Bootstrap Examples jQuery Course
PHP Examples Java Course
Java Examples C++ Course
XML Examples C# Course
jQuery Examples XML Course
Get Certified »
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and
learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot
warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our
terms of use, cookie and privacy policy.
8 of 8 1/25/2022, 11:43 PM