Image Accordion

A row of image panels where the hovered or focused one widens to show its caption.

Examples

Image accordion basic

Hover a panel with the mouse, tab to it with the keyboard, or tap it. Below the sm breakpoint the panels stack and grow in height.

Give an item an href and its panel becomes a link. Focus opens it before Enter follows it, and on a touch screen the first tap opens it and the second follows it.

Vertical

orientation='vertical' keeps the panels stacked at every width, for a narrow column.

Installation

npx shadcn@latest add https://ui.ndekocode.dev/r/motion-image-accordion.json

Component API

ImageAccordion

PropTypeDefaultDescription
itemsImageAccordionItem[]The panels.
defaultValuestringthe first idThe panel open first.
valuestringThe open panel, when controlled.
onValueChange(value: string) => voidCalled when another panel opens.
orientation'horizontal' | 'vertical''horizontal'Horizontal stacks below sm; vertical stacks at every width.
classNamestringClasses of the list. The height lives here (h-[28rem] sm:h-80 by default).

ImageAccordionItem

FieldTypeDescription
idstringA unique id.
srcstringThe image source.
altstringThe description of the image.
titlestringThe caption title, also the name of the panel.
descriptionstringAn optional second line in the caption.
hrefstringTurns the panel into a link.

The open panel grows through a flex-grow transition of 500ms on --ease-out-strong, so the panels share the row without measuring anything. The image stays centred and the panel crops it, so a widening panel reads as a window opening rather than a picture stretching. The caption arrives 150ms later and leaves in 100ms.