Expandable Card

A card that unfolds to show what it was hiding

The height animates to auto, the chevron flips, and nothing below the card jumps.

Create an expandable card. A card with a header row that, when clicked, smoothly unfolds a hidden content area below it; clicking again folds it back. The hard part is animating to an unknown height. With Framer Motion: animate height between 0 and 'auto' (it measures for you) with { duration: 0.35, ease: cubic-bezier(0.22, 1, 0.36, 1) }, opacity 0 to 1 slightly faster, and overflow: hidden on the animating wrapper. Vanilla JS: measure scrollHeight, animate max-height or height to that pixel value, then set height: auto after the transition ends (and reverse by fixing the height first). Details: a chevron icon in the header rotates 180deg in sync with the fold (300ms); the header is a real button with aria-expanded and aria-controls pointing at the content region; content below the card gets pushed down smoothly by the same animation, never jumps. In accordion groups, opening one may close the others. Under prefers-reduced-motion, toggle instantly with no height animation. Build the component, not this demo of it. - Ambient motion that IS the component may loop: a drifting background, a marquee, a spinner while something is genuinely loading. - Do not add any timer, interval, loop or script that performs a person's action by itself. No auto-hover, no auto-click, no cycling through states, no pretend submitting, no replaying the interaction on a schedule. - Every state that answers a person waits for a real event from that person. - Placeholder copy and sample content are welcome. Simulated behaviour is not.

Rate it
0
0

We'd like to measure how the site gets used, with Google Analytics. It sets cookies. Everything the site needs to work runs either way. How we handle data