Menu
Coddy logo textTech

Interactive FAQ accordion

Part of the JavaScript in Action section of Coddy's HTML journey — lesson 24 of 27.

challenge icon

Challenge

Easy

We have a simple FAQ page with a few questions. This type of design is very common: when a user clicks a question, the hidden answer should slide down smoothly. At the same time, we can rotate the “+” sign into an “×” to show the section is open.

We have an FAQ section with one question. Your job is to make it interactive:

In JavaScript:

  • Add a click event listener to the FAQ question
  • When clicked, toggle the "show" class on the answer

In CSS:
Add styles so that:

  • When the FAQ answer has the "show" class, set its opacity to 1 and max-height to 300px

Try it yourself

<!DOCTYPE html>
<html>
<head>
  <title>FAQ Challenge</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
   <h1>FAQ – Healthy Lifestyle</h1>
  <div class="faq">
    <div class="faq-item">
      <div class="faq-question">
        <span>What does a balanced diet mean?</span>
        <span>+</span>
      </div>
      <div class="faq-answer">
        A balanced diet includes a variety of foods — fruits, vegetables, whole grains, lean proteins, and healthy fats — in the right proportions to keep your body nourished and energized.
      </div>
    </div>
  </div>
 <script src="script.js"></script>
</body>
</html>

All lessons in JavaScript in Action