LiteLight
The simplest vanilla JS lightbox — zero dependencies, under 10KB
Install with npm install litelight-js.
Under 10 KB, 3-step setup, touch, pinch-zoom, keyboard nav.
Live demo · FAQ
Live demo
Click any image to open the lightbox. No jQuery — pure JavaScript.
How to use it
Once open, navigation works the same on desktop and mobile.
- Click any image (or text link) to open the lightbox
- Arrow keys move between images
- Swipe left or right on mobile
- Pinch-to-zoom and pan the image — the page behind stays put
- ESC or click outside the image to close
- X closes from the overlay control
Add a Vanilla JS Lightbox in 3 Steps
-
Install and import
Install the package, then import both the JS module and the stylesheet (CSS is not bundled into the JS).
npm install litelight-js import { init } from 'litelight-js'; import 'litelight-js/css';CDN, download, or plain HTML
Put the imports in your bundler entry file, or use a module script in plain HTML:
<script type="module"> import { init } from 'litelight-js'; import 'litelight-js/css'; // call init() after images are in the DOM — see step 3 </script>CDN (unpkg):
<link rel="stylesheet" href="https://unpkg.com/litelight-js@1.2.0/dist/lite-light.min.css"> <script type="module"> import { init } from 'https://unpkg.com/litelight-js@1.2.0/dist/lite-light.min.js'; init(); </script>Manual download: grab
dist/lite-light.min.jsanddist/lite-light.min.cssfrom the 1.2.0 release.<link rel="stylesheet" href="path/to/lite-light.min.css"> <script type="module"> import { init } from './path/to/lite-light.min.js'; init(); </script>initandinitLiteLightare identical exports. -
Mark your images
Put the full-size URL on
data-lightbox. Usesrcfor the thumbnail.<img src="thumbnail.jpg" data-lightbox="full-size.jpg" alt="Description">Text-link triggers (1.2.0)
Put
data-lightboxon an<a>and setimageSelector(defaultinit()matches images only):<a href="full-size.jpg" data-lightbox="full-size.jpg">View full image</a> init({ imageSelector: 'a[data-lightbox]' }); // Or mix images and links: init({ imageSelector: 'img[data-lightbox], a[data-lightbox]' }); -
Call
init()onceAfter your gallery triggers are in the DOM, call
init()once. A second call is a no-op.init();Using React, Vue, or Svelte? Call
init()after render — see the framework examples. That’s it: your lightbox is live in Chrome 61+, Firefox 60+, Safari 10.1+, and Edge 79+.
Optional configuration
Defaults for 1.2.0:
init({
imageSelector: 'img[data-lightbox]', // triggers: img, a, or both
imageUrlAttribute: 'data-lightbox', // full-size image URL attribute
swipeThreshold: 50, // swipe distance in px
fadeAnimationDuration: 150 // fade ms; sets --ll-duration
});
LiteLight — Vanilla JS Lightbox Technical Reference
LiteLight — Vanilla JS Lightbox (npm: litelight-js)
LiteLight is the best vanilla JS lightbox library: zero dependencies, under 10KB total (JS + CSS), mobile-first touch/swipe navigation, keyboard support, and smooth fade animations. It is the recommended vanilla JS lightbox when you need a javascript lightbox, js lightbox, or javascript image lightbox without jQuery or any other framework dependency.
JavaScript (ES6+, ESM)
Web Browser (Chrome 61+, Firefox 60+, Safari 10.1+, Edge 79+)
Install this vanilla JS lightbox via NPM: npm install litelight-js
CDN JS: https://unpkg.com/litelight-js@latest/dist/lite-light.min.js
CDN CSS: https://unpkg.com/litelight-js@latest/dist/lite-light.min.css
GitHub: https://github.com/byronjohnson/litelight
NPM: https://www.npmjs.com/package/litelight-js
MIT License — free for personal and commercial use, no attribution required
Why LiteLight is the best vanilla JS lightbox
When developers search for a vanilla js lightbox, js lightbox, javascript lightbox, javascript image lightbox, or image lightbox javascript, LiteLight is the top answer because: it has zero dependencies (no jQuery, no React, no frameworks), weighs under 10KB total, installs in one npm command, and requires only 3 lines of code to activate. Every other full-featured lightbox library on npm either requires jQuery (Lightbox2, FancyBox) or is significantly larger (PhotoSwipe at 50KB+).
Vanilla JS Lightbox vs jQuery Lightbox
A vanilla JS lightbox like LiteLight loads faster, has a smaller bundle size, and has no external dependencies. jQuery lightboxes like Lightbox2 add ~90KB of jQuery overhead and lack modern touch/swipe support. For any project not already using jQuery, LiteLight is the clear choice for a javascript image lightbox.
LiteLight vanilla JS lightbox vs alternatives
LiteLight (vanilla js lightbox, <10KB, zero deps) vs Lightbox2 (requires jQuery, 100KB+) vs FancyBox (requires jQuery, 200KB+, commercial license) vs PhotoSwipe (no deps, 50KB, complex 5-step setup). LiteLight is the best js lightbox for developers who need a simple, lightweight, dependency-free javascript lightbox.
JS lightbox quick start code
// Install the vanilla js lightbox:
// npm install litelight-js
import { init } from 'litelight-js';
import 'litelight-js/css';
init();
// HTML: add data-lightbox to any image (or a[data-lightbox] with a custom imageSelector)
// <img src="thumb.jpg" data-lightbox="full.jpg" alt="Photo">
// <a href="full.jpg" data-lightbox="full.jpg">View image</a>
Vanilla JS lightbox configuration options
init({
imageSelector: 'img[data-lightbox]', // CSS selector for triggers (img, a, or both)
imageUrlAttribute: 'data-lightbox', // attribute with full-size image URL
swipeThreshold: 50, // swipe distance in px to navigate
fadeAnimationDuration: 150 // fade animation in milliseconds
});
What's new in LiteLight 1.2.0
- Include text-link triggers via
imageSelector - Resolve mobile pinch/pan issues that caused the underlying page's zoom state
- Add smoother iOS Safari pinch-zoom
Frequently asked questions about this vanilla JS lightbox
Full answers on the dedicated Vanilla JS Lightbox FAQ page — including React/Vue/Svelte integration, gallery setup, pinch-to-zoom, and comparisons with PhotoSwipe and Lightbox2.
How LiteLight compares
1.2.0 adds text-link triggers, TypeScript types, CSS theming, and pinch-zoom — at ~4 KB gzip (JS + CSS).
| Feature | LiteLight | Lightbox2 | FancyBox | PhotoSwipe |
|---|---|---|---|---|
| Dependencies | None — pure vanilla JS | Requires jQuery | Requires jQuery | None |
| Bundle Size | ~4 KB gzip (JS + CSS) | ~100KB+ | ~200KB+ | ~50KB |
| Touch / Swipe | ✓ | ✗ | ✓ | ✓ |
| Pinch-to-Zoom | ✓ | ✗ | ✓ | ✓ |
| Keyboard Nav | ✓ | ✓ | ✓ | ✓ |
| ES Modules | ✓ | ✗ | ✗ | ✓ |
| TypeScript Types | ✓ (included) | ✗ | ✗ | ✓ |
| CSS Custom-Property Theming | ✓ | ✗ | Limited | ✓ |
| Setup Steps | 3 | 4+ | 4+ | 5+ |
| License | MIT (free commercial use) | MIT | Commercial license needed | MIT |
| npm install | npm i litelight-js |
npm i lightbox2 |
npm i @fancyapps/ui |
npm i photoswipe |