An animated accordion with no JavaScript

Questions that slide open and closed with no JavaScript at all. The browser does the opening; a few lines of CSS make it smooth.

UI loop

An accordion with no JavaScript

Can I use these in client work?

Yes. Everything in the library is free for personal and commercial work.

Does it need JavaScript?

No. It is a details element with a few lines of CSS.

What if the browser is older?

It still opens and closes. It just skips the slide.

Delivery

Orders leave within two working days.

Returns

Send it back within 30 days for a full refund.

Sundry Millsundrymill.com/library
An animated accordion with no JavaScript

Everything in the preview is live. Try it.

The code, one by one

Shared: the open and close animation
/* the open and close animation, for every style below */
.acc { width: min(100%, 320px); interpolate-size: allow-keywords; }
.acc details::details-content {
  block-size: 0;
  overflow-y: clip;
  transition: block-size .3s cubic-bezier(.33, 1, .68, 1), content-visibility .3s allow-discrete;
}
.acc details[open]::details-content { block-size: auto; }
.acc summary { list-style: none; cursor: pointer; }
.acc summary::-webkit-details-marker { display: none; }
@media (prefers-reduced-motion: reduce) {
  .acc details::details-content { transition: none; }
}

Chevron list

An FAQ list. The three share a name, so opening one closes the one before.

HTML
<div class="acc acc-list">
  <details name="faq" open>
    <summary>Can I use these in client work? <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 9l6 6 6-6"/></svg></summary>
    <p>Yes. Everything in the library is free for personal and commercial work.</p>
  </details>
  <details name="faq">
    <summary>Does it need JavaScript? <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 9l6 6 6-6"/></svg></summary>
    <p>No. It is a details element with a few lines of CSS.</p>
  </details>
  <details name="faq">
    <summary>What if the browser is older? <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 9l6 6 6-6"/></svg></summary>
    <p>It still opens and closes. It just skips the slide.</p>
  </details>
</div>
CSS
.acc-list { border-top: 1px solid #DDD5C8; }
.acc-list details { border-bottom: 1px solid #DDD5C8; }
.acc-list summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 12px 4px;
  font-weight: 700;
}
.acc-list summary svg {
  flex: none;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: rotate .3s cubic-bezier(.33, 1, .68, 1);
}
.acc-list details[open] summary svg { rotate: 180deg; }
.acc-list summary:focus-visible { outline: 3px solid #E8631A; outline-offset: 2px; border-radius: 6px; }
.acc-list p { margin: 0; padding: 0 4px 16px; color: #3D4755; line-height: 1.55; }
@media (prefers-reduced-motion: reduce) {
  .acc-list summary svg { transition: none; }
}

Plus cards

Separate cards, each with a plus that turns into a minus. These open on their own, without closing each other.

HTML
<div class="acc acc-cards">
  <details>
    <summary>Delivery</summary>
    <p>Orders leave within two working days.</p>
  </details>
  <details>
    <summary>Returns</summary>
    <p>Send it back within 30 days for a full refund.</p>
  </details>
</div>
CSS
.acc-cards { display: grid; gap: 8px; }
.acc-cards details { border-radius: 14px; background: #FFFFFF; box-shadow: inset 0 0 0 1.5px #E5DED3; }
.acc-cards summary { position: relative; min-height: 52px; box-sizing: border-box; padding: 15px 52px 15px 16px; font-weight: 700; }
.acc-cards summary::before,
.acc-cards summary::after {
  content: "";
  position: absolute;
  right: 20px;
  top: 50%;
  width: 14px;
  height: 2.5px;
  margin-top: -1.25px;
  border-radius: 2px;
  background: currentColor;
  transition: rotate .3s cubic-bezier(.33, 1, .68, 1);
}
.acc-cards summary::after { rotate: 90deg; }
.acc-cards details[open] summary::after { rotate: 0deg; }
.acc-cards summary:focus-visible { outline: 3px solid #E8631A; outline-offset: 2px; border-radius: 14px; }
.acc-cards p { margin: 0; padding: 0 16px 16px; color: #3D4755; line-height: 1.55; }
@media (prefers-reduced-motion: reduce) {
  .acc-cards summary::after { transition: none; }
}

How to use it

  • It is the details element, so the keyboard, screen readers and find in page all work with nothing added. Press Tab to reach a question and Enter or Space to open it.
  • interpolate-size: allow-keywords lets the browser animate to height auto, and ::details-content is the part that opens. Browsers without them open the answer at once, which is a fine way to fail.
  • Give several details the same name and they act as one group: opening one closes the others. Leave the name off, as the cards do, to let any number stay open.
  • The padding is on the summary, so the whole row is the button and it stays at least 52 pixels tall.

When to use it

  • FAQ sections, shipping and returns details, and long settings lists, where people look for one answer and skip the rest.
  • Phone layouts that would otherwise be a very long scroll of headings and text.
  • Not for the main content of a page or anything most people need. Hiding it behind a click makes it slower to read, and some people never open it.

A worked example: an FAQ that search engines and people can both read

A product FAQ built from the Chevron list, with the answers in the HTML so they are found by search and by find in page.

  1. Write each question as a summary and the answer straight after it. The answers are in the page from the start, only folded.
  2. Give every details the same name, such as "faq", so only one answer is open at a time and the list stays short on a phone.
  3. Open the most asked question by default with the open attribute, so the first answer is visible without a click.
  4. To link straight to an answer, give the details an id and open it from the address: if location.hash names it, set open to true and scroll it into view.
Open the answer named in the address
const target = location.hash && document.querySelector(location.hash);
if (target && target.tagName === 'DETAILS') {
  target.open = true;
  target.scrollIntoView({ block: 'start' });
}

Showing an interaction like this to a client or in a tutorial? Framok records your screen and zooms in on every click for you.

Sources: Chrome for Developers, Animate to height: auto (interpolate-size from Chrome 129, ::details-content from Chrome 131), and MDN, the details element, for the name attribute.

Free to use in personal and commercial work. No credit needed, though a link back is always nice.

More from the library

See the whole library