Skip to content
IndexRequest a UIAboutContact

Accordion

A stack of sections where opening one closes the others, with keyboard arrow navigation.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Create a single-open accordion with three items ("Shipping", "Returns", "Warranty"). Each item has a button header (48px tall, 14px medium text, a plus icon on the right made from two CSS bars) and a panel with a short paragraph. Opening an item closes the others. Animate panels with grid-template-rows from 0fr to 1fr over 260ms cubic-bezier(.2,.7,.2,1), with the inner element overflow hidden and min-height 0. When open, the vertical bar of the plus scales to 0 over 200ms to form a minus. Headers carry aria-expanded and aria-controls; panels use role region and aria-labelledby. ArrowDown and ArrowUp move focus to the next and previous header, Home and End jump to the first and last. Hover tints the header; focus-visible shows a 2px ring. Dividers are 1px lines. Under prefers-reduced-motion remove all transitions.

About this pattern

Definition

A vertical list of headings that each reveal a panel. In the single-open variant, opening one section closes the previous one so the list never grows beyond one open panel.

Purpose & UX principles

  • Good for FAQs and settings where people read one answer at a time.
  • Single-open keeps the page height stable and the user oriented.
  • Each header is a button with aria-expanded; Up and Down arrows move focus between headers.

Interaction states

  • Closed, open, hover (tint), focus-visible, pressed.
  • The plus icon becomes a minus when open.

Motion specification

  • Height animation with grid-template-rows, 260ms cubic-bezier(.2,.7,.2,1).
  • The plus icon's vertical bar scales to zero in 200ms.
  • Reduced motion: panels open instantly and the icon swaps without animation.

Responsive behaviour

  • Full width; headers are at least 48px tall for touch.
  • Long panel text wraps; no horizontal scrolling inside panels.

Code

HTML
<div class="acc" id="acc">
  <div class="item"><h3><button class="hd" id="a1" aria-expanded="true" aria-controls="p1">Shipping<i></i></button></h3><div class="pn open" id="p1" role="region" aria-labelledby="a1"><div class="in"><p>Orders ship within 2 business days. Tracking is emailed once the parcel leaves.</p></div></div></div>
  <div class="item"><h3><button class="hd" id="a2" aria-expanded="false" aria-controls="p2">Returns<i></i></button></h3><div class="pn" id="p2" role="region" aria-labelledby="a2"><div class="in"><p>Return unused items within 30 days for a full refund to the original payment method.</p></div></div></div>
  <div class="item"><h3><button class="hd" id="a3" aria-expanded="false" aria-controls="p3">Warranty<i></i></button></h3><div class="pn" id="p3" role="region" aria-labelledby="a3"><div class="in"><p>Every product includes a two year limited warranty against manufacturing defects.</p></div></div></div>
</div>

Related patterns

Expandable Card

↗
Expandable CardCards & Containers

Tab Navigation

↗
Tab NavigationNavigation

Interactive Card

↗
Interactive CardCards & Containers