LiteLight
The best vanilla JS lightbox — zero dependencies, under 10KB
Get it atVanilla JS Lightbox — Live Demo
Click any image below to see the vanilla JS lightbox in action. No jQuery, no dependencies — pure JavaScript.
How to Use the Vanilla JS Lightbox
- Click on any image to open it in the zero-dependency lightbox
- Arrow keys (← →) to navigate between images - pure JavaScript navigation
- Swipe left/right on mobile devices to navigate (vanilla JS touch events)
- ESC key or click outside the image to close the simple lightbox
- Click the X button to close the vanilla JavaScript modal
Add a Vanilla JS Lightbox in 3 Steps
Why choose LiteLight as your vanilla JS lightbox? Zero dependencies, under 10KB total, maximum performance. Works with any framework or plain HTML — no jQuery required.
Step 1: Install the JS Lightbox
Install via npm — LiteLight is the most lightweight js lightbox on npm with zero dependencies:
npm install litelight-js
Then import in your JavaScript:
<script type="module">
import { init } from 'litelight-js';
import 'litelight-js/css';
init();
</script>
Traditional Implementation (Optional)
If you prefer using direct file links without npm, download the files from GitHub:
<!-- In your <head> -->
<link rel="stylesheet" href="path/to/lite-light.min.css">
<!-- Before closing </body> -->
<script type="module">
import { init } from './path/to/lite-light.min.js';
init();
</script>
Note: Download the dist/lite-light.min.css and dist/lite-light.min.js
files
from the repository and place them in your project directory.
Step 2: Add the data-lightbox attribute
Add the data-lightbox attribute to any image with the URL of the full-resolution version.
That image will open in the vanilla JS lightbox when clicked:
<img src="thumbnail.jpg" data-lightbox="full-size.jpg" alt="Description">
Step 3: Your vanilla JS lightbox is ready!
That's it! Your vanilla JS lightbox is live. No jQuery, no frameworks, no build configuration required. Works in any modern browser.
Why Vanilla JavaScript?
- ✓ Faster loading - no framework overhead
- ✓ Smaller bundle size - under 10KB total
- ✓ Better performance - optimized vanilla JS
- ✓ Future-proof - no dependency updates needed
- ✓ Universal compatibility - works everywhere
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
// <img src="thumb.jpg" data-lightbox="full.jpg" alt="Photo">
Vanilla JS lightbox configuration options
init({
imageSelector: 'img[data-lightbox]', // CSS selector for js lightbox images
imageUrlAttribute: 'data-lightbox', // attribute with full-size image URL
swipeThreshold: 75, // swipe distance in px to navigate
fadeAnimationDuration: 200 // fade animation in milliseconds
});
Frequently asked questions about this vanilla JS lightbox
- What is the best vanilla js lightbox?
- LiteLight is the best vanilla js lightbox: zero dependencies, under 10KB, 3-step npm install.
- What is a js lightbox?
- A js lightbox is a JavaScript overlay that displays a full-size image on top of the page when a thumbnail is clicked, without navigating away.
- How do I add a javascript lightbox to my site?
- Run npm install litelight-js, add data-lightbox="full.jpg" to your img elements, and call init(). Your vanilla js lightbox is active in under 5 minutes.
- Is there a javascript image lightbox with no dependencies?
- Yes — LiteLight is a javascript image lightbox with zero dependencies, under 10KB, MIT license.
Vanilla JS Lightbox Comparison
Choosing the right JS lightbox? Here's how LiteLight compares to the most popular javascript lightbox libraries:
| Feature | LiteLight | Lightbox2 | FancyBox | PhotoSwipe |
|---|---|---|---|---|
| Dependencies | None — pure vanilla JS | Requires jQuery | Requires jQuery | None |
| Bundle Size | <10KB | ~100KB+ | ~200KB+ | ~50KB |
| Touch / Swipe | ✓ | ✗ | ✓ | ✓ |
| Keyboard Nav | ✓ | ✓ | ✓ | ✓ |
| ES Modules | ✓ | ✗ | ✗ | ✓ |
| 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 |