Add a custom PNG icon to replace the + in your accordion block
Easily swap the default plus icon in your Squarespace accordion block with a custom PNG and add a smooth 90-degree rotation effect when it’s opened. Follow these simple steps!
-
Description text goes here
Step 1: Add the JavaScript
Log in to your Squarespace account.
Navigate to Settings > Advanced > Code Injection.
Scroll to the Footer section.
Paste the following JavaScript code into the footer code box and save your changes.
<script> document.addEventListener("DOMContentLoaded", function() { const accordionItems = document.querySelectorAll('.accordion-item'); // Change the selector to match your accordion's container accordionItems.forEach(item => { item.addEventListener('click', function() { // Toggle the active state on the accordion item this.classList.toggle('open'); }); }); }); </script>
Step 2: Add Custom CSS
Navigate to Design > Custom CSS.
Paste the following CSS code into the Custom CSS editor:
Save your changes.
//Add your own accordion plus icon that rotates on open// .plus { background-image: url("YOUR-PNG-URL"); background-size: contain; background-repeat: no-repeat; display: inline-block; width: 23px !important; /* Adjust size */ height: 23px !important; /* Adjust size */ text-indent: -9999px; overflow: hidden; transition: transform 0.3s ease; /* Smooth transition for rotation */ } /* This targets the plus icon when the accordion item is open */ .accordion-item.open .plus { transform: rotate(90deg); /* Rotates the icon 90 degrees */ }
Step 3: Edit Accordion Block Icon colour
Navigate to Site Styles
Choose Colours
Choose the Section colour theme that your blog post pages is using
Scroll down to Accordion block colour settings and make sure the opacity of the Accordion Block Icon colour is set to 0%. This will ensure the default icon is hidden
Customisable code
Icon Size: Adjust the width and height in the CSS to resize the icon.
Icon Rotation Degree: Change the rotation angle (e.g., 90deg) in the CSS to modify how much the icon rotates.
Accordion Selector: Modify the JavaScript selector (.accordion-item) to match your specific accordion item class.
Transition Speed: Change the duration in the transition property to make the icon rotate faster or slower.