Spotlight JS is a tiny, dependency-free image viewer that instantly turns images on any webpage into a polished full-screen gallery. It provides smooth animations, trackpad gestures, touch, keyboard shortcuts and fullscreen support β all wired up automatically with zero configuration.
- Lightweight and self-contained β drop in
spotlight.min.jsand it just works. - Automatic grouping β images inside
<article>or elements with the.galleryclass become collections. - Fast, fluid animations β hardware-accelerated transitions for a native feel.
- Accessible β ARIA live region and sensible focus management.
- Automatic detection of images inside
articleand.gallery - Fullscreen viewer with smooth transitions
- Zoom (buttons, mouse wheel, trackpad, pinch)
- Pan by dragging
- Trackpad gestures
- Touch support
- Keyboard navigation (Arrow keys + optional VIM-like keys)
- Captions from
figcaption,alt, ordata-caption - Dark / light theme support via
prefers-color-scheme - No external dependencies
Experience full control via keyboard, mouse, touch, and trackpad.
Include the built script on your page:
<script src="spotlight.min.js"></script>Spotlight initializes automatically when a user clicks an image inside an article or a .gallery element.
Write normal HTML β Spotlight works with simple images or semantic markup:
<article>
<figure>
<img src="photo1.jpg" alt="Mountains at sunrise" />
<figcaption>Mountains at sunrise</figcaption>
</figure>
<img src="photo2.jpg" alt="Forest trail" />
</article>Or use a gallery:
<div class="gallery">
<img src="a.jpg" />
<img src="b.jpg" />
<img src="c.jpg" />
</div>Click any image to open the viewer.
To contribute or build Spotlight from source:
-
Clone the repository:
git clone https://github.com/jarpex/spotlight-js.git cd spotlight-js -
Install dependencies:
npm install
-
Build the project:
Spotlight offers two build modes:
-
Optimized Build (Default):
npm run build
Creates a highly compressed bundle in
dist/spotlight.min.js. This mode aggressively renames CSS classes and IDs to short tokens (e.g.,a,b) to minimize size. Warning: This may cause conflicts if your page uses similar short class names or IDs. -
Safe Build:
npm run build:safe
Creates a standard minified bundle that preserves original class names and IDs. Use this version to avoid conflicts with other scripts or styles on your page, or if you need to use the Programmatic API.
-
Note: The programmatic API is available only in the safe build.
The standard
npm run buildcommand uses aggressive minification that renames classes and symbols, making the API inaccessible. To use the API, build the project withnpm run build:safe.
Spotlight.open(collectionIndex, itemIndex)β Opens the gallery. Defaults to the first image in the first collection if no indices are provided.Spotlight.rescan()β Re-scans the DOM for new images. Call this after dynamically adding content to the page.Spotlight.getCapturedErrors()β Retrieves a list of non-fatal errors logged by the library.Spotlight.clearCapturedErrors()β Clears the list of captured errors.
Spotlight.instanceβ Returns the active Spotlight instance, ornullif the gallery has not been initialized.Spotlight.debugβ Enables verbose console logging when set totrue. Only functional in development builds.
Access the instance via Spotlight.instance.
instance.attachImage(element, collectionIndex, itemIndex)β Manually registers an image element with the Spotlight gallery.
// Enable debug mode
Spotlight.debug = true;
// Open the first image in the first collection
Spotlight.open(0, 0);
// Manually attach an image
const instance = Spotlight.instance;
if (instance) {
const img = document.querySelector('#my-image');
instance.attachImage(img, 0, 0);
}Spotlight JS is released under the MIT License β see LICENSE. It bundles Tabler Icons (MIT) as noted in LICENSE.tabler-icons.




