---
title: "How do I make a native HTML accordion?"
description: "Build an accessible accordion with the details and summary elements and no JavaScript. Add a shared name attribute so only one panel opens at a time."
url: https://www.danny.engineering/answer/html/how-do-i-make-a-native-html-accordion
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T17:24:00.000Z
tags: ["HTML"]
---

# How do I make a native HTML accordion?

## The short answer


Use the `details` element with a `summary` inside it. The browser handles opening, closing, keyboard support and screen reader announcements for you. Give several `details` elements the same `name` attribute to make an exclusive accordion, where opening one closes the others.


```html
<details name="faq" open>
  <summary>What is your returns policy?</summary>
  <p>You can return any item within 30 days.</p>
</details>

<details name="faq">
  <summary>Do you ship abroad?</summary>
  <p>Yes, to most countries in Europe.</p>
</details>
```


## Why it happens


Accordions are usually built with buttons, `aria-expanded`, hidden panels and a click handler. That is a lot of code to get right, and it is easy to miss keyboard focus, the expanded state or the link between the button and its panel.


The `details` element is a built-in disclosure widget. Its `summary` is focusable and responds to Enter and Space, assistive technology announces it as expanded or collapsed, and the `open` attribute reflects its state. Content inside a closed `details` element can also be found with the browser's find in page, which opens the panel automatically in supporting browsers.


The `name` attribute adds the one feature people used to need JavaScript for: groups where only one panel can be open. Elements with the same `name` value form a group, even if they are not siblings. It is supported in Chrome and Edge 120, Safari 17.2 and Firefox 130, so it works in all current major browsers. In older browsers the attribute is ignored and each panel opens independently, which is a safe fallback.


## How to fix it


### Build the basic accordion


The `summary` must be the first child of `details`. Anything after it is the panel content. Add `open` to show a panel by default.


```html
<details>
  <summary>Delivery times</summary>
  <p>Most orders arrive within three working days.</p>
</details>
```


### Make panels exclusive with name


Give every `details` in the group the same `name`. Use a different name for each separate group on the page.


```html
<details name="shipping">...</details>
<details name="shipping">...</details>
<details name="payments">...</details>
```


### Style the marker and open state


The default triangle is a `::marker` on the summary. Hide it with `list-style: none`, or with the WebKit pseudo-element for older Safari, and draw your own. Style the open state with the `[open]` attribute selector.


```css
summary {
  list-style: none;
  cursor: pointer;
  padding: 0.75rem 1rem;
}

summary::-webkit-details-marker {
  display: none;
}

summary::after {
  content: '+';
  float: right;
}

details[open] > summary::after {
  content: '\2212';
}
```


### Animate opening and closing


Newer browsers expose the panel content as the `::details-content` pseudo-element. Animating it to `auto` also needs `interpolate-size`, which at the time of writing only Chromium browsers support. Other browsers simply open without animation, so this is safe to add as an enhancement.


```css
:root {
  interpolate-size: allow-keywords;
}

details::details-content {
  block-size: 0;
  overflow: hidden;
  transition: block-size 250ms, content-visibility 250ms allow-discrete;
}

details[open]::details-content {
  block-size: auto;
}
```


### React to changes in JavaScript


If you need to track which panel is open, listen for the `toggle` event. It fires after the state changes.


```javascript
document.querySelectorAll('details').forEach((panel) => {
  panel.addEventListener('toggle', () => {
    console.log(panel.open ? 'opened' : 'closed');
  });
});
```


## Common pitfalls

- Putting a heading around the `details` and expecting the summary to act as that heading. If headings matter for navigation, put the heading inside the `summary`.
- Adding buttons or links inside `summary`. Interactive content there is confusing for keyboard and screen reader users.
- Changing `display` on `summary` to `flex` and losing the marker. That is expected; draw your own indicator.
- Using a non-unique `name` across unrelated groups. Every `details` with the same name on the page is one group.
- Relying on `name` for content users need to compare side by side. Exclusive accordions hide one answer when the next opens.

## Related reading

- [MDN: The details element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details)
- [MDN: The summary element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/summary)
