Documentation
Complete API reference for litelight-js v1.5.0 — zero dependencies,
~5.1 KB gzipped combined (3.9 KB JS + 1.2 KB CSS), MIT license.
Try the live demo or compare alternatives.
Installation recipes
Always load both the JavaScript and CSS files. The stylesheet is not bundled inside the JS module.
npm / ES Modules (Vite, webpack, Rollup, esbuild)
npm install litelight-js
import { init } from 'litelight-js';
import 'litelight-js/css';
init();
CDN (unpkg — ES module, no bundler)
<link rel="stylesheet" href="https://unpkg.com/litelight-js@1.5.0/dist/lite-light.min.css">
<script type="module">
import { init } from 'https://unpkg.com/litelight-js@1.5.0/dist/lite-light.min.js';
init();
</script>
UMD global (classic <script> tag)
<link rel="stylesheet" href="https://unpkg.com/litelight-js@1.5.0/dist/lite-light.min.css">
<script src="https://unpkg.com/litelight-js@1.5.0/dist/lite-light.umd.min.js"></script>
<script>
LiteLight.init();
</script>
Manual download
Copy dist/lite-light.min.js and dist/lite-light.min.css from the
1.5.0 npm release:
<link rel="stylesheet" href="/vendor/lite-light.min.css">
<script type="module">
import { init } from '/vendor/lite-light.min.js';
init();
</script>
init(options) API & TypeScript
init() registers a single delegated click listener on document and runs the optional
data-lightbox-cover pass once. Subsequent calls to init() are no-ops.
init and initLiteLight are identical exports.
| Option | Type | Default | Description |
|---|---|---|---|
imageSelector |
string |
'img[data-lightbox]' |
CSS selector for triggers. Use 'a[data-lightbox]' for text links or combine both. |
imageUrlAttribute |
string |
'data-lightbox' |
Attribute holding the full-size image URL. |
lightboxClass |
string |
'lite-light' |
Root CSS class name on the lightbox overlay element. |
swipeThreshold |
number |
50 |
Horizontal swipe distance in pixels for mobile prev/next navigation. |
fadeAnimationDuration |
number |
150 |
Fade duration in milliseconds; sets CSS --ll-duration on open. |
groupAttribute |
string |
'data-lightbox-group' |
Attribute on a trigger or ancestor naming an independent gallery. |
coverAttribute |
string |
'data-lightbox-cover' |
Collapses a gallery to one visible on-page thumbnail; hidden items open in the lightbox. |
thumbAttribute |
string |
'data-lightbox-thumb' |
Marks which trigger stays visible in a cover gallery (defaults to first trigger). |
LiteLightOptions TypeScript interface
Type definitions ship directly in the package at dist/lite-light.d.ts:
export interface LiteLightOptions {
/**
* CSS selector for gallery triggers. Default: `'img[data-lightbox]'`.
* Use `'a[data-lightbox]'` for text links, or
* `'img[data-lightbox], a[data-lightbox]'` to mix images and links.
*/
imageSelector?: string;
/** Attribute on each trigger that holds the full-size image URL. Default: `'data-lightbox'`. */
imageUrlAttribute?: string;
lightboxClass?: string;
swipeThreshold?: number;
fadeAnimationDuration?: number;
/**
* Attribute that names an independent gallery. Default: `'data-lightbox-group'`.
* Triggers with the same value (on the trigger or an ancestor) navigate only
* among themselves. Triggers without the attribute stay in one shared gallery.
* A group of one image hides prev/next.
*/
groupAttribute?: string;
/**
* Attribute that collapses a gallery to one visible trigger. Default: `'data-lightbox-cover'`.
* Put it on a wrapper or on each trigger in the set. The other triggers stay in the
* DOM and open inside the lightbox. A parent that contains only a hidden trigger is hidden
* with it. The hide pass runs once, when `init()` is called. Omit it and every trigger stays visible.
*/
coverAttribute?: string;
/**
* Attribute that marks the visible trigger in a cover gallery. Default: `'data-lightbox-thumb'`.
* Put it on one trigger. When no trigger has it, the first trigger in the set stays visible.
*/
thumbAttribute?: string;
}
export function init(options?: LiteLightOptions): void;
export function initLiteLight(options?: LiteLightOptions): void;
CSS custom property theming
Override any of the five CSS variables on .lite-light in your own stylesheet without forking
the library CSS. Backdrop blur applies automatically where backdrop-filter is supported.
| Variable | Default | Purpose |
|---|---|---|
--ll-overlay |
rgba(0, 0, 0, 0.75) |
Backdrop scrim color |
--ll-duration |
0.15s |
Image fade transition timing |
--ll-radius |
6px |
Lightbox image corner radius |
--ll-image-bg |
#fff |
Background matte behind transparent images |
--ll-control |
#fff |
Previous, next, and close icon color |
.lite-light {
--ll-overlay: rgba(20, 6, 3, 0.88);
--ll-duration: 0.2s;
--ll-radius: 10px;
--ll-image-bg: #140603;
--ll-control: #f2e9ce;
}
Framework integration
Because LiteLight uses global event delegation on document, call init() once after
your gallery elements are mounted. If you use data-lightbox-cover, ensure all cover images are
in the DOM before calling init().
React
import { useEffect } from 'react';
import { init } from 'litelight-js';
import 'litelight-js/css';
export function Gallery({ images }) {
useEffect(() => {
init();
}, []);
return images.map((img) => (
<img key={img.id} src={img.thumb} data-lightbox={img.full} alt={img.alt} />
));
}
Vue 3
<script setup>
import { onMounted } from 'vue';
import { init } from 'litelight-js';
import 'litelight-js/css';
onMounted(() => init());
</script>
<template>
<img v-for="img in images" :key="img.id"
:src="img.thumb" :data-lightbox="img.full" :alt="img.alt" />
</template>
Svelte
<script>
import { onMount } from 'svelte';
import { init } from 'litelight-js';
import 'litelight-js/css';
onMount(() => init());
</script>
{#each images as img (img.id)}
<img src={img.thumb} data-lightbox={img.full} alt={img.alt} />
{/each}
Astro
---
import 'litelight-js/css';
---
<img src="/thumb.jpg" data-lightbox="/full.jpg" alt="Mountain view" />
<script>
import { init } from 'litelight-js';
init();
</script>
Plain HTML
<link rel="stylesheet" href="https://unpkg.com/litelight-js@1.5.0/dist/lite-light.min.css">
<img src="thumb.jpg" data-lightbox="full.jpg" alt="Photo">
<script type="module">
import { init } from 'https://unpkg.com/litelight-js@1.5.0/dist/lite-light.min.js';
init();
</script>
Browser support & v1.5.0 behavior
| Browser | Minimum Version | Notes |
|---|---|---|
| Chrome | 112+ | Full support including backdrop blur |
| Edge | 112+ | Full support including backdrop blur |
| Firefox | 117+ | Full support including backdrop blur |
| Safari | 16.5+ | Solid scrim on Safari 16.5–17; backdrop blur on Safari 18+ |
Missing full-size image handling (v1.5.0)
If a full-size URL in data-lightbox fails to load, LiteLight 1.5.0 displays the loading spinner
for one second and then automatically advances to the next image in the active gallery. Arrow keys, clicks,
and swipes continue working during that second; closing the lightbox cancels the skip. If every image in the
gallery fails, the spinner stops instead of looping indefinitely.
Limitations & scope
LiteLight is intentionally focused on fast, minimal image galleries. Keep these boundaries in mind when evaluating it:
- Images only: LiteLight does not embed YouTube/Vimeo videos, iframes, or arbitrary HTML modals. If you need multi-media overlays, see GLightbox or FancyBox.
- Single
init()pass: Callinginit()a second time is a no-op and does not reconfigure options. Dynamically appended images still open via global click delegation, butdata-lightbox-coverhiding runs once wheninit()is called. - Modern browsers only: Requires Chrome 112+, Edge 112+, Firefox 117+, or Safari 16.5+ (no IE11 or legacy polyfill bundle).