DEV Community

Cover image for simple responsive FAQ section using only HTML and CSS, without JavaScript
Technical Care BD
Technical Care BD

Posted on

simple responsive FAQ section using only HTML and CSS, without JavaScript

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Simple Responsive FAQ</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      margin: 0;
      padding: 20px;
      background-color: #f4f4f4;
    }

    .faq-container {
      max-width: 800px;
      margin: 0 auto;
      background-color: #fff;
      padding: 20px;
      border-radius: 8px;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    .faq-item {
      border-bottom: 1px solid #ddd;
    }

    .faq-item:last-child {
      border-bottom: none;
    }

    .faq-question {
      font-weight: bold;
      padding: 15px 0;
      cursor: pointer;
      transition: color 0.3s ease;
    }

    .faq-answer {
      display: none;
      padding: 0 0 15px;
    }

    input[type="checkbox"] {
      display: none;
    }

    input[type="checkbox"]:checked ~ .faq-answer {
      display: block;
    }

    label:hover {
      color: #007BFF;
    }

    @media (max-width: 600px) {
      .faq-container {
        padding: 15px;
      }

      .faq-question {
        font-size: 16px;
      }

      .faq-answer {
        font-size: 14px;
      }
    }
  </style>
</head>
<body>

  <div class="faq-container">
    <div class="faq-item">
      <input type="checkbox" id="faq1">
      <label for="faq1" class="faq-question">What is HTML?</label>
      <div class="faq-answer">
        HTML stands for HyperText Markup Language. It is used to structure content on the web.
      </div>
    </div>

    <div class="faq-item">
      <input type="checkbox" id="faq2">
      <label for="faq2" class="faq-question">What is CSS?</label>
      <div class="faq-answer">
        CSS stands for Cascading Style Sheets. It is used to style and layout web pages.
      </div>
    </div>

    <div class="faq-item">
      <input type="checkbox" id="faq3">
      <label for="faq3" class="faq-question">How does CSS make a website responsive?</label>
      <div class="faq-answer">
        CSS makes a website responsive by using media queries, flexible layouts, and other techniques to adjust the design based on the device's screen size.
      </div>
    </div>
  </div>

</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Visit Web: Technical Care BD

Top comments (0)