lightgallery vs glightbox vs lightbox2 vs magnific-popup vs photoswipe vs viewerjs
JavaScript Lightbox Libraries for Image and Media Galleries
lightgalleryglightboxlightbox2magnific-popupphotoswipeviewerjsSimilar 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
lightgallery74,7267,0477.97 MB64a year agoGPLv3
glightbox51,8992,519401 kB442 years agoMIT
lightbox206,373946 kB506 months ago-
magnific-popup011,3141.05 MB6782 years agoMIT
photoswipe025,2401.21 MB1702 years agoMIT
viewerjs08,232504 kB40a month 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
glightboxNone✅✅Swipe navGoodSimple, modern galleries
lightgalleryNone✅✅Swipe navExcellentFeature-rich galleries
photoswipeNone✅ManualPinch/swipeFullPerformance-critical UX
viewerjsNone✅❌Zoom/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: lightgallery vs glightbox vs lightbox2 vs magnific-popup vs photoswipe vs viewerjs

  • 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.

  • 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.

  • 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.

  • 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.

  • 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 lightgallery

commit npm npm-tag size tree-shaking types hits

lightGallery

A customizable, modular, responsive, lightbox gallery plugin. No dependencies.\ Available for React.js, Angular, Vue.js, and typescript.

lightgallery

Core features

  • Fully responsive.
  • Modular architecture with built in plugins.
  • Highly optimized for touch devices.
  • Mouse drag supports for desktops.
  • Double-click/Double-tap to see actual size of the image.
  • Animated thumbnails.
  • Social sharing.
  • YouTube Vimeo Wistia and html5 videos Support.
  • 20+ Hardware-Accelerated CSS3 transitions.
  • Dynamic mode.
  • Inline gallery.
  • Full screen support.
  • Zoom in/out, Pinch to zoom.
  • Swipe/Drag up/down support to close gallery.
  • Browser history API(deep linking).
  • Responsive images.
  • HTML iframe support.
  • Multiple instances on one page.
  • Easily customizable via CSS (SCSS) and Settings.
  • Smart image preloading and code optimization.
  • Keyboard Navigation for desktop.
  • SVG icons.
  • Accessibility support.
  • Rotate, flip images.
  • And many more.

Documentation

Installation

lightGallery is available on NPM, Yarn, Bower, CDNs, and GitHub. You can use any of the following method to download lightGallery.

  • NPM - NPM is a package manager for the JavaScript programming language. You can install lightgallery using the following command

    npm install lightgallery
    
  • YARN - Yarn is another popular package manager for the JavaScript programming language. If you prefer you can use Yarn instead of NPM

    yarn add lightgallery
    
  • Bower - You can find lightGallery on Bower package manager as well

    bower install lightgallery --save
    
  • GitHub - You can also directly download lightgallery from GitHub

  • CDN - If you prefer to use a CDN, you can load files via jsdelivr, cdnjs or unpkg

Include CSS and Javascript files

First of all, include lightgallery.css in the <head> of the document. If you want include any lightGallery plugin such as thumbnails or zoom, you need to include respective css files as well.

Alternatively you can include lightgallery-bundle.css which contains lightGallery and all plugin styles instead of separate stylesheets.

If you like you can also import scss files instead of css files from the scss folder.

<head>
    <link type="text/css" rel="stylesheet" href="css/lightgallery.css" />

    <!-- lightgallery plugins -->
    <link type="text/css" rel="stylesheet" href="css/lg-zoom.css" />
    <link type="text/css" rel="stylesheet" href="css/lg-thumbnail.css" />


    <!-- OR -->

    <link type="text/css" rel="stylesheet" href="css/lightgallery-bundle.css" />
</head>

Then include lightgallery.umd.js into your document. If you want to include any lightgallery plugin you can include it after lightgallery.umd.js.

<body>
    ....

    <script src="js/lightgallery.umd.js"></script>

    <!-- lightgallery plugins -->
    <script src="js/plugins/lg-thumbnail.umd.js"></script>
    <script src="js/plugins/lg-zoom.umd.js"></script>
</body>

lightGallery supports AMD, CommonJS and ES6 modules too.

import lightGallery from 'lightgallery';

// Plugins
import lgThumbnail from 'lightgallery/plugins/thumbnail'
import lgZoom from 'lightgallery/plugins/zoom'

The markup

lightgallery does not force you to use any kind of markup. you can use whatever markup you want. Here can find detailed examples of different kinds of markups.

If you know the original size of the media, you can pass it via data-lg-size="${width}-${height}" attribute for the initial zoom animation. But, this is completely optional.

<div id="lightgallery">
    <a href="https://github.com/sachinchoolur/lightGallery/blob/HEAD/img/img1.jpg" data-lg-size="1600-2400">
        <img alt=".." src="https://raw.githubusercontent.com/sachinchoolur/lightGallery/HEAD/img/thumb1.jpg" />
    </a>
    <a href="https://github.com/sachinchoolur/lightGallery/blob/HEAD/img/img2.jpg" data-lg-size="1024-800">
        <img alt=".." src="https://raw.githubusercontent.com/sachinchoolur/lightGallery/HEAD/img/thumb2.jpg" />
    </a>
    ...
</div>

Initialize lightGallery

Finally, you need to initiate the gallery by adding the following code.

<script type="text/javascript">
    lightGallery(document.getElementById('lightgallery'), {
        plugins: [lgZoom, lgThumbnail],
        speed: 500,
        licenseKey: 'your_license_key'
        ... other settings
    });
</script>

CodePen Demos

License Key

You'll receive a license key via email one you purchase a license More info

Plugins

As shown above, you need to pass the plugins via settings if you want to use any lightGallery plugins.

If you are including lightGallery files via script tag, please use the same plugins names as follows.

lgZoom, lgAutoplay, lgComment, lgFullscreen , lgHash, lgPager, lgRotate, lgShare, lgThumbnail, lgVideo, lgMediumZoom

Browser support

lightGallery supports all major browsers including IE 10 and above.

License

Commercial license

If you want to use lightGallery to develop commercial sites, themes, projects, and applications, the Commercial license is the appropriate license. With this option, your source code is kept proprietary. Read more about the commercial license

Open source license

If you are creating an open source application under a license compatible with the GNU GPL license v3, you may use this project under the terms of the GPLv3.

Support

If you have any questions, suggestions, feedback, please reach out to contact@lightgalleryjs.com or DM me on twitter