Skip to content
IndexRequest a UIAboutContact

Expandable Card

A card that expands in place to reveal more content, with a smooth height animation.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Create an expandable card 320px wide. The header is a full-width button containing a 14px semibold title ("Order #4821"), a 12px secondary line ("Arriving Thursday") and a chevron icon on the right. Below it is a detail area with three rows of order information. Hidden by default. Animate the open and close with CSS grid: wrap the details in a container with display grid and grid-template-rows 0fr (collapsed) to 1fr (expanded), transition 280ms cubic-bezier(.2,.7,.2,1), with the inner element overflow hidden and min-height 0. Rotate the chevron 180deg in 220ms. The button has aria-expanded and aria-controls pointing at the region, and the region has role region and aria-labelledby. Hover tints the header with a light surface colour. Show a 2px focus-visible ring. Support Enter and Space natively through the button. Under prefers-reduced-motion remove all transitions.

About this pattern

Definition

A card with a summary row and a hidden detail area. Activating the header grows the card to show the details without leaving the page, and activating it again collapses it.

Purpose & UX principles

  • Keeps lists scannable while letting people open only what they care about.
  • Uses a real button with aria-expanded and aria-controls, so the pattern works with keyboard and assistive technology.
  • Animating the height gives continuity: content below moves smoothly instead of jumping.

Interaction states

  • Collapsed, expanded, hover (header tint), focus-visible ring, pressed.
  • The chevron rotates 180 degrees when expanded.

Motion specification

  • Height uses the grid-template-rows 0fr to 1fr technique, 280ms cubic-bezier(.2,.7,.2,1).
  • Chevron rotation 220ms; content fades in 180ms after the height starts.
  • Reduced motion: the card opens instantly with no height animation or rotation.

Responsive behaviour

  • Full width of the container; the toggle button spans the card header for a large touch target.
  • Long content scrolls with the page, not inside the card.

Code

HTML
<article class="card">
  <button class="head" id="h" aria-expanded="false" aria-controls="d">
    <span><b>Order #4821</b><small>Arriving Thursday</small></span>
    <svg viewBox="0 0 24 24" width="18" height="18" aria-hidden="true"><path d="M6 9l6 6 6-6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
  </button>
  <div class="panel" id="d" role="region" aria-labelledby="h"><div class="in">
    <div class="row"><span>Items</span><b>3</b></div>
    <div class="row"><span>Shipping</span><b>Free</b></div>
    <div class="row"><span>Total</span><b>$84.00</b></div>
  </div></div>
</article>

Related patterns

Accordion

↗
AccordionCards & Containers

Interactive Card

↗
Interactive CardCards & Containers

Hover Reveal Card

↗
Hover Reveal CardCards & Containers