search
HomeWeb Front-endCSS TutorialBuild a FAQ Accordion Website

Build a FAQ Accordion Website

Introduction

Hello, developers! I’m excited to share my latest project: a FAQ Accordion web application. This project is perfect for those looking to create an interactive and user-friendly FAQ section for their websites. It’s a great way to enhance your frontend development skills using HTML, CSS, and JavaScript while building a practical component that can be used in various applications.

Project Overview

The FAQ Accordion is a web application designed to display frequently asked questions in an expandable and collapsible format. With a clean and modern design, it allows users to click on a question to reveal the corresponding answer. This project showcases how to create an interactive FAQ section that improves user experience by making content easily accessible.

Features

  • Interactive Accordion: Users can click on questions to toggle the visibility of answers, enhancing content readability.
  • Responsive Design: The application is fully responsive, ensuring an optimal viewing experience on both desktop and mobile devices.
  • Dynamic Icons: Icons change to indicate whether an answer is expanded or collapsed.

Technologies Used

  • HTML: Provides the structure for the FAQ Accordion application.
  • CSS: Styles the application to create a clean and responsive design.
  • JavaScript: Manages the interactive elements, including expanding and collapsing answers and toggling icons.

Project Structure

Here’s an overview of the project structure:

FAQ-Accordion/
├── index.html
├── style.css
└── script.js
  • index.html: Contains the HTML structure for the FAQ Accordion application.
  • style.css: Includes CSS styles to create an engaging and responsive design.
  • script.js: Manages the interactive elements, such as expanding and collapsing answers and updating icons.

Installation

To get started with the project, follow these steps:

  1. Clone the repository:

    git clone https://github.com/abhishekgurjar-in/FAQ-Accordion.git
    
  2. Open the project directory:

    cd FAQ-Accordion
    
  3. Run the project:

    • Open the index.html file in a web browser to view the FAQ Accordion application.

Usage

  1. Open the application in a web browser.
  2. Click on a question to toggle the visibility of the answer.
  3. Expand and collapse different questions to view their answers.
  4. Update or add new questions as needed.

Code Explanation

HTML

The index.html file defines the structure of the FAQ Accordion application, including questions and answers. Here’s a snippet:


  
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>FAQ accordion</title>
    <link rel="stylesheet" href="./style.css">
    <script src="./script.js" defer></script>
  
  
    <div class="conatiner">
      <img src="/static/imghwm/default1.png" data-src="./assets/images/background-pattern-desktop.svg" class="lazy" alt="">
      <div class="box">
        <h1>
          FAQs
          <span class="imageStar">
            <img src="/static/imghwm/default1.png" data-src="./assets/images/icon-star.svg" class="lazy" alt=""></span>
        </h1>
        <section class="section">
          <div class="question">
            <h3 id="Is-Frontend-Mentor-free">Is Frontend Mentor free?</h3>
            <div class="icon-img">
              <img src="/static/imghwm/default1.png" data-src="./assets/images/icon-plus.svg" class="lazy" alt="">
            </div>
          </div>
          <div class="answer">
            <p>
              Frontend Mentor offers realistic coding challenges to help
              developers improve their frontend coding skills with projects in
              HTML, CSS, and JavaScript. It's suitable for all levels and ideal
              for portfolio building.
            </p>
          </div>
          <hr>
        </section>
        <section class="section">
          <div class="question">
            <h3 id="Can-I-use-Frontend-Mentor-projects-in-my-portfolio">Can I use Frontend Mentor projects in my portfolio?</h3>
            <div class="icon-img">
              <img src="/static/imghwm/default1.png" data-src="./assets/images/icon-plus.svg" class="lazy" alt="">
            </div>
          </div>
          <div class="answer">
            <p>
              Yes, Frontend Mentor offers both free and premium coding
              challenges, with the free option providing access to a range of
              projects suitable for all skill levels.
            </p>
          </div>
          <hr>
        </section>
        <section class="section">
          <div class="question">
            <h3 id="Can-I-use-Frontend-Mentor-projects-in-my-portfolio">Can I use Frontend Mentor projects in my portfolio?</h3>
            <div class="icon-img">
              <img src="/static/imghwm/default1.png" data-src="./assets/images/icon-plus.svg" class="lazy" alt="">
            </div>
          </div>
          <div class="answer">
            <p>
              Yes, you can use projects completed on Frontend Mentor in your
              portfolio. It's an excellent way to showcase your skills to
              potential employers!
            </p>
          </div>
          <hr>
        </section>
        <section class="section">
          <div class="question">
            <h3>
              How can I get help if I'm stuck on a Frontend Mentor challenge?
            </h3>
            <div class="icon-img">
              <img src="/static/imghwm/default1.png" data-src="./assets/images/icon-plus.svg" class="lazy" alt="">
            </div>
          </div>
          <div class="answer">
            <p>
              The best place to get help is inside Frontend Mentor's Discord
              community. There's a help channel where you can ask questions and
              seek support from other community members.
            </p>
          </div>
          <hr>
        </section>
      </div>
    </div>

  


CSS

The style.css file styles the FAQ Accordion application, ensuring it’s visually appealing and responsive. Below are some key styles:

* {
  box-sizing: border-box;
  margin: 0;
}

body {
  background-color: hsl(275, 100%, 97%);

}

img {
  width: 100%;
  position: fixed;
}

.container {
  position: absolute;
}

.box {
  top: 100px;
  margin: 0 auto;
  background-color: hsl(0, 0%, 100%);
  max-width: 555px;
  position: relative;
  border-radius: 13px;
  padding: 20px;
}

.imageStar img {
  width: 36px;
  margin-left: 10px;
}

.section {
  padding: 5px;
}

.question {
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.answer {
  display: none;
  overflow: hidden;
  padding: 10px;
}

.answer.active {
  display: block;
}

.icon-img {
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-img img {
  position: fixed;
  width: 19px;
}

@media (max-width: 700px) {
  .box {
    max-width: 500px;
  }
}

@media (max-width: 500px) {
  .box {
    max-width: 400px;
  }
}

JavaScript

The script.js file contains the functionality for expanding and collapsing answers. Here’s a snippet for demonstration:

const questions = document.querySelectorAll(".question");

questions.forEach(question => {
  question.addEventListener("click", () => {
    const answer = question.nextElementSibling;
    const icon = question.querySelector(".icon-img img");

    // Toggle answer visibility
    answer.classList.toggle("active");

    // Change icon
    if (answer.classList.contains("active")) {
      icon.src = "./assets/images/icon-minus.svg";
    } else {
      icon.src = "./assets/images/icon-plus.svg";
    }
  });
});

Live Demo

You can check out the live demo of the FAQ Accordion project here.

Conclusion

Building the FAQ Accordion application was a rewarding experience in creating an interactive and user-friendly FAQ section. This project highlights the importance of user engagement and content accessibility. By applying HTML, CSS, and JavaScript, we’ve developed a component that enhances user experience by making frequently asked questions easily accessible. I hope this project inspires you to build your own interactive components. Happy coding!

Credits

This project was developed as part of my continuous learning journey in web development.

Author

  • Abhishek Gurjar
    • GitHub Profile

The above is the detailed content of Build a FAQ Accordion Website. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
So Many Color LinksSo Many Color LinksApr 13, 2025 am 11:36 AM

There's been a run of tools, articles, and resources about color lately. Please allow me to close a few tabs by rounding them up here for your enjoyment.

How Auto Margins Work in FlexboxHow Auto Margins Work in FlexboxApr 13, 2025 am 11:35 AM

Robin has covered this before, but I've heard some confusion about it in the past few weeks and saw another person take a stab at explaining it, and I wanted

Moving Rainbow UnderlinesMoving Rainbow UnderlinesApr 13, 2025 am 11:27 AM

I absolutely love the design of the Sandwich site. Among many beautiful features are these headlines with rainbow underlines that move as you scroll. It's not

New Year, New Job? Let's Make a Grid-Powered Resume!New Year, New Job? Let's Make a Grid-Powered Resume!Apr 13, 2025 am 11:26 AM

Many popular resume designs are making the most of the available page space by laying sections out in a grid shape. Let’s use CSS Grid to create a layout that

One Way to Break Users Out of the Habit of Reloading Too MuchOne Way to Break Users Out of the Habit of Reloading Too MuchApr 13, 2025 am 11:25 AM

Page reloads are a thing. Sometimes we refresh a page when we think it’s unresponsive, or believe that new content is available. Sometimes we’re just mad at

Domain-Driven Design With ReactDomain-Driven Design With ReactApr 13, 2025 am 11:22 AM

There is very little guidance on how to organize front-end applications in the world of React. (Just move files around until it “feels right,” lol). The truth

Detecting Inactive UsersDetecting Inactive UsersApr 13, 2025 am 11:08 AM

Most of the time you don’t really care about whether a user is actively engaged or temporarily inactive on your application. Inactive, meaning, perhaps they

Wufoo   ZapierWufoo ZapierApr 13, 2025 am 11:02 AM

Wufoo has always been great with integrations. They have integrations with specific apps, like Campaign Monitor, Mailchimp, and Typekit, but they also

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools