htmlintermediatemit

FAQ Accordion Section

A full FAQ section with accordions.

8.6k3.3k483353

About this module

A complete FAQ section with a heading and several accordion items, fully keyboard accessible.

#faq#accordion#questions

Source code

Installation

  1. 1

    Create the files

    Create `index.html` and `style.css` in the same folder.

  2. 2

    Paste the code

    Copy each file's source into its matching file.

  3. 3

    Open in the browser

    Open `index.html` in any modern browser.

Usage

  1. 1

    Copy the HTML

    Paste the section markup where you need it.

    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
    <section class="mh-sec">
      <div class="mh-container mh-faq">
        <div class="mh-center-head"><span class="mh-eyebrow">FAQ</span><h2 class="mh-h2">Frequently asked questions</h2></div>
        <div class="mh-faq-list">
          <div class="mh-faq-item">
            <button class="mh-faq-head" aria-expanded="false" aria-controls="f1"><span>Is ModuleHarbor free?</span><span class="mh-plus">+</span></button>
            <div class="mh-faq-body" id="f1"><p>Yes. Every module is MIT licensed and free to use in personal and commercial projects.</p></div>
          </div>
          <div class="mh-faq-item">
            <button class="mh-faq-head" aria-expanded="false" aria-controls="f2"><span>Can I contribute modules?</span><span class="mh-plus">+</span></button>
            <div class="mh-faq-body" id="f2"><p>Absolutely. Submit a module from your dashboard and it will be reviewed by our team before publishing.</p></div>
          </div>
          <div class="mh-faq-item">
            <button class="mh-faq-head" aria-expanded="false" aria-controls="f3"><span>Do I need Node.js?</span><span class="mh-plus">+</span></button>
            <div class="mh-faq-body" id="f3"><p>Only for framework modules like React or Angular. Pure HTML/CSS/JS modules run anywhere.</p></div>
          </div>
        </div>
      </div>
    </section>
  2. 2

    Wire up the script

    Include `script.js` before the closing body tag.

    document.querySelectorAll(".mh-faq-head").forEach((btn) => {
      btn.addEventListener("click", () => {
        const body = document.getElementById(btn.getAttribute("aria-controls"));
        const open = btn.getAttribute("aria-expanded") === "true";
        btn.setAttribute("aria-expanded", String(!open));
        body.style.maxHeight = open ? "0px" : body.scrollHeight + "px";
      });
    });
Overview
Categorysections
Frameworkhtml
Difficultyintermediate
Licensemit
Versionv1.0.0
Features
  • Fully responsive
  • Semantic markup
  • No dependencies
Traits
  • ResponsiveYes
  • Dark modeYes
  • AccessibleYes
  • Production readyYes
Browser support
  • Chrome 90+
  • Firefox 90+
  • Safari 15+
  • Edge 90+

Related modules

Command Palette

Search modules and jump anywhere