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 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 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 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 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 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.
A customizable, modular, responsive, lightbox gallery plugin. No dependencies.\ Available for React.js, Angular, Vue.js, and typescript.

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
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'
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>
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>
You'll receive a license key via email one you purchase a license More info
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
lightGallery supports all major browsers including IE 10 and above.
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
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.
If you have any questions, suggestions, feedback, please reach out to contact@lightgalleryjs.com or DM me on twitter