Bootstrap 5 Photo Gallery with Modal Lightbox
A bento-style photo gallery with a featured tile, caption overlays and a modal lightbox with previous and next controls, arrow-key support and a photo counter.
<section class="wdw-stage gl-stage">
<div class="container" style="max-width:1000px">
<div class="d-flex flex-column flex-sm-row justify-content-between align-items-sm-end gap-2 mb-4">
<div><span class="wdw-eyebrow mb-1">Gallery</span><h2 class="wdw-heading h2 mb-0">Good dogs, 2024</h2></div>
<p class="wdw-muted mb-0">Select any photo to view it full size.</p>
</div>
<div class="gl-grid">
<button type="button" class="gl-card gl-feat" aria-haspopup="dialog" data-bs-toggle="modal" data-bs-target="#gl-modal" data-src="https://images.unsplash.com/photo-1544568100-847a948585b9?auto=format&fit=crop&w=1600&q=80" data-title="The good ol' boy" data-sub="Trail walk, 2024">
<img src="https://images.unsplash.com/photo-1544568100-847a948585b9?auto=format&fit=crop&w=1000&h=800&q=75" width="1000" height="800" loading="lazy" alt="The good ol' boy" class="gl-img">
<span class="gl-scrim"><span class="gl-cap"><span class="d-block fw-semibold">The good ol' boy</span><span class="d-block small gl-sub">Trail walk, 2024</span></span><span class="gl-open">Open photo</span></span>
</button>
<button type="button" class="gl-card" aria-haspopup="dialog" data-bs-toggle="modal" data-bs-target="#gl-modal" data-src="https://images.unsplash.com/photo-1517423440428-a5a00ad493e8?auto=format&fit=crop&w=1600&q=80" data-title="Mr I didn't do it" data-sub="Studio portrait">
<img src="https://images.unsplash.com/photo-1517423440428-a5a00ad493e8?auto=format&fit=crop&w=600&h=600&q=75" width="600" height="600" loading="lazy" alt="Mr I didn't do it" class="gl-img">
<span class="gl-scrim"><span class="gl-cap"><span class="d-block fw-semibold">Mr I didn't do it</span><span class="d-block small gl-sub">Studio portrait</span></span><span class="gl-open">Open photo</span></span>
</button>
<button type="button" class="gl-card" aria-haspopup="dialog" data-bs-toggle="modal" data-bs-target="#gl-modal" data-src="https://images.unsplash.com/photo-1510771463146-e89e6e86560e?auto=format&fit=crop&w=1600&q=80" data-title="Spring sniff" data-sub="Garden">
<img src="https://images.unsplash.com/photo-1510771463146-e89e6e86560e?auto=format&fit=crop&w=600&h=600&q=75" width="600" height="600" loading="lazy" alt="Spring sniff" class="gl-img">
<span class="gl-scrim"><span class="gl-cap"><span class="d-block fw-semibold">Spring sniff</span><span class="d-block small gl-sub">Garden</span></span><span class="gl-open">Open photo</span></span>
</button>
<button type="button" class="gl-card" aria-haspopup="dialog" data-bs-toggle="modal" data-bs-target="#gl-modal" data-src="https://images.unsplash.com/photo-1507146426996-ef05306b995a?auto=format&fit=crop&w=1600&q=80" data-title="Sunny puppy" data-sub="First summer">
<img src="https://images.unsplash.com/photo-1507146426996-ef05306b995a?auto=format&fit=crop&w=600&h=600&q=75" width="600" height="600" loading="lazy" alt="Sunny puppy" class="gl-img">
<span class="gl-scrim"><span class="gl-cap"><span class="d-block fw-semibold">Sunny puppy</span><span class="d-block small gl-sub">First summer</span></span><span class="gl-open">Open photo</span></span>
</button>
<button type="button" class="gl-card" aria-haspopup="dialog" data-bs-toggle="modal" data-bs-target="#gl-modal" data-src="https://images.unsplash.com/photo-1530281700549-e82e7bf110d6?auto=format&fit=crop&w=1600&q=80" data-title="Wide smile" data-sub="Park day">
<img src="https://images.unsplash.com/photo-1530281700549-e82e7bf110d6?auto=format&fit=crop&w=600&h=600&q=75" width="600" height="600" loading="lazy" alt="Wide smile" class="gl-img">
<span class="gl-scrim"><span class="gl-cap"><span class="d-block fw-semibold">Wide smile</span><span class="d-block small gl-sub">Park day</span></span><span class="gl-open">Open photo</span></span>
</button>
<button type="button" class="gl-card gl-wide" aria-haspopup="dialog" data-bs-toggle="modal" data-bs-target="#gl-modal" data-src="https://images.unsplash.com/photo-1548199973-03cce0bbc87b?auto=format&fit=crop&w=1600&q=80" data-title="Best friends" data-sub="Beach run">
<img src="https://images.unsplash.com/photo-1548199973-03cce0bbc87b?auto=format&fit=crop&w=900&h=450&q=75" width="900" height="450" loading="lazy" alt="Best friends" class="gl-img">
<span class="gl-scrim"><span class="gl-cap"><span class="d-block fw-semibold">Best friends</span><span class="d-block small gl-sub">Beach run</span></span><span class="gl-open">Open photo</span></span>
</button>
</div>
</div>
</section>
<div class="modal fade" id="gl-modal" tabindex="-1" aria-labelledby="gl-title" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-xl modal-fullscreen-md-down">
<div class="modal-content gl-modal-content overflow-hidden border-0">
<button type="button" class="btn-close btn-close-white gl-close" data-bs-dismiss="modal" aria-label="Close"></button>
<div class="gl-stagebox position-relative">
<div id="gl-big" class="d-flex justify-content-center w-100"></div>
<button type="button" class="gl-nav gl-prev" id="gl-prev" aria-label="Previous photo"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M15 5l-7 7 7 7"/></svg></button>
<button type="button" class="gl-nav gl-next" id="gl-next" aria-label="Next photo"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 5l7 7-7 7"/></svg></button>
</div>
<div class="d-flex justify-content-between align-items-center gap-3 px-4 py-3">
<h3 class="h6 fw-bold mb-0" id="gl-title">Photo</h3>
<span class="small gl-count" id="gl-count" aria-live="polite">1 / 6</span>
</div>
</div>
</div>
</div>
/* Web Designer Wall library style — shared base for every Bootstrap 5 snippet.
Indigo accent, Plus Jakarta Sans, soft cards, pill buttons. Works in light and dark. */
@import url("https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap");
:root,
[data-bs-theme="light"] {
--wdw-font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
--bs-body-font-family: var(--wdw-font);
--bs-primary: #4f46e5;
--bs-primary-rgb: 79, 70, 229;
--bs-primary-text-emphasis: #3730a3;
--bs-primary-bg-subtle: #eef2ff;
--bs-primary-border-subtle: #c7d2fe;
--bs-link-color: #4f46e5;
--bs-link-color-rgb: 79, 70, 229;
--bs-link-hover-color: #4338ca;
--bs-link-hover-color-rgb: 67, 56, 202;
--bs-focus-ring-color: rgba(79, 70, 229, 0.25);
--bs-border-radius: 0.75rem;
--bs-border-radius-lg: 1rem;
--bs-border-radius-xl: 1.25rem;
--wdw-radius-card: 1.25rem;
--wdw-shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 16px 40px -16px rgba(16, 24, 40, 0.22);
--wdw-shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 12px -4px rgba(16, 24, 40, 0.12);
--wdw-stage: #f5f6fb;
}
[data-bs-theme="dark"] {
--bs-primary: #818cf8;
--bs-primary-rgb: 129, 140, 248;
--bs-primary-text-emphasis: #c7d2fe;
--bs-primary-bg-subtle: rgba(129, 140, 248, 0.14);
--bs-primary-border-subtle: rgba(129, 140, 248, 0.35);
--bs-link-color: #a5b4fc;
--bs-link-color-rgb: 165, 180, 252;
--bs-link-hover-color: #c7d2fe;
--bs-link-hover-color-rgb: 199, 210, 254;
--bs-focus-ring-color: rgba(129, 140, 248, 0.35);
--wdw-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 16px 40px -16px rgba(0, 0, 0, 0.7);
--wdw-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px -4px rgba(0, 0, 0, 0.5);
--wdw-stage: #0f1117;
}
body { font-family: var(--wdw-font); -webkit-font-smoothing: antialiased; }
/* Bootstrap compiles its blue into these components; point them at the accent. */
.btn-primary {
--bs-btn-bg: var(--bs-primary); --bs-btn-border-color: var(--bs-primary);
--bs-btn-hover-bg: #4338ca; --bs-btn-hover-border-color: #4338ca;
--bs-btn-active-bg: #3730a3; --bs-btn-active-border-color: #3730a3;
--bs-btn-disabled-bg: var(--bs-primary); --bs-btn-disabled-border-color: var(--bs-primary);
--bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
[data-bs-theme="dark"] .btn-primary { --bs-btn-color: #0f1117; --bs-btn-hover-bg: #a5b4fc; --bs-btn-hover-border-color: #a5b4fc; --bs-btn-hover-color: #0f1117; --bs-btn-active-color: #0f1117; }
.btn-outline-primary {
--bs-btn-color: var(--bs-primary); --bs-btn-border-color: var(--bs-primary);
--bs-btn-hover-bg: var(--bs-primary); --bs-btn-hover-border-color: var(--bs-primary);
--bs-btn-active-bg: var(--bs-primary); --bs-btn-active-border-color: var(--bs-primary);
--bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
.btn { --bs-btn-font-weight: 600; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; }
.btn-sm { min-height: 36px; }
.form-control, .form-select { min-height: 44px; border-radius: .75rem; }
.form-control:focus, .form-select:focus, .form-check-input:focus { border-color: rgba(var(--bs-primary-rgb), .6); box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.form-check-input:checked { background-color: var(--bs-primary); border-color: var(--bs-primary); }
.nav-pills { --bs-nav-pills-link-active-bg: var(--bs-primary); }
.nav { --bs-nav-link-color: var(--bs-secondary-color); --bs-nav-link-hover-color: var(--bs-emphasis-color); }
.pagination { --bs-pagination-active-bg: var(--bs-primary); --bs-pagination-active-border-color: var(--bs-primary); --bs-pagination-color: var(--bs-body-color); --bs-pagination-focus-box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.progress, .progress-stacked { --bs-progress-bar-bg: var(--bs-primary); }
.list-group { --bs-list-group-active-bg: var(--bs-primary); --bs-list-group-active-border-color: var(--bs-primary); }
.dropdown-menu { --bs-dropdown-link-active-bg: var(--bs-primary); border-radius: .875rem; box-shadow: var(--wdw-shadow-sm); }
.accordion { --bs-accordion-active-bg: var(--bs-primary-bg-subtle); --bs-accordion-active-color: var(--bs-primary-text-emphasis); --bs-accordion-btn-focus-box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.badge { font-weight: 600; }
/* Library building blocks — use these instead of re-inventing them per snippet. */
.wdw-stage { min-height: 100vh; display: flex; align-items: center; background: var(--wdw-stage); padding-block: 3rem; }
.wdw-card { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: var(--wdw-radius-card); box-shadow: var(--wdw-shadow); }
.wdw-card-sm { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: 1rem; box-shadow: var(--wdw-shadow-sm); }
.wdw-aurora { position: relative; color: #fff; background: radial-gradient(60% 55% at 100% 0, #818cf8 0, transparent 70%), radial-gradient(65% 60% at 0 100%, #ec4899 0, transparent 65%), #1e1b4b; }
.wdw-eyebrow { display: inline-block; font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--bs-primary); }
.wdw-heading { font-weight: 800; letter-spacing: -.02em; color: var(--bs-emphasis-color); }
.wdw-muted { color: var(--bs-secondary-color); }
.wdw-icon { width: 2.75rem; height: 2.75rem; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: .875rem; background: var(--bs-primary-bg-subtle); color: var(--bs-primary); }
/* Component */
.gl-stage{padding-block:2rem}
.gl-grid{display:grid;grid-template-columns:repeat(2,1fr);grid-auto-rows:170px;gap:.75rem}
.gl-feat{grid-column:span 2;grid-row:span 2}
.gl-wide{grid-column:span 2}
@media (min-width:768px){.gl-grid{grid-template-columns:repeat(5,1fr);grid-auto-rows:minmax(0,215px);gap:1rem}}
.gl-card{position:relative;display:block;padding:0;border:0;overflow:hidden;border-radius:1.25rem;background:var(--bs-tertiary-bg);box-shadow:var(--wdw-shadow-sm);color:#fff;text-align:left;transition:box-shadow .25s ease}
.gl-card:hover{box-shadow:var(--wdw-shadow)}
.gl-card:focus-visible{outline:2px solid var(--bs-primary);outline-offset:3px}
.gl-img{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;transition:transform .5s ease}
.gl-card:hover .gl-img{transform:scale(1.05)}
.gl-scrim{position:absolute;inset:0;display:flex;align-items:flex-end;justify-content:space-between;gap:.5rem;padding:.9rem;background:linear-gradient(to top,rgba(10,10,25,.8) 0,rgba(10,10,25,0) 55%)}
.gl-cap{min-width:0}
.gl-sub{color:rgba(255,255,255,.8)}
.gl-open{position:absolute;top:.75rem;right:.75rem;flex:none;font-size:.75rem;font-weight:600;padding:.25rem .65rem;border-radius:2rem;background:rgba(255,255,255,.2);backdrop-filter:blur(6px);opacity:0;transform:translateY(4px);transition:opacity .2s,transform .2s}
.gl-card:hover .gl-open,.gl-card:focus-visible .gl-open{opacity:1;transform:none}
@media (hover:none){.gl-open{opacity:1;transform:none}}
.gl-modal-content{background:#0b0b14;color:#fff}
.gl-stagebox{display:flex;align-items:center;justify-content:center;background:#000}
.gl-img-big{display:block;max-width:100%;max-height:72vh;width:auto;object-fit:contain}
@media (max-width:767.98px){.gl-img-big{max-height:none;width:100%}}
.gl-close{position:absolute;top:.75rem;right:.75rem;z-index:5;width:2.5rem;height:2.5rem;padding:0;display:flex;align-items:center;justify-content:center;background-color:rgba(0,0,0,.6);background-size:.8rem;border-radius:50%;opacity:1}
.gl-nav{position:absolute;top:50%;z-index:4;width:2.75rem;height:2.75rem;margin-top:-1.375rem;display:flex;align-items:center;justify-content:center;border:0;border-radius:50%;background:rgba(0,0,0,.6);color:#fff}
.gl-nav:hover{background:rgba(0,0,0,.8)}
.gl-nav:focus-visible{outline:2px solid #fff;outline-offset:2px}
.gl-prev{left:.75rem}.gl-next{right:.75rem}
.gl-count{color:rgba(255,255,255,.75);font-variant-numeric:tabular-nums}
@media (prefers-reduced-motion:reduce){.gl-card,.gl-img,.gl-open{transition:none}}
function initGallery() {
var modal = document.getElementById('gl-modal');
if (!modal) return;
var cards = Array.prototype.slice.call(document.querySelectorAll('.gl-card'));
var big = document.getElementById('gl-big');
var title = document.getElementById('gl-title');
var count = document.getElementById('gl-count');
var current = 0;
function show(i) {
current = (i + cards.length) % cards.length;
var c = cards[current];
var img = document.createElement('img');
img.className = 'gl-img-big';
img.alt = c.dataset.title;
img.src = c.dataset.src;
big.replaceChildren(img);
title.textContent = c.dataset.title + ' – ' + c.dataset.sub;
count.textContent = (current + 1) + ' / ' + cards.length;
}
modal.addEventListener('show.bs.modal', function (e) {
var idx = cards.indexOf(e.relatedTarget);
show(idx < 0 ? 0 : idx);
});
modal.addEventListener('hidden.bs.modal', function () { big.replaceChildren(); });
document.getElementById('gl-prev').addEventListener('click', function () { show(current - 1); });
document.getElementById('gl-next').addEventListener('click', function () { show(current + 1); });
modal.addEventListener('keydown', function (e) {
if (e.key === 'ArrowLeft') { e.preventDefault(); show(current - 1); }
if (e.key === 'ArrowRight') { e.preventDefault(); show(current + 1); }
});
}
initGallery();
Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.