How to Create FAQ Section in HTML: Simple Guide
To create a FAQ section in HTML, use semantic elements like
<section> for grouping, <h2> for the title, and <details> with <summary> for each question and answer pair. This structure makes the FAQ easy to read and interactive without extra scripts.Syntax
A FAQ section typically uses the <section> tag to group all questions and answers. Each question is inside a <summary> tag, which is wrapped by a <details> tag that holds the answer content. Use headings like <h2> for the FAQ title.
html
<section>
<h2>FAQ</h2>
<details>
<summary>Question 1?</summary>
<p>Answer to question 1.</p>
</details>
<details>
<summary>Question 2?</summary>
<p>Answer to question 2.</p>
</details>
</section>Output
FAQ
Question 1? ▼
Answer to question 1.
Question 2? ▼
Answer to question 2.
Example
This example shows a simple FAQ section with three questions. Clicking a question reveals its answer. This uses only HTML, so it works in all modern browsers without extra code.
html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Simple FAQ Section</title> <style> body { font-family: Arial, sans-serif; max-width: 600px; margin: 2rem auto; padding: 0 1rem; } details { margin-bottom: 1rem; border: 1px solid #ccc; border-radius: 5px; padding: 0.5rem 1rem; background-color: #f9f9f9; } summary { font-weight: bold; cursor: pointer; outline: none; } summary:focus { outline: 2px solid #007acc; outline-offset: 2px; } </style> </head> <body> <section aria-label="Frequently Asked Questions"> <h2>Frequently Asked Questions</h2> <details> <summary>What is HTML?</summary> <p>HTML stands for HyperText Markup Language and is used to create web pages.</p> </details> <details> <summary>How do I create a FAQ section?</summary> <p>Use the <code><details></code> and <code><summary></code> tags to make questions expandable.</p> </details> <details> <summary>Is JavaScript needed for FAQ?</summary> <p>No, HTML <code><details></code> works without JavaScript for basic FAQ functionality.</p> </details> </section> </body> </html>
Output
Frequently Asked Questions
What is HTML? ▼
HTML stands for HyperText Markup Language and is used to create web pages.
How do I create a FAQ section? ▼
Use the <details> and <summary> tags to make questions expandable.
Is JavaScript needed for FAQ? ▼
No, HTML <details> works without JavaScript for basic FAQ functionality.
Common Pitfalls
- Not using semantic tags like
<details>and<summary>can make the FAQ less accessible and harder to use. - Putting all questions and answers in plain
<div>tags without interaction makes the FAQ static and less user-friendly. - Forgetting to add
aria-labelor headings can reduce accessibility for screen readers.
html
<!-- Wrong: Using divs without interaction -->
<section>
<h2>FAQ</h2>
<div>
<p><strong>Question 1?</strong></p>
<p>Answer 1.</p>
</div>
<div>
<p><strong>Question 2?</strong></p>
<p>Answer 2.</p>
</div>
</section>
<!-- Right: Using details and summary for interaction -->
<section aria-label="FAQ">
<h2>FAQ</h2>
<details>
<summary>Question 1?</summary>
<p>Answer 1.</p>
</details>
<details>
<summary>Question 2?</summary>
<p>Answer 2.</p>
</details>
</section>Quick Reference
- Use
<section>to group the FAQ content. - Use
<h2>or appropriate heading for the FAQ title. - Use
<details>to create expandable question blocks. - Use
<summary>inside<details>for the question text. - Put the answer inside the
<details>but outside<summary>. - Add
aria-labelto the section for accessibility.
Key Takeaways
Use
and
tags to create interactive FAQ questions and answers.
Wrap your FAQ in a with a clear heading for structure and accessibility.
Avoid static divs without interaction to keep the FAQ user-friendly and accessible.
Add simple CSS for better spacing and focus outlines to improve usability.
No JavaScript is needed for a basic, accessible FAQ section using HTML5 tags.