photo-galleries
intermediate
gallery
images
lightbox
filtering
portfolio
Category · Photo Galleries Difficulty Level · Intermediate Published on · August 22, 2025

Animated Image Gallery

Modern image gallery with filtering, sorting, and lightbox functionality, perfect for showcasing portfolios and photo collections.

#gallery #images #lightbox #filtering #portfolio

Responsive Design

Yes

Dark Mode Support

No

lines

718

Browser Compatibility

Chrome · Firefox · Safari · Edge

Live Preview

Interact with the component without leaving the page.

400px

Overview

Modern image gallery with filtering, sorting, and lightbox functionality, perfect for showcasing portfolios and photo collections.

How to use

  1. Copy the HTML markup into your page.
  2. Paste the CSS into your stylesheet and ensure the selectors match your markup.
  3. Paste the JavaScript and load it after the markup.
  4. Adjust spacing, colors, and text to match your design system.

Customization tips

  • Rename class names to avoid collisions with your existing CSS.
  • Replace hard-coded colors with CSS variables for theming.
  • Verify the layout at 320px, 768px, and 1024px widths.

HTML

49

lines

CSS

418

lines

JavaScript

251

lines


                <div class="image-gallery-container">
  <div class="image-gallery-demo">
    <div class="gallery-header">
      <h2>Image Gallery</h2>
      <p>Beautiful photo collection with filtering</p>
    </div>
    
    <div class="gallery-controls">
      <div class="filter-buttons">
        <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="urban">Urban</button>
        <button class="filter-btn" data-filter="people">People</button>
        <button class="filter-btn" data-filter="abstract">Abstract</button>
      </div>
      
      <div class="sort-dropdown">
        <select id="sortSelect">
          <option value="newest">Newest First</option>
          <option value="oldest">Oldest First</option>
          <option value="name">Name A-Z</option>
        </select>
      </div>
    </div>
    
    <div class="gallery-grid" id="galleryGrid">
      
    </div>
    
    <div class="gallery-footer">
      <div class="pagination-info">
        Showing <span id="currentCount">0</span> of <span id="totalCount">0</span> images
      </div>
    </div>
  </div>
</div>


<div class="lightbox" id="lightbox">
  <div class="lightbox-content">
    <button class="lightbox-close" id="lightboxClose">&times;</button>
    <button class="lightbox-nav prev" id="lightboxPrev">‹</button>
    <button class="lightbox-nav next" id="lightboxNext">›</button>
    <div class="lightbox-image-container">
      <img class="lightbox-image" id="lightboxImage" src="" alt="">
      <div class="lightbox-caption" id="lightboxCaption"></div>
    </div>
  </div>
</div>

              
49lines
1681characters
HTMLLanguage

Browser Compatibility

Chrome

>= 50

Firefox

>= 45

Safari

>= 10

Edge

>= 15

Related Code Snippets

Explore template packs

Need larger building blocks? Browse responsive landing pages and component bundles.

Open HTML Template Library ->