How to Make a Custom FAQ Accordion in Squarespace
Here is the script you'll need:
This one goes in the site wide code injection (footer) - 'Settings > Advanced > Code Injection > Footer'
<script>
var acc = document.getElementsByClassName("accordion");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function() {
this.classList.toggle("active");
var panel = this.nextElementSibling;
if (panel.style.display === "block") {
panel.style.display = "none";
} else {
panel.style.display = "block"; }});}
var acc = document.getElementsByClassName("accordion");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function() {
this.classList.toggle("active");
var panel = this.nextElementSibling;
if (panel.style.maxHeight) {
panel.style.maxHeight = null;
} else {
panel.style.maxHeight = panel.scrollHeight + "px"; }});}
</script>
Then you'll need to add this in a Code Block on the page where you would like your FAQ accordion to appear:
<button class="accordion">QUESTION HERE</button>
<div class="panel">
<p>ANSWER HERE</p>
</div>
Lastly place the CSS in the Custom CSS section 'Design > Custom CSS'
.accordion {
background-color: #525252;
color: #fff;
border: solid 1px #fff;
cursor: pointer;
padding: 18px;
width: 100%;
text-align: left;
transition: 0.4s;
}
.accordion:hover {
background-color: #ccc;
}
.panel {
padding: 0 20px;
background-color: #fff;
max-height: 0;
overflow: hidden;
transition: max-height 0.4s ease-out;
}
Try changing the font weight, colour and sizing, you'll find more info on CSS and text at w3 Schools
Subscribe on YouTube for more Squarespace tips & tricks!