ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

How-To: 50+ Real-World Developer Recipes• 5 min read

How To: Accordions with Native <details>

Create collapsible FAQ accordions using native HTML5 <details> and <summary> tags with smooth CSS animations.

Zero-JavaScript Accordions with <details>

The HTML5 <details> and <summary> elements create fully functional collapsible widgets without a single line of JavaScript. They are keyboard accessible by default (Space and Enter toggle open/closed).

Styled Accordion Group with Custom Indicators
<details class="faq-item" name="faq">
  <summary>What is Codexia Academy?</summary>
  <div class="content">
    <p>Codexia is a production-ready interactive coding academy with sandboxes and certificates.</p>
  </div>
</details>

<details class="faq-item" name="faq">
  <summary>Are certificates verifiable?</summary>
  <div class="content">
    <p>Yes, all certificates include a unique verification code and public portal.</p>
  </div>
</details>

<style>
  details {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 8px;
    overflow: hidden;
  }
  summary {
    padding: 14px 18px;
    font-weight: 600;
    cursor: pointer;
    background: #f8fafc;
    user-select: none;
  }
  details[open] summary {
    border-bottom: 1px solid #e2e8f0;
  }
  .content {
    padding: 16px 18px;
    background: #ffffff;
  }
</style>
Pro Tip

Adding the name="faq" attribute to <details> elements makes them mutually exclusive: opening one automatically closes the others in modern browsers!

ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

Which modern HTML attribute groups multiple <details> elements together so opening one automatically closes others?