Browse docs

Accordion

Collapsible disclosure using native details/summary with auto-height animation.

stableSince 0.2.0

On this page
  1. Semantic HTML
  2. Animation strategy
  3. Class contract
ExampleScroll inside to see moreOpen in a new page

The .pl-c-accordion wraps <details>/<summary> elements for a collapsible disclosure UI. Animates open/close to/from height: auto using interpolate-size: allow-keywords where supported, with a universal grid-template-rows: 0fr to 1fr fallback.

Semantic HTML

<div class="pl-c-accordion">
  <!-- Streamlined modern markup (::details-content in Chrome 131+) -->
  <details class="pl-c-accordion__item">
    <summary class="pl-c-accordion__header">
      <span>Section title</span>
      <svg class="pl-c-accordion__icon">...</svg>
    </summary>
    <div class="pl-c-accordion__content">Content goes here.</div>
  </details>

  <!-- Legacy wrapper structure (works in all browsers via grid fallback) -->
  <details class="pl-c-accordion__item">
    <summary class="pl-c-accordion__header">
      <span>Section with panel wrapper</span>
      <svg class="pl-c-accordion__icon">...</svg>
    </summary>
    <div class="pl-c-accordion__panel">
      <div class="pl-c-accordion__content">Content goes here.</div>
    </div>
  </details>
</div>

Animation strategy

Three techniques are layered progressively:

  1. Native ::details-content (Chrome 131+, Safari 18.4+): The browser targets the disclosure box directly with block-size: 0 to auto and interpolate-size: allow-keywords. The .pl-c-accordion__panel wrapper is completely optional.
  2. interpolate-size with panel wrapper: For browsers that support keyword interpolation without ::details-content, the panel wrapper animates block-size directly.
  3. Universal fallback: grid-template-rows: 0fr to 1fr on the panel wrapper. Works across all legacy browsers.

Class contract

Selector Role
.pl-c-accordion Container for items.
.pl-c-accordion__item A <details> element.
.pl-c-accordion__header The <summary> (click target).
.pl-c-accordion__icon Chevron icon (rotates on open).
.pl-c-accordion__panel Optional animated wrapper (fallback for older browsers).
.pl-c-accordion__content Inner content (padding + typography).

Search Porchlight