Skip to content

Photo gallery with lightbox in HTML and CSS

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 HTML and CSS. 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 HTML and CSS

index.html
<!doctype html>
<html lang="fr">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Galerie photos avec agrandissement</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <main class="demo">
      <section class="glb" aria-labelledby="glb-title" data-glb>
        <div class="glb__head">
script.js
document.querySelectorAll("[data-glb]").forEach((root) => {
  const items = [...root.querySelectorAll("[data-glb-item]")];
  const viewer = root.querySelector("[data-glb-viewer]");
  const photo = viewer.querySelector("[data-glb-photo]");
  const count = viewer.querySelector("[data-glb-count]");
  const title = viewer.querySelector("[data-glb-title]");
  const kind = viewer.querySelector("[data-glb-tag]");
  const text = viewer.querySelector("[data-glb-text]");
  const strip = viewer.querySelector("[data-glb-strip]");
  const model = viewer.querySelector("[data-glb-thumb]").content.firstElementChild;
  const still = matchMedia("(prefers-reduced-motion: reduce)");
  let index = 0;
style.css
:root {
  /* Rounded corners of the tiles: 0 for a strict grid, 28px for softer, organic shapes. */
  --glb-radius: 14px;
  --glb-text: #1f2a24;
  --glb-muted: #4f5d56;
  --glb-accent: #a63d1b;
  --glb-ring: #a63d1b;
  --demo-bg: #f7f4ee;
  --demo-text: #1f2a24;
}

@media (prefers-color-scheme: dark) {

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

Galleries and carousels components in HTML and CSS
  • 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