Skip to content

Block 26 of 297

Image Gallery

A captioned photo grid where each photo opens a full-screen view with next, previous and close links, no JavaScript.

Puck key
ImageGalleryBlock
Export
imageGalleryBlock
React component
<ImageGallery />
Path
components/puck/image-gallery-block.tsx
Dependencies
None
License
MIT

About this block

When to use it, how to write for it, and what to change in the code.

What it's for

A captioned grid of up to 24 photos where each thumbnail opens a full-screen view with previous, next and close links plus the caption and credit. The viewer is built on URL fragments and the CSS :target selector, so there is no JavaScript. Thumbnails crop to one shape you choose; the full-size view shows the whole photo. Phones show a single column.

  • Event or season recap photos
  • A facility, venue or rental space tour
  • Before-and-after or progress photos for a project
Writing the content
  • Fill in Alt text for every photo; each thumbnail is a link, so the alt is its name. Blank alt falls back to the caption, then "Photo 3 of 12".
  • Use large source images, since the same URL is shown full-screen.
  • Pick Thumbnail shape to suit most of your photos; Portrait 4:5 suits people, Landscape 4:3 suits places.
  • Credit appears only in the full-size view, so put required attribution there and keep Caption for context.
Accessibility
  • Every control (thumbnail, previous, next, close) is a real link, so the viewer works with a keyboard and without scripts (WCAG 2.1.1). Each thumbnail adds hidden ", open full size" text.
  • Each full-size view is a group labeled "Photo 3 of 12", with previous and next in a nav labeled Gallery.
  • Because it's CSS only, Escape does not close the viewer and focus is not trapped inside it; the Close link returns to the thumbnail. The hover zoom is turned off under reduced motion.
Customizing the code
  • Columns are set in gridCols and shapes in shapeClass (aspect-4/3, aspect-square, aspect-4/5).
  • The overlay background is bg-neutral-950/95 on the fixed target:flex container; add a small script if you need Escape to close it.

Editor fields

What content editors see in the P1 sidebar when they select this block.

  • Headingtext
  • Heading levelselect
  • Introtextarea
  • Columnsselect
  • Thumbnail shapeselect
  • Photosarray