• blog
  • Build an Accordion Without JavaScript

October 7,2021

Build an Accordion Without JavaScript

byIsev Team Isev Team

accordion-v2
In the pursuit of web performance, we are all looking to come up with clever solutions to make our websites load faster. One way many of us do this is coming up with and stealing (which in this case, the latter is more appropriate) ways of writing less JavaScript.

Many websites I work on include an FAQ section, and nine times out of ten I end up building some form of accordion. But recently I saw a method of building a mobile menu without the use of JavaScript, and I wondered if I could use the same method to build an accordion.

See the Pen Building an Accordion without JavaScript – Part I by Michael (@mjtweaver) on CodePen.

The above pen really simply demonstrates how we can achieve this. We use the label to use as the question, and we also include a checkbox. The checkbox is hidden from view. When we click on the label, it checks the input and then we can use this to display the answer. You’ll notice here we use the general sibling combinator or ~. I wrote some more information on this here. The above example was very simple, how about a styled up version?

After searching on Google, I know others have also used this solution in the past, so it may not be new to you, but it would interesting to get your thoughts.

As a note on browser compatibility, the only thing you have to really consider is the general sibling selector, information can be found here.

Continue Reading

Data Analysis: Tips and Best Practices

Now that a vast majority of businesses are online, there are a range of different data sets that they can analyse. This is great! It means they can really take the time to understand how their business is doing, they can also learn more about their customers. However, this isn’t the easiest process if you … Continued

Avatar
Leanne July 23rd, 2024
Should you get your website redesigned?

Recognising whether your website needs a redesign involves assessing various crucial areas that impact its overall success, such as user experience, and more. From visual elements to technical aspects, every component contributes to the effectiveness of your online presence. To guide you through this process, we’ve compiled a comprehensive list to help you figure out … Continued

Isev Team
Isev Team June 4th, 2024
Key Practices for Enhanced Admin Security

Safeguarding your website’s admin area is crucial in today’s digital age, especially as despite the amount of online security available, there are just as many threats. Websites hold a wealth of sensitive information and the admin area of a website is a prime target for cyber threats, such as data breaches and unauthorised access. This … Continued

Isev Team
Isev Team May 22nd, 2024
Why you need to upgrade Magento

Upgrading Magento offers a wealth of benefits, yet many businesses remain reluctant to take the leap. Despite the compelling advantages, the process of upgrading can be perceived as complex and resource-intensive – and while this can be true, the benefits and safety that comes with upgrading should be enough cause to get businesses to capitalise … Continued

Avatar
Leanne May 17th, 2024