• Home
  • /
  • Animated Accordion FAQ Section Using HTML, CSS & JS

Animated Accordion FAQ Section Using HTML, CSS & JS

HTML

				
					<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>FAQ Accordion - Learn With Arshyan</title>
<style>
  * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  
  font-family: 'Segoe UI', sans-serif;
  background: #f0f4ff;
  color: #333;
  padding: 40px 20px;
}

.faq-section {
  max-width: 700px;
  margin: 0 auto;
  background: #fff;
  border-radius: 16px;
  padding: 40px;
  box-shadow: 0 15px 30px rgba(0,0,0,0.05);
}

.faq-section h2 {
  text-align: center;
  margin-bottom: 30px;
  color: #4b00e0;
}

.accordion {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.accordion-item {
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #ddd;
}

.accordion-header {
  width: 100%;
  background: #e7ebff;
  padding: 16px 20px;
  font-size: 18px;
  font-weight: 600;
  color: #333;
  text-align: left;
  cursor: pointer;
  border: none;
  transition: background 0.3s ease;
}

.accordion-header:hover {
  background: #d2d9ff;
}

.accordion-body {
  background: #fafbff;
  padding: 18px 20px;
  display: none;
  font-size: 16px;
  line-height: 1.6;
}

.accordion-body.active {
  display: block;
}

</style>
</head>
<body>

  <section class="faq-section">
    <h2>Frequently Asked Questions</h2>
    
    <div class="accordion">
      <div class="accordion-item">
        <button class="accordion-header">What is HTML?</button>
        <div class="accordion-body">
          <div class='code-block code-block-2' style='margin: 8px 0; clear: both;'>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2094722033678002"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-2094722033678002"
     data-ad-slot="2248279416"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></div>
<p>HTML stands for HyperText Markup Language. It structures web content for the browser.</p>
        </div>
      </div>

      <div class="accordion-item">
        <button class="accordion-header">How does CSS work?</button>
        <div class="accordion-body">
          <p>CSS controls how elements appear on a page, including layout, colors, and fonts.</p>
        </div>
      </div>

      <div class="accordion-item">
        <button class="accordion-header">Why learn JavaScript?</button>
        <div class="accordion-body">
          <p>JavaScript adds interactivity to websites, allowing dynamic content, animations, and more.</p>
        </div>
      </div>
    </div>
  </section>

  <script>
    const headers = document.querySelectorAll('.accordion-header');

headers.forEach(header => {
  header.addEventListener('click', () => {
    const body = header.nextElementSibling;

    document.querySelectorAll('.accordion-body').forEach(item => {
      if (item !== body) item.classList.remove('active');
    });

    body.classList.toggle('active');
  });
});

  </script>
</body>
</html>

				
			

Share this post

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top