Skip to content

Accordion

Accordions built on `<details>` / `<summary>`, with an optional managed structure for measured height animation.

<pe-accordion class="Accordion">
<details class="Item" data-accordion-item data-accordion-value="shipping" name="faq">
  <summary class="Trigger">How long does shipping take?</summary>
  <p class="Content">Standard shipping arrives within three to five business days.</p>
</details>
<details class="Item" data-accordion-item data-accordion-value="returns" name="faq">
  <summary class="Trigger">Can I return an item?</summary>
  <p class="Content">Unused items can be returned within 30 days.</p>
</details>
</pe-accordion>

Accordion groups multiple related disclosure items together. The standard structure uses <details> / <summary>. Give each <details> the same name for single-open behavior, or omit it to allow multiple items. Content in that structure can be animated with ::details-content where supported.

Managed alternative for required height animation

Section titled “Managed alternative for required height animation”

Use managed items only when measured height animation or custom trigger/panel structure is required:

<pe-accordion class="Accordion" data-accordion-single data-accordion-hidden-until-found>
<div class="Item" data-accordion-item data-accordion-value="shipping">
<h3 class="Header">
<button type="button" class="Trigger" data-accordion-trigger>Shipping</button>
</h3>
<div class="Panel" data-accordion-panel>
<div class="Content">Shipping information.</div>
</div>
</div>
</pe-accordion>

Do not mix native and managed items in one host. Add data-accordion-hidden-until-found when closed content must remain available to browser find-in-page.

<pe-accordion class="Accordion" data-accordion-single data-accordion-hidden-until-found>
<div class="Item" data-accordion-item data-accordion-value="shipping">
  <h3 class="Header">
    <button type="button" class="Trigger" data-accordion-trigger>Shipping</button>
  </h3>
  <div class="Panel" data-accordion-panel>
    <div class="Content">Shipping information.</div>
  </div>
</div>
</pe-accordion>
Part Native selector Managed selector
Host <pe-accordion> <pe-accordion>
Item details[data-accordion-item] div[data-accordion-item]
Trigger Direct <summary> child <button data-accordion-trigger>
Panel Native details content [data-accordion-panel]
Open state open on item data-accordion-open on item
Value data-accordion-value on item data-accordion-value on item

Managed accordions allow multiple open items by default; add data-accordion-single for one at a time. All parts expose data-state="open|closed".

NameDescription
data-accordion-openOn a managed div item: reflects its open state and can be changed externally.
data-accordion-singleOn a managed host: allows only one managed item to remain open.
data-accordion-hidden-until-foundOn a managed host or panel: uses hidden="until-found" while closed and opens synchronously on beforematch.
NameTypeDescription
open(valueOrItem)voidOpens an item by data-accordion-value or details/div element reference.
close(valueOrItem)voidCloses an item by value or element reference.
toggle(valueOrItem)voidToggles an item by value or element reference.

The host’s value property gets or sets an array of open data-accordion-value strings. Its disabled boolean property reflects root data-accordion-disabled. Native details[name] and managed data-accordion-single determine whether multiple requested values can remain open.

NameTypeDescription
valuestring[]Gets or sets open item values from `data-accordion-value`.
disabledbooleanGets or sets root disabled state via `data-accordion-disabled`.
NameDescription
data-accordion-itemMarks a native `<details>` or managed `<div>` item.
data-accordion-valueStable string identifier for programmatic open/close/toggle.
data-accordion-openOn managed items: marks the initial or current open state.
data-accordion-disabledOn the host or an item: ignores user interaction.
data-stateOn items, triggers, and panels: "open" or "closed".
data-indexZero-based item index within the host.
data-disabledOn the host when root disabled: present as an empty attribute.
NameDescription
pe-accordion:openBubbles and is composed. Fired when an item opens.
pe-accordion:closeBubbles and is composed. Fired when an item closes.

Event detail fields: item, trigger, summary (alias of trigger), panel (null on native items), optional value, index, and reason (trigger, programmatic, attribute, beforematch, or native). The native toggle event remains available on each <details>.

An open managed panel exposes --accordion-panel-height and --accordion-panel-width while enter and exit transitions run.

.Panel {
height: var(--accordion-panel-height);
overflow: hidden;
transition: height 160ms ease;
}
.Panel[data-starting-style],
.Panel[data-ending-style] {
height: 0;
}

Closed managed panels are hidden after finite exit animations finish. beforematch skips the opening animation so the browser can scroll immediately.