Toggle navigation
☰
Home
HTML
CSS
Scripting
Database
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>FAQ Section</title> <style> body { font-family: Arial, sans-serif; margin: 0; padding: 2rem; background-color: #f9f9f9; } .faq-container { max-width: 800px; margin: 0 auto; } .faq-item { border-bottom: 1px solid #ddd; } .faq-question { background: none; border: none; width: 100%; text-align: left; padding: 1rem; font-size: 1.1rem; display: flex; justify-content: space-between; align-items: center; cursor: pointer; background-color: #fff; } .faq-question:focus { outline: 2px solid #007BFF; } .faq-icon { transition: transform 0.3s ease; font-size: 1.2rem; } .faq-answer { max-height: 0; overflow: hidden; transition: max-height 0.4s ease; padding: 0 1rem; background-color: #f1f1f1; } .faq-answer.open { padding: 1rem; } @media (max-width: 600px) { .faq-question { font-size: 1rem; } } </style> </head> <body> <div class="faq-container"> <h1>Frequently Asked Questions</h1> <div class="faq-item"> <button class="faq-question" aria-expanded="false" aria-controls="faq1"> What is your return policy? <span class="faq-icon">+</span> </button> <div id="faq1" class="faq-answer" role="region"> <p>We offer a 30-day return policy from the date of delivery. Please contact our support for return authorization.</p> </div> </div> <div class="faq-item"> <button class="faq-question" aria-expanded="false" aria-controls="faq2"> How long does shipping take? <span class="faq-icon">+</span> </button> <div id="faq2" class="faq-answer" role="region"> <p>Shipping typically takes 5–7 business days depending on your location.</p> </div> </div> <div class="faq-item"> <button class="faq-question" aria-expanded="false" aria-controls="faq3"> Do you ship internationally? <span class="faq-icon">+</span> </button> <div id="faq3" class="faq-answer" role="region"> <p>Yes, we ship to most countries worldwide. International shipping rates apply.</p> </div> </div> <div class="faq-item"> <button class="faq-question" aria-expanded="false" aria-controls="faq4"> How can I track my order? <span class="faq-icon">+</span> </button> <div id="faq4" class="faq-answer" role="region"> <p>Once your order is shipped, we’ll email you a tracking number to monitor delivery progress.</p> </div> </div> <div class="faq-item"> <button class="faq-question" aria-expanded="false" aria-controls="faq5"> What payment methods do you accept? <span class="faq-icon">+</span> </button> <div id="faq5" class="faq-answer" role="region"> <p>We accept all major credit cards, PayPal, Apple Pay, and Google Pay.</p> </div> </div> </div> <script> // Select all FAQ question buttons const faqButtons = document.querySelectorAll('.faq-question'); faqButtons.forEach((button) => { button.addEventListener('click', () => { const expanded = button.getAttribute('aria-expanded') === 'true'; const answerId = button.getAttribute('aria-controls'); const answer = document.getElementById(answerId); // Close all other open items faqButtons.forEach((otherBtn) => { if (otherBtn !== button) { otherBtn.setAttribute('aria-expanded', 'false'); const otherAnswerId = otherBtn.getAttribute('aria-controls'); const otherAnswer = document.getElementById(otherAnswerId); otherAnswer.style.maxHeight = null; otherAnswer.classList.remove('open'); otherBtn.querySelector('.faq-icon').textContent = '+'; } }); // Toggle current item if (!expanded) { button.setAttribute('aria-expanded', 'true'); answer.style.maxHeight = answer.scrollHeight + 'px'; answer.classList.add('open'); button.querySelector('.faq-icon').textContent = '−'; } else { button.setAttribute('aria-expanded', 'false'); answer.style.maxHeight = null; answer.classList.remove('open'); button.querySelector('.faq-icon').textContent = '+'; } }); }); // Set initial height for open answers on load (in case of JS reload) window.addEventListener('load', () => { document.querySelectorAll('.faq-answer').forEach((answer) => { if (answer.classList.contains('open')) { answer.style.maxHeight = answer.scrollHeight + 'px'; } }); }); </script> </body> </html>