Snippets Card

Bootstrap 5 Masonry Image Gallery with Filter and Lightbox

A responsive masonry photo gallery with category filter pills, hover captions and a click-to-enlarge lightbox.

Bootstrap 5 No jQuery Oct 2019 6.6K views

<section class="wdw-stage align-items-start">
  <div class="container" style="max-width:1100px">
    <div class="d-flex flex-wrap justify-content-between align-items-end gap-3 mb-4">
      <div><span class="wdw-eyebrow">Gallery</span><h2 class="wdw-heading h2 mt-1 mb-0">Tech and workspace photos</h2></div>
      <div class="d-flex flex-wrap gap-2 gal-filters" role="group" aria-label="Filter photos">
        <button type="button" class="btn btn-sm rounded-pill active" data-filter="all" aria-pressed="true">All</button>
        <button type="button" class="btn btn-sm rounded-pill" data-filter="Code" aria-pressed="false">Code</button>
        <button type="button" class="btn btn-sm rounded-pill" data-filter="Hardware" aria-pressed="false">Hardware</button>
        <button type="button" class="btn btn-sm rounded-pill" data-filter="Workspace" aria-pressed="false">Workspace</button>
      </div>
    </div>
    <div class="gal-grid" id="galGrid">
      <figure class="gal-item m-0" data-cat="Hardware"><button type="button" class="gal-btn" data-full="https://images.unsplash.com/photo-1518770660439-4636190af475?auto=format&fit=crop&w=1400&q=80" data-alt="Circuit board close-up" aria-label="Open photo: Circuit board close-up"><img src="https://images.unsplash.com/photo-1518770660439-4636190af475?auto=format&fit=crop&w=600&q=70" alt="Circuit board close-up" loading="lazy" style="aspect-ratio:4/3"><span class="gal-tag">Hardware</span></button></figure>
      <figure class="gal-item m-0" data-cat="Code"><button type="button" class="gal-btn" data-full="https://images.unsplash.com/photo-1461749280684-dccba630e2f6?auto=format&fit=crop&w=1400&q=80" data-alt="Source code on a dark editor" aria-label="Open photo: Source code on a dark editor"><img src="https://images.unsplash.com/photo-1461749280684-dccba630e2f6?auto=format&fit=crop&w=600&q=70" alt="Source code on a dark editor" loading="lazy" style="aspect-ratio:3/4"><span class="gal-tag">Code</span></button></figure>
      <figure class="gal-item m-0" data-cat="Workspace"><button type="button" class="gal-btn" data-full="https://images.unsplash.com/photo-1498050108023-c5249f4df085?auto=format&fit=crop&w=1400&q=80" data-alt="Laptop on a bright desk" aria-label="Open photo: Laptop on a bright desk"><img src="https://images.unsplash.com/photo-1498050108023-c5249f4df085?auto=format&fit=crop&w=600&q=70" alt="Laptop on a bright desk" loading="lazy" style="aspect-ratio:1/1"><span class="gal-tag">Workspace</span></button></figure>
      <figure class="gal-item m-0" data-cat="Hardware"><button type="button" class="gal-btn" data-full="https://images.unsplash.com/photo-1558494949-ef010cbdcc31?auto=format&fit=crop&w=1400&q=80" data-alt="Server rack with cables" aria-label="Open photo: Server rack with cables"><img src="https://images.unsplash.com/photo-1558494949-ef010cbdcc31?auto=format&fit=crop&w=600&q=70" alt="Server rack with cables" loading="lazy" style="aspect-ratio:3/4"><span class="gal-tag">Hardware</span></button></figure>
      <figure class="gal-item m-0" data-cat="Code"><button type="button" class="gal-btn" data-full="https://images.unsplash.com/photo-1487058792275-0ad4aaf24ca7?auto=format&fit=crop&w=1400&q=80" data-alt="Blurred lines of code" aria-label="Open photo: Blurred lines of code"><img src="https://images.unsplash.com/photo-1487058792275-0ad4aaf24ca7?auto=format&fit=crop&w=600&q=70" alt="Blurred lines of code" loading="lazy" style="aspect-ratio:4/3"><span class="gal-tag">Code</span></button></figure>
      <figure class="gal-item m-0" data-cat="Workspace"><button type="button" class="gal-btn" data-full="https://images.unsplash.com/photo-1519389950473-47ba0277781c?auto=format&fit=crop&w=1400&q=80" data-alt="Team laptops seen from above" aria-label="Open photo: Team laptops seen from above"><img src="https://images.unsplash.com/photo-1519389950473-47ba0277781c?auto=format&fit=crop&w=600&q=70" alt="Team laptops seen from above" loading="lazy" style="aspect-ratio:1/1"><span class="gal-tag">Workspace</span></button></figure>
      <figure class="gal-item m-0" data-cat="Hardware"><button type="button" class="gal-btn" data-full="https://images.unsplash.com/photo-1531297484001-80022131f5a1?auto=format&fit=crop&w=1400&q=80" data-alt="Laptop glowing in the dark" aria-label="Open photo: Laptop glowing in the dark"><img src="https://images.unsplash.com/photo-1531297484001-80022131f5a1?auto=format&fit=crop&w=600&q=70" alt="Laptop glowing in the dark" loading="lazy" style="aspect-ratio:4/3"><span class="gal-tag">Hardware</span></button></figure>
      <figure class="gal-item m-0" data-cat="Code"><button type="button" class="gal-btn" data-full="https://images.unsplash.com/photo-1555066931-4365d14bab8c?auto=format&fit=crop&w=1400&q=80" data-alt="Code open on a laptop" aria-label="Open photo: Code open on a laptop"><img src="https://images.unsplash.com/photo-1555066931-4365d14bab8c?auto=format&fit=crop&w=600&q=70" alt="Code open on a laptop" loading="lazy" style="aspect-ratio:3/4"><span class="gal-tag">Code</span></button></figure>
      <figure class="gal-item m-0" data-cat="Workspace"><button type="button" class="gal-btn" data-full="https://images.unsplash.com/photo-1504384308090-c894fdcc538d?auto=format&fit=crop&w=1400&q=80" data-alt="Open-plan office" aria-label="Open photo: Open-plan office"><img src="https://images.unsplash.com/photo-1504384308090-c894fdcc538d?auto=format&fit=crop&w=600&q=70" alt="Open-plan office" loading="lazy" style="aspect-ratio:4/3"><span class="gal-tag">Workspace</span></button></figure>
      <figure class="gal-item m-0" data-cat="Code"><button type="button" class="gal-btn" data-full="https://images.unsplash.com/photo-1555949963-ff9fe0c870eb?auto=format&fit=crop&w=1400&q=80" data-alt="Colourful code highlighting" aria-label="Open photo: Colourful code highlighting"><img src="https://images.unsplash.com/photo-1555949963-ff9fe0c870eb?auto=format&fit=crop&w=600&q=70" alt="Colourful code highlighting" loading="lazy" style="aspect-ratio:1/1"><span class="gal-tag">Code</span></button></figure>
      <figure class="gal-item m-0" data-cat="Hardware"><button type="button" class="gal-btn" data-full="https://images.unsplash.com/photo-1550751827-4bd374c3f58b?auto=format&fit=crop&w=1400&q=80" data-alt="Illuminated circuit traces" aria-label="Open photo: Illuminated circuit traces"><img src="https://images.unsplash.com/photo-1550751827-4bd374c3f58b?auto=format&fit=crop&w=600&q=70" alt="Illuminated circuit traces" loading="lazy" style="aspect-ratio:3/4"><span class="gal-tag">Hardware</span></button></figure>
      <figure class="gal-item m-0" data-cat="Workspace"><button type="button" class="gal-btn" data-full="https://images.unsplash.com/photo-1593642632559-0c6d3fc62b89?auto=format&fit=crop&w=1400&q=80" data-alt="Minimal desk by a window" aria-label="Open photo: Minimal desk by a window"><img src="https://images.unsplash.com/photo-1593642632559-0c6d3fc62b89?auto=format&fit=crop&w=600&q=70" alt="Minimal desk by a window" loading="lazy" style="aspect-ratio:4/3"><span class="gal-tag">Workspace</span></button></figure>
    </div>
  </div>
  <div class="modal fade" id="galModal" tabindex="-1" aria-label="Photo preview" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered modal-lg"><div class="modal-content border-0 overflow-hidden rounded-4">
      <button type="button" class="btn-close gal-close" data-bs-dismiss="modal" aria-label="Close"></button>
      <img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" alt="" class="img-fluid w-100" id="galModalImg">
    </div></div>
  </div>
</section>

Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.

Free to use in personal and commercial projects under the MIT license.