Skip to content

Photo gallery with lightbox in React

A photo mosaic (dishes, dining room, terrace) that opens in a large lightbox with captions, a thumbnail strip, keyboard navigation and swipe.

Here is an excerpt of this component's code in React. The full code is free for members, ready to copy into your project.

This component also comes in

Open in a new tab

The code in React

PhotoLightboxGallery.tsx
import { useEffect, useRef, useState } from "react";
import type { KeyboardEvent, MouseEvent, PointerEvent } from "react";

// Replace each background with a real photo (an <img> with the same alt) when you have one.
const photos = [
  {
    size: "wide",
    kind: "Plat",
    title: "Filet de lieu, beurre blanc",
    description:
      "Le classique de la maison : lieu jaune de la criée, beurre blanc au muscadet et poireaux fondants.",
    alt: "Assiette blanche de poisson nappé de beurre blanc, vue de dessus sur une table vert sombre",

Free component: copy it freely, including for commercial projects.

Galleries and carousels components in React
  • A product photo that zooms in under the pointer, and from the keyboard with Enter and the arrow keys, to inspect the details.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Building site photos sorted by dated step on a vertical timeline, with the current step highlighted.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • YouTube videos shown as thumbnails: the player only loads on click, to respect privacy and keep the page light.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A slideshow that fills the whole screen, browsed with the keyboard or a finger swipe, and closed with Escape.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component