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.
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.
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();
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>' }
]
}
});
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.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%
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.glightbox, lightgallery, photoswipe, viewerjs) are actively maintained with recent releases and modern JavaScript support.glightboximport GLightbox from 'glightbox';
GLightbox({ selector: '.gallery-link' });
lightgallery or viewerjslightgallery for a full gallery with thumbnails; use viewerjs if you need deep image inspection on a single product image.photoswipemagnific-popup (if already using jQuery)viewerjs| Library | Dependencies | Actively Maintained | Video Support | Mobile Gestures | Custom UI | Best For |
|---|---|---|---|---|---|---|
lightbox2 | jQuery | ❌ (Deprecated) | ❌ | Basic | Limited | Legacy projects only |
magnific-popup | jQuery | ⚠️ (Maintenance) | ✅ | Basic | Moderate | jQuery-based sites |
glightbox | None | ✅ | ✅ | Swipe nav | Good | Simple, modern galleries |
lightgallery | None | ✅ | ✅ | Swipe nav | Excellent | Feature-rich galleries |
photoswipe | None | ✅ | Manual | Pinch/swipe | Full | Performance-critical UX |
viewerjs | None | ✅ | ❌ | Zoom/pan | Methods | Image inspection |
For new projects, eliminate lightbox2 immediately and avoid magnific-popup unless you’re stuck in a jQuery ecosystem. Among the modern options:
photoswipe if you care deeply about performance, accessibility, and mobile UX.lightgallery if you need a Swiss Army knife of gallery features.glightbox for the simplest, cleanest out-of-the-box experience.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.
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.
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.
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.
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.
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.
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.
PhotoSwipe v5 — JavaScript image gallery and lightbox
dist/ - main JS and CSSsrc/ - 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.
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.