Closeup of an old staircase in sunlight

As I discussed in the article that introduced the tags, the details and summary elements are excellent ways to create accordion interfaces on web pages. Until recently, features like this have required a mass of JavaScript. (Indeed, frameworks like JQuery UI have entire modules devoted to supporting them).

As I mentioned in the previous article, there are a few issues to using details today, mostly around lack of support in and Microsoft Edge. Thankfully, these are easy to solve with a combination of and a little JavaScript feature detection and DOM manipulation.


<details id="det-container">
    <a href="#">Park</a>
    <a href="#">Hosts</a>
    <a href="#">Storylines</a>
    <a href="#">Recalls</a>

Adding support with feature detection

Placed at the bottom of your page, the script does two things. First, it initiates a simple feature check by attempting to create a <details> element with an open attribute in the DOM. If the check fails, the script adds a no-det class to the <details> element, with user clicks on the <summary> child of this element adding and removing an open attribute:

function supports_details() {
	if (!('open' in document.createElement('details'))) {
		return "no-details"; }
function switchOpen() {
	if (details.getAttribute('open')) {
	} else {
        details.setAttribute('open', 'open');
if (supports_details() == "no-details" ) {
	var details = document.getElementById("det-container");
	var summary = details.firstElementChild;
    summary.addEventListener("click", switchOpen, false);

Adding style

You can apply CSS to the details and <summary> elements in the same ways that you can to everything else. In this case, I'm using the addition of the no-det class to create an equivalent UI element for non-supporting browsers:

summary, details, details a {
	display: block;
} summary::before { 
  content: "►";
  padding-right: 5px;
  font-size: 1.2em;
  transition: .6s linear;
  display: inline-block;
}[open] summary::before { 
  transform: rotate(90deg); 
} a {
  display: none;
details[open].no-det a { 
  display: block;

This duplicates the functionality of the <details> and <summary> elements for all browsers. I’ve added a little more CSS to the version you can see on the associated CodePen.

Photograph by Wolfgang Staudt, used under a Creative Commons Attribution-NonCommercial 2.0 Generic license

Enjoy this piece? I invite you to follow me at to learn more.
Check out the CodePen demo for this article at