photoswipe vs glightbox vs lightbox2 vs lightgallery vs magnific-popup vs viewerjs
JavaScript Lightbox Libraries for Image and Media Galleries
photoswipeglightboxlightbox2lightgallerymagnific-popupviewerjsSimilar Packages:

JavaScript Lightbox Libraries for Image and Media Galleries

glightbox, lightbox2, lightgallery, magnific-popup, photoswipe, and viewerjs are JavaScript libraries that provide lightbox functionality — modal overlays for displaying images, videos, and other media in an immersive, user-friendly way. These libraries typically support features like navigation arrows, keyboard controls, touch gestures, responsive design, and caption display. While they share a common goal, they differ significantly in architecture, customization options, framework compatibility, and maintenance status.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
photoswipe416,20225,1041.21 MB1632 years agoMIT
glightbox02,438401 kB44a year agoMIT
lightbox206,375946 kB4814 days ago-
lightgallery06,9917.97 MB625 months agoGPLv3
magnific-popup011,3581.05 MB6782 years agoMIT
viewerjs08,193504 kB37a year agoMIT

JavaScript Lightbox Libraries Compared: Architecture, Features, and Trade-offs

Lightbox libraries solve a deceptively complex problem: displaying media in a modal overlay that feels native, responsive, and accessible. While all six packages (glightbox, lightbox2, lightgallery, magnific-popup, photoswipe, viewerjs) aim to deliver this experience, their approaches vary dramatically in terms of dependencies, extensibility, and modern web standards compliance. Let’s break down how they differ in real-world usage.

🧱 Core Architecture: Dependencies and Modernity

lightbox2 relies on jQuery and uses global script tags. It hasn’t been updated since 2021 and is marked as deprecated on its GitHub repository. New projects should avoid it entirely.

<!-- lightbox2: Requires jQuery -->
<script src="jquery.js"></script>
<script src="lightbox.js"></script>
<a href="image.jpg" data-lightbox="gallery">View</a>

magnific-popup also depends on jQuery, though it’s more feature-rich. It’s in maintenance mode — no new features, but bug fixes are still accepted.

// magnific-popup: jQuery plugin
$('.gallery').magnificPopup({
  delegate: 'a',
  type: 'image'
});

glightbox, photoswipe (v5+), lightgallery, and viewerjs are dependency-free and use modern ES modules. They can be imported directly in frameworks like React or Vue without extra wrappers.

// glightbox: ES module
import GLightbox from 'glightbox';
const lightbox = GLightbox();
// photoswipe v5: Constructor-based
import PhotoSwipeLightbox from 'photoswipe/lightbox';
const lightbox = new PhotoSwipeLightbox({
  gallery: '#gallery',
  children: 'a'
});
lightbox.init();

🖼️ Media Support: Beyond Static Images

Not all lightboxes handle video, iframes, or inline content. Here’s how each library compares:

lightbox2 only supports static images. No video, no HTML content.

viewerjs is image-only, but excels at image manipulation (zoom, rotate, flip).

// viewerjs: Image-focused
import Viewer from 'viewerjs';
new Viewer(document.getElementById('images'));

glightbox, magnific-popup, and lightgallery support images, videos (YouTube/Vimeo), iframes, and inline content.

// glightbox: Mixed media
const lightbox = GLightbox({
  elements: [
    { href: 'video.mp4', type: 'video' },
    { href: 'https://example.com', type: 'iframe' }
  ]
});
// magnific-popup: Mixed media via type option
$('.popup').magnificPopup({
  items: {
    src: 'https://youtu.be/...',
    type: 'iframe'
  }
});
// lightgallery: Dynamic mixed media
lightGallery(document.getElementById('dynamic'), {
  dynamic: true,
  dynamicEl: [
    { src: 'img1.jpg', thumb: 'thumb1.jpg' },
    { src: 'https://vimeo.com/...', iframeMaxWidth: '80%' }
  ]
});

photoswipe (v5) focuses on images and HTML slides, but doesn’t natively support video players. You can embed video manually in slide content, but it requires custom implementation.

// photoswipe: Custom slide with video
const lightbox = new PhotoSwipeLightbox({
  dataSource: {
    items: [
      { html: '<video controls><source src="video.mp4"></video>' }
    ]
  }
});

📱 Mobile Experience and Gestures

Touch support varies significantly:

  • photoswipe offers the most polished mobile experience with pinch-to-zoom, swipe-to-close, and hardware-accelerated animations.
  • glightbox and lightgallery support swipe navigation and responsive scaling.
  • magnific-popup and lightbox2 have basic touch support but feel dated on mobile.
  • viewerjs provides multi-touch zoom and pan, making it ideal for detailed image inspection.

⚙️ Customization and UI Control

lightbox2 and magnific-popup offer limited theming — mostly via CSS overrides.

glightbox allows replacing UI elements and callbacks:

const lightbox = GLightbox({
  touchNavigation: true,
  loop: false,
  beforeSlideChange: () => console.log('Changing slide')
});

lightgallery uses a plugin architecture — you can enable/disable features like thumbnails, zoom, or autoplay:

lightGallery(el, {
  plugins: [lgZoom, lgThumbnail],
  thumbnail: true,
  zoomFromOrigin: false
});

photoswipe gives you full control over the UI by letting you define your own toolbar and buttons:

const lightbox = new PhotoSwipeLightbox({
  gallery: '#gallery',
  children: 'a',
  pswpModule: PhotoSwipe
});

lightbox.on('uiRegister', () => {
  lightbox.pswp.ui.registerElement({
    name: 'custom-button',
    ariaLabel: 'Custom',
    order: 8,
    isButton: true,
    html: 'Custom',
    onClick: () => alert('Clicked!')
  });
});

viewerjs exposes methods like zoom(), rotate(), and move() for programmatic control:

const viewer = new Viewer(image);
viewer.zoom(0.5); // Zoom to 50%

🚫 Deprecated and Maintenance Status

  • lightbox2: Deprecated. The official GitHub repo states: “Lightbox is no longer actively maintained.” Do not use in new projects.
  • magnific-popup: In maintenance mode. No new features, but stable for existing jQuery-based sites.
  • All others (glightbox, lightgallery, photoswipe, viewerjs) are actively maintained with recent releases and modern JavaScript support.

🧪 Real-World Selection Guide

Scenario 1: Simple Image Gallery on a Static Site

  • Best choice: glightbox
  • Why? Zero dependencies, clean defaults, and minimal setup.
import GLightbox from 'glightbox';
GLightbox({ selector: '.gallery-link' });

Scenario 2: E-commerce Product Viewer with Zoom and Thumbnails

  • Best choice: lightgallery or viewerjs
  • Use lightgallery for a full gallery with thumbnails; use viewerjs if you need deep image inspection on a single product image.

Scenario 3: High-Performance Photo Blog with Mobile-First UX

  • Best choice: photoswipe
  • Why? Best-in-class mobile gestures, accessibility, and performance.

Scenario 4: Legacy jQuery Site Needing Quick Popup Solution

  • Best choice: magnific-popup (if already using jQuery)
  • Avoid in new projects; consider refactoring to a modern alternative.

Scenario 5: Technical Documentation with Diagram Inspection

  • Best choice: viewerjs
  • Why? Built-in zoom, rotate, and drag are perfect for detailed diagrams.

📊 Summary Table

LibraryDependenciesActively MaintainedVideo SupportMobile GesturesCustom UIBest For
lightbox2jQuery❌ (Deprecated)BasicLimitedLegacy projects only
magnific-popupjQuery⚠️ (Maintenance)BasicModeratejQuery-based sites
glightboxNoneSwipe navGoodSimple, modern galleries
lightgalleryNoneSwipe navExcellentFeature-rich galleries
photoswipeNoneManualPinch/swipeFullPerformance-critical UX
viewerjsNoneZoom/panMethodsImage inspection

💡 Final Recommendation

For new projects, eliminate lightbox2 immediately and avoid magnific-popup unless you’re stuck in a jQuery ecosystem. Among the modern options:

  • Pick photoswipe if you care deeply about performance, accessibility, and mobile UX.
  • Pick lightgallery if you need a Swiss Army knife of gallery features.
  • Pick glightbox for the simplest, cleanest out-of-the-box experience.
  • Pick viewerjs when your users need to closely examine images.

Each library solves a slightly different problem — choose based on whether you’re building a gallery browser, a media popup, or an image inspector.

How to Choose: photoswipe vs glightbox vs lightbox2 vs lightgallery vs magnific-popup vs viewerjs

  • photoswipe:

    Choose photoswipe if you prioritize performance, accessibility, and a native-like mobile experience with pinch-to-zoom and smooth animations. Version 5+ is a complete rewrite using modern JavaScript and offers excellent control over UI and behavior. It’s ideal for high-traffic sites or apps where user experience and standards compliance are critical.

  • glightbox:

    Choose glightbox if you need a modern, lightweight, dependency-free lightbox with strong mobile support and clean default styling. It’s ideal for projects where you want minimal setup and don’t require advanced gallery features like thumbnails or deep video integration. Its ES6 module structure makes it easy to integrate into modern build systems.

  • lightbox2:

    Avoid lightbox2 for new projects — it is officially deprecated as of 2023 and no longer maintained. While it was once the standard for simple image lightboxes, its reliance on jQuery, lack of video support, and outdated codebase make it unsuitable for contemporary applications. Consider migrating existing implementations to a more current alternative.

  • lightgallery:

    Choose lightgallery if you need a full-featured, plugin-based gallery system with extensive customization, dynamic loading, and rich media support (including YouTube, Vimeo, and inline content). It’s well-suited for complex galleries requiring thumbnails, zoom, and responsive layouts, though its larger footprint may be overkill for basic use cases.

  • magnific-popup:

    Choose magnific-popup if you’re working in a jQuery environment and need a versatile popup solution that handles not just images but also AJAX content, iframes, and inline elements. Despite being in maintenance mode (no active feature development), it remains stable and widely used. However, avoid it in new non-jQuery projects due to its dependency on jQuery.

  • viewerjs:

    Choose viewerjs if you need a dedicated image viewer with zoom, rotation, and drag capabilities, especially for technical or documentation sites. It works best when you want users to closely inspect images rather than just browse a gallery. Note that it focuses solely on images and doesn’t support video or mixed media types.

README for photoswipe

Stand With Ukraine

PhotoSwipe v5 — JavaScript image gallery and lightbox

Demo | Documentation

Sponsor via OpenCollective Follow on Twitter

Repo structure

  • dist/ - main JS and CSS
  • src/ - source JS and CSS.
    • src/js/photoswipe.js - entry for PhotoSwipe Core.
    • src/js/lightbox/lightbox.js - entry for PhotoSwipe Lightbox.
  • docs/ - documentation markdown files.
  • demo-docs-website/ - website with documentation, demos and manual tests.
  • build/ - rollup build config.

To build JS and CSS in dist/ directory, run npm run build.

To run the demo website and automatically rebuild files during development, run npm install in demo-docs-website/ and npm run watch in the root directory.

Older versions

Documentation for the old version (v4) can be found here and the code for 4.1.3 is here.


This project is tested with BrowserStack.