HTML Details Element: The Native Accordion You're Not Using

Discover how the HTML details element can replace your JavaScript accordions and why it might be better than your current solution

The HTML <details> element might be one of the most underappreciated native features we have. I’m constantly surprised by how many developers reach for JavaScript solutions when they need to show/hide content, completely overlooking this built-in option.

The <details> element creates an expandable widget that users can open and close. Think of it as a native accordion - no JavaScript required. Here’s the basic syntax:


That’s it. No JavaScript. No CSS. No aria attributes to manage. The browser handles all the accessibility features, keyboard navigation, and state management for you.

<details> Built-in Features

  • Screen reader announcements for expanded/collapsed states
  • Keyboard navigation using Enter and Space keys
  • Proper focus management
  • Semantic HTML structure
  • State management without JavaScript
The <details> element shines when building documentation, FAQs, or navigation menus.
▶What is the details element?
A native HTML element that creates expandable widgets without requiring JavaScript. Perfect for accordions, FAQs, and collapsible sections.
▶Why use it?
Built-in accessibility, keyboard navigation, and state management make it a robust choice compared to custom JavaScript solutions.
▶Browser support?
Excellent support across modern browsers, with easy fallback options for legacy environments.

Code implementation with Tailwind

While the <details> element works perfectly out of the box, this styled version demonstrates how it can be enhanced with CSS techniques while maintaining its native functionality. The beauty lies in its progressive enhancement - starting with semantic HTML, adding thoughtful styling, and preserving all built-in accessibility features.

Next time you reach for a JavaScript accordion, consider whether this native HTML element might serve your needs better. Sometimes the best solutions are already built-in!


P.S. — ::details-content just shipped. Style the content area without wrapper divs.


Trevor I. Lasn

Trevor I. Lasn

Building whiteheap.com and 0xinsider.com.



Related Articles

Check out these related articles that might be useful for you. They cover similar topics and provide additional insights.

Web performance
3 min read

A plain preload link fetches the wrong file for a responsive image. Add imagesrcset and imagesizes to link rel=preload so the browser picks the same image.

Nov 28, 2024
Read article
HTML
3 min read

The HTML Popover API builds tooltips, dropdowns and overlays without a JavaScript library. How to use it, what it returns and where browsers support it.

Jan 24, 2025
Read article
HTML
3 min read

The <search> element wraps a search form or filter controls so browsers and screen readers know their purpose. When to use it, with input type=search examples.

Dec 2, 2024
Read article
CSS
4 min read

Style connected UI with the :interest-source and :interest-target pseudo-classes. Interactive examples of tooltips, forms and navigation without JavaScript.

Nov 12, 2025
Read article
Web performance
3 min read

Set loading=lazy on an iframe and the browser waits to load it until the reader scrolls near. Before-and-after code, the bandwidth saved and browser support.

Sep 13, 2024
Read article
CSS
3 min read

The ::details-content pseudo-element lets you style the expandable content of details elements separately from the summary, no divs needed.

Nov 11, 2025
Read article
Web performance
4 min read

Using link rel='preconnect' can improve your website's performance by reducing connection setup times to key external domains.

Sep 13, 2024
Read article
CSS
3 min read

The new pseudo-classes :user-valid and :user-invalid give us a smarter way to style form validation states based on user interaction

Dec 12, 2024
Read article
Web performance
9 min read

How the Speculation Rules API improves web performance by prefetching and prerendering future navigations

Sep 15, 2024
Read article

This article was originally published on https://www.trevorlasn.com/blog/html-details-element. It was written by a human and polished using grammar tools for clarity.