How to create a FAQ page

To create a FAQ (Frequently Asked Questions) page using Bootstrap, you can utilize the accordion component to display the questions and answers in an expandable format. Here's an example of how to create a FAQ page using Bootstrap 4:

<!DOCTYPE html>
<html>
<head>
  <title>FAQ Page Example</title>
  <!-- Include Bootstrap CSS -->
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
</head>
<body>

  <div class="container mt-5">
    <h1>Frequently Asked Questions</h1>
    <div class="accordion mt-4" id="faqAccordion">
    <!-- Question 1 -->
      <div class="card">
        <div class="card-header" id="headingOne">
          <h5 class="mb-0">
            <button class="btn btn-link" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
              Question 1
            </button>
          </h5>
        </div>
        <div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#faqAccordion">
          <div class="card-body">
            Answer to question 1.
          </div>
        </div>
      </div>

      <!-- Question 2 -->
      <div class="card">
        <div class="card-header" id="headingTwo">
          <h5 class="mb-0">
            <button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
              Question 2
            </button>
          </h5>
        </div>
        <div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#faqAccordion">
          <div class="card-body">
            Answer to question 2.
          </div>
        </div>
      </div>

      <!-- Question 3 -->
      <div class="card">
        <div class="card-header" id="headingThree">
          <h5 class="mb-0">
            <button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
              Question 3
            </button>
          </h5>
        </div>
        <div id="collapseThree" class="collapse" aria-labelledby="headingThree" data-parent="#faqAccordion">
          <div class="card-body">
            Answer to question 3.
          </div>
        </div>
      </div>
    </div>
  </div>

  <!-- Include Bootstrap JS -->
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</body>
</html>

In the example above, we start by including the necessary Bootstrap CSS and JS files. Make sure to include them in the head section of your HTML document.

Inside the container, we have a heading element and a div with the `accordion` class. The `accordion` class provides the necessary styling and behavior for the FAQ section.

Within the accordion, we define each question and answer as a separate card. Each card has a card header and a card body. The card header contains a button with the `btn btn-link` classes, which can be clicked to toggle the visibility of the answer.

The `data-toggle` attribute is set to "collapse" to indicate that clicking the button should toggle the visibility of the associated answer. The `data-target` attribute specifies the ID of the collapsible element.


Output:

img


About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext