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.
Mutually exclusive <details> elements
Baseline 2024 newly available
Supported in Chrome: yes.
Supported in Edge: yes.
Supported in Firefox: yes.
Supported in Safari: yes.
Since September 2024 this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Mutually exclusive <details> elements on Web Platform Status
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
<details>
element shines when building documentation, FAQs, or navigation menus.▶What is the details element?
▶Why use it?
▶Browser support?
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!