Image Gallery
Intermediate
Modern image gallery with grid layout, lightbox effect, filtering, and responsive design.
Live Preview
Code Implementation
HTML
<div class="gallery-container">
<div class="gallery-header">
<h1 class="gallery-title">Photo Gallery</h1>
<p class="gallery-subtitle">Explore our collection of stunning photographs</p>
</div>
<!-- Filter Buttons -->
<div class="filter-controls">
<button class="filter-btn active" data-filter="all">All</button>
<button class="filter-btn" data-filter="nature">Nature</button>
<button class="filter-btn" data-filter="architecture">Architecture</button>
<button class="filter-btn" data-filter="portrait">Portrait</button>
<button class="filter-btn" data-filter="street">Street</button>
</div>
<!-- Gallery Grid -->
<div class="gallery-grid" id="galleryGrid">
<div class="gallery-item" data-category="nature">
<img src="https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=400&h=300&fit=crop" alt="Mountain landscape" loading="lazy">
<div class="gallery-overlay">
<div class="gallery-info">
<h3 class="gallery-item-title">Mountain Vista</h3>
<p class="gallery-item-category">Nature</p>
</div>
<button class="gallery-zoom-btn" data-index="0">
<svg viewBox="0 0 24 24" fill="currentColor">
<path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/>
<path d="M12 10h-2v2H9v-2H7V9h2V7h1v2h2v1z"/>
</svg>
</button>
</div>
</div>
<div class="gallery-item" data-category="architecture">
<img src="https://images.unsplash.com/photo-1486406146926-c627a92ad1ab?w=400&h=300&fit=crop" alt="Modern building" loading="lazy">
<div class="gallery-overlay">
<div class="gallery-info">
<h3 class="gallery-item-title">Urban Architecture</h3>
<p class="gallery-item-category">Architecture</p>
</div>
<button class="gallery-zoom-btn" data-index="1">
<svg viewBox="0 0 24 24" fill="currentColor">
<path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/>
<path d="M12 10h-2v2H9v-2H7V9h2V7h1v2h2v1z"/>
</svg>
</button>
</div>
</div>
<div class="gallery-item" data-category="portrait">
<img src="https://images.unsplash.com/photo-1494790108755-2616c6d4e6e8?w=400&h=300&fit=crop" alt="Portrait photography" loading="lazy">
<div class="gallery-overlay">
<div class="gallery-info">
<h3 class="gallery-item-title">Portrait Study</h3>
<p class="gallery-item-category">Portrait</p>
</div>
<button class="gallery-zoom-btn" data-index="2">
<svg viewBox="0 0 24 24" fill="currentColor">
<path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/>
<path d="M12 10h-2v2H9v-2H7V9h2V7h1v2h2v1z"/>
</svg>
</button>
</div>
</div>
<div class="gallery-item" data-category="street">
<img src="https://images.unsplash.com/photo-1449824913935-59a10b8d2000?w=400&h=300&fit=crop" alt="Street photography" loading="lazy">
<div class="gallery-overlay">
<div class="gallery-info">
<h3 class="gallery-item-title">City Streets</h3>
<p class="gallery-item-category">Street</p>
</div>
<button class="gallery-zoom-btn" data-index="3">
<svg viewBox="0 0 24 24" fill="currentColor">
<path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/>
<path d="M12 10h-2v2H9v-2H7V9h2V7h1v2h2v1z"/>
</svg>
</button>
</div>
</div>
<div class="gallery-item" data-category="nature">
<img src="https://images.unsplash.com/photo-1441974231531-c6227db76b6e?w=400&h=300&fit=crop" alt="Forest path" loading="lazy">
<div class="gallery-overlay">
<div class="gallery-info">
<h3 class="gallery-item-title">Forest Path</h3>
<p class="gallery-item-category">Nature</p>
</div>
<button class="gallery-zoom-btn" data-index="4">
<svg viewBox="0 0 24 24" fill="currentColor">
<path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/>
<path d="M12 10h-2v2H9v-2H7V9h2V7h1v2h2v1z"/>
</svg>
</button>
</div>
</div>
<div class="gallery-item" data-category="architecture">
<img src="https://images.unsplash.com/photo-1518005020951-eccb494ad742?w=400&h=300&fit=crop" alt="Modern architecture" loading="lazy">
<div class="gallery-overlay">
<div class="gallery-info">
<h3 class="gallery-item-title">Glass Structure</h3>
<p class="gallery-item-category">Architecture</p>
</div>
<button class="gallery-zoom-btn" data-index="5">
<svg viewBox="0 0 24 24" fill="currentColor">
<path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/>
<path d="M12 10h-2v2H9v-2H7V9h2V7h1v2h2v1z"/>
</svg>
</button>
</div>
</div>
<div class="gallery-item" data-category="portrait">
<img src="https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=400&h=300&fit=crop" alt="Portrait" loading="lazy">
<div class="gallery-overlay">
<div class="gallery-info">
<h3 class="gallery-item-title">Character Study</h3>
<p class="gallery-item-category">Portrait</p>
</div>
<button class="gallery-zoom-btn" data-index="6">
<svg viewBox="0 0 24 24" fill="currentColor">
<path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/>
<path d="M12 10h-2v2H9v-2H7V9h2V7h1v2h2v1z"/>
</svg>
</button>
</div>
</div>
<div class="gallery-item" data-category="street">
<img src="https://images.unsplash.com/photo-1477959858617-67f85cf4f1df?w=400&h=300&fit=crop" alt="Urban scene" loading="lazy">
<div class="gallery-overlay">
<div class="gallery-info">
<h3 class="gallery-item-title">Urban Life</h3>
<p class="gallery-item-category">Street</p>
</div>
<button class="gallery-zoom-btn" data-index="7">
<svg viewBox="0 0 24 24" fill="currentColor">
<path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/>
<path d="M12 10h-2v2H9v-2H7V9h2V7h1v2h2v1z"/>
</svg>
</button>
</div>
</div>
</div>
<!-- Lightbox Modal -->
<div class="lightbox" id="lightbox">
<div class="lightbox-content">
<button class="lightbox-close" id="lightboxClose">
<svg viewBox="0 0 24 24" fill="currentColor">
<path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/>
</svg>
</button>
<button class="lightbox-nav lightbox-prev" id="lightboxPrev">
<svg viewBox="0 0 24 24" fill="currentColor">
<path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"/>
</svg>
</button>
<button class="lightbox-nav lightbox-next" id="lightboxNext">
<svg viewBox="0 0 24 24" fill="currentColor">
<path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/>
</svg>
</button>
<div class="lightbox-image-container">
<img class="lightbox-image" id="lightboxImage" src="" alt="">
</div>
<div class="lightbox-info">
<h3 class="lightbox-title" id="lightboxTitle"></h3>
<p class="lightbox-category" id="lightboxCategory"></p>
<div class="lightbox-counter">
<span id="lightboxCounter">1 / 8</span>
</div>
</div>
</div>
</div>
</div>
Snippet Features
Browser Compatibility
🟢
chrome 60+ 🟠
firefox 55+ 🔵
safari 10+ 🟦
edge 15+