Blocks/Content/Gallery/Gallery Lightbox

Photo gallery with lightbox

Photo grid where clicking any photo opens it full-screen in a lightbox with previous / next buttons and a caption. Built from the data-lightbox runtime attributes (the grid tiles name a popover viewer) — no custom JavaScript or inject code. Close with the X, a backdrop click, or Escape. Using it twice on one page: rename the gallery-lightbox* ids in the second copy.

gallerylightboxphotosportfolioprojectsimageszoomclick to enlargesection

About this block

A grid of photos where tapping any one opens it full size over a dark backdrop. Visitors get a quick overview from the thumbnails and a close look at the shots they care about, without leaving the page. It suits any business whose work sells best when people can see it.

When to use it

  • You want to show finished jobs: builds, renovations, gardens, haircuts, cakes, events.
  • Your photos have detail that gets lost at thumbnail size.
  • A portfolio or "Our work" page needs a gallery that also works well on phones.
  • You want proof of quality near a quote form or contact section.

What's inside

  • An h2 heading and a short line of intro text above the grid.
  • 6 photos in rounded tiles, 2 columns on phones and 3 from tablet width up. Each tile zooms slightly on hover.
  • Tapping a tile opens a full-screen viewer with that photo as large as the screen allows, a caption from the photo’s alt text, previous and next buttons and a close button above it.
  • The viewer closes with the close button, a tap on the dark area around the photo, or the Escape key. Taps on the photo itself keep it open.
  • Every photo has alt text, and the viewer is announced to screen readers as a photo viewer.

How to customize it

  • Swap in your own photos: change the image on each tile (the viewer shows the same file, so there is one image per photo) and keep the alt text, which becomes the caption.
  • Use landscape photos of a similar shape so the grid stays even. The tiles crop to a 4:3 shape.
  • To add a photo, duplicate a tile inside the grid. The previous / next buttons step through every tile that holds an image.
  • Write alt text that says what the photo shows, like "Kitchen with oak island after renovation", not "photo 3".

Questions

Will a photo gallery slow down my page?
Photos are the main cost. Upload them through the media library so they are compressed and served at sensible sizes, and keep each gallery to a dozen or so photos.
Can I use this gallery twice on one page?
Yes, but rename the ids in the second copy: the viewer (gallery-lightbox), its caption and the grid (gallery-lightbox-grid), and the data-lightbox, data-lightbox-grid, data-lightbox-caption and commandfor values that name them. Otherwise both grids open the same viewer.
Does the lightbox work on phones?
Yes. On a phone the photo fills the width of the screen and the close button sits just above it. Tap outside the photo to close.

Browse other blocks

Same library cards — preview live and grab the code from any block.

View full library