Expanding gallery
An image opens from its exact place in the grid, becomes a spacious viewer, and finds its way back.
Used forPortfolio and case studiesProduct screenshot galleriesListings and product photosTemplate and theme previews
Install with the shadcn CLI
Older shadcn CLI, or a network that blocks ui.shadcn.com? Install by URL: shadcn add https://hairlineui.com/r/expanding-gallery.json. More
Templates
Need the whole page?
65 Next.js landing pages, each designed from scratch. Try any of them live; one is $39, all of them $159, and 8 are free.
Where it’s used
Portfolio and case studies
Open a project from its thumbnail into a large viewer.
Product screenshot galleries
Let visitors look closely at the interface on a landing page.
Listings and product photos
Browse several photos of a property, a product or a venue.
Template and theme previews
Show a set of designs that open at full size.
What it handles for you
A gallery that opens a lightbox from nowhere loses the sense of which image you picked. This opens each image from its own place in the grid and sends it back there.
It opens from its thumbnail
The image grows from its exact place in the grid into the viewer, keeping its proportions. The caption follows a moment later.
It returns where it came from
Closing sends the current image back to its own thumbnail, or fades it if the thumbnail has scrolled out of view.
Browse by arrow, key or swipe
The next image arrives from the direction you moved. A swipe follows your finger and the ends resist.
Focus is handled
Focus stays inside the viewer, the page behind does not scroll, and Escape closes it and returns focus to the thumbnail.
Failed images are handled
A broken image shows a labelled fallback without changing the gallery’s size.
Real proportions
Each image has its own width and height, so wide and tall pictures sit in the grid without being cropped in the viewer.
Overview
A gallery with a sense of place. Select a study and the image grows from its thumbnail into a full-screen viewer, keeping its proportions. Its caption follows a moment later. Browse with the arrows, keyboard or a swipe; the next study arrives from the direction you moved. Close it and the current image returns to its own thumbnail. The viewer is a native modal dialog, so the page behind it stays inert and keyboard focus stays inside.
States
- open
- The viewer measures the thumbnail and destination, then expands the image over 560ms. The caption follows after 180ms.
- browse
- Previous and next images enter from the direction of travel in 380ms. Navigation stops at the ends.
- swipe
- The image follows horizontal dragging. A 64px drag or a deliberate quick flick advances; a short drag settles back. The ends resist movement.
- close
- The current image returns to its measured thumbnail in 380ms. If its thumbnail has left the viewport, it fades away instead.
- unavailable
- A failed image shows a labelled fallback without changing the gallery’s dimensions.
Usage
Depends on lucide-react, installed for you by the CLI along with the keyframes it needs.
Works with
Installs with it
Track the selected study
Use stable image IDs and real intrinsic dimensions. Supply your own local or remote image URLs.
Props
- images
- GalleryImage[]
- Stable id, src, alt, title, width and height; optional description and meta. Intrinsic proportions are preserved.
- label= Selected work
- string
- The gallery heading and viewer heading.
- onImageChange
- (image: GalleryImage | null) => void
- Called when a study opens or changes. Receives null on close.
- className
- string
- Additional classes on the gallery root. Standard div attributes are forwarded.
Accessibility and motion
- The viewer is a top-layer popover with role="dialog" and aria-modal: it opens above everything without making the page inert, which on a large page restyles every element in the frame it opens. Focus is trapped inside, the page behind does not scroll, Escape closes and focus returns to the current thumbnail, including after browsing.
- Left and Right browse, Home and End jump to the first and last image. Buttons expose disabled states at the ends.
- Pointer cancellation restores the image. Horizontal swipes leave vertical touch movement to the browser.
- Reduced motion removes expansion, sliding, overshoot and thumbnail zoom. Navigation and all controls remain available.
- Image IDs must be unique; width and height should match the source asset. The component handles an empty collection.
- The entry point, viewer and motion helpers install together. No global animation stylesheet or animation library is required.
Requirements
React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.
The CLI also installs Number roll, Text morph.
Source
Registry item: /r/expanding-gallery.json


