FAQ Accordion List Template
Answer your users' frequently asked questions with this interactive and accessible FAQ accordion.
This template allows users to click on a question to reveal the answer, keeping your help section tidy and easy to navigate.

About this Template
This template is built upon a semantic definition list (dl
), with each question as a dt
(definition term) and each answer as a dd
(definition description). Lightweight, dependency-free JavaScript powers the expand and collapse functionality, ensuring fast performance. ARIA attributes are used to communicate the state of each accordion item to screen readers, making it fully accessible.
Features
- Semantic Structure: Uses a
dl
for a perfectly structured question and answer list. - Accessible & Interactive: Implements ARIA attributes like
aria-expanded
andaria-controls
, which are updated dynamically by the JavaScript. - Pure JavaScript: The toggle functionality is self-contained and uses modern, efficient JavaScript with no external libraries like jQuery.
- CSS Animated Icon: The plus/minus icon is created with CSS and smoothly animates during the state change.
- Self-Contained Code: All styles are scoped to the
.faq-accordion-template
class to prevent conflicts.
Code Breakdown
The FAQ is structured as a dl
element. Each question is a button
inside the dt
for maximum accessibility, and the corresponding answer is inside the dd
. By default, the answers are hidden with display: none
.
The JavaScript finds all the question buttons. It adds a click event listener to each one. When a button is clicked, the script toggles an .active
class on the question and toggles the visibility of the next element, which is the answer. It also updates the aria-expanded
attribute on the button from false
to true
, which is essential for assistive technologies.
Code
Here's the full code for the template: