A small, dependency-free lightbox and filterable grid for photos and videos. The gallery unfolds from the thumbnail you click; the grid animates between category filters.
Live demos · Documentation · Releases
- Images and video in one gallery: JPG, PNG and WebP (with
srcset), MP4 and WebM, YouTube and Vimeo. - Thumbnail strip, captions and a counter.
- Zoom: double-click, pinch, trackpad pinch or the zoom button; drag to pan.
- Fullscreen, slideshow with a progress bar, and an optional download button.
- Touch: swipe between slides, swipe down to close.
- Themes: dark, light or automatic, plus CSS custom properties for your own look.
- Accessible: dialog semantics, focus trap, keyboard (arrows, Home, End, Esc), respects reduced motion.
- Privacy friendly: YouTube and Vimeo players load only when the visitor presses play; YouTube uses
youtube-nocookie.com. - Filterable grid: cards glide, fade and scale between filters, with any CSS layout.
- Translatable and works on right-to-left pages.
No dependencies, about 11 KB minified and gzipped (JS + CSS).
From npm:
npm install foldboximport Foldbox from 'foldbox';
import 'foldbox/dist/foldbox.min.css';import gets the ES module build (dist/foldbox.mjs), which also has named exports (import { open, bind, grid } from 'foldbox'), and require( 'foldbox' ) the UMD build. TypeScript types are included, so editors autocomplete the options and items.
Or from the jsDelivr CDN:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/wpgenius/foldbox@1/dist/foldbox.min.css">
<script src="https://cdn.jsdelivr.net/gh/wpgenius/foldbox@1/dist/foldbox.min.js"></script>@1 follows the latest 1.x release; pin an exact version (such as @1.2.0) in production. Or download foldbox.min.js and foldbox.min.css from the latest release. Foldbox is a UMD module, so require( 'foldbox' ) and AMD loaders work too.
const items = [
{ src: 'beach.jpg', thumb: 'beach-thumb.jpg', alt: 'Beach', caption: 'Summer 2026' },
{ src: 'clip.mp4', poster: 'clip.jpg' },
{ src: 'https://www.youtube.com/watch?v=aqz-KE-bpKQ' },
{ src: 'https://vimeo.com/1084537', thumb: 'vimeo-thumb.jpg' },
];
button.addEventListener( 'click', () => {
Foldbox.open( items, { origin: button, theme: 'auto' } );
} );<div id="gallery">
<a href="large-1.jpg" data-caption="First"><img src="small-1.jpg" alt=""></a>
<a href="large-2.jpg" data-caption="Second"><img src="small-2.jpg" alt=""></a>
<a href="https://youtu.be/aqz-KE-bpKQ">Video</a>
</div>
<script>
Foldbox.bind( '#gallery', { download: true } );
</script>const grid = Foldbox.grid( '.grid', { itemSelector: ':scope > .card' } );
grid.filter( '.weddings' ); // CSS selector
grid.filter( '*' ); // everything
grid.filter( ( item ) => item.dataset.year === '2026' );Hidden items get the hidden attribute, so hide them in your CSS: .card[hidden] { display: none; }.
Foldbox.open( items, options ) |
Open a gallery. Returns an object with next(), prev(), goTo( i ), play(), pause(), toggleZoom(), toggleFullscreen() and close(). |
Foldbox.bind( container, options ) |
Open the links inside a container in a gallery. Returns an unbind function. |
Foldbox.grid( element, options ) |
Make a filterable grid with filter( selector | fn, instant ). |
Foldbox.close() |
Close the open gallery. |
Foldbox.defaults |
Default options for every gallery. |
Commonly used options: index, loop, animation ('slide' / 'fade'), theme ('dark' / 'light' / 'auto'), thumbnails, zoom, fullscreen, slideshow, download, captions, labels and the onOpen / onChange / onClose callbacks.
The documentation covers every item field, option, CSS property and translation label.
.foldbox {
--foldbox-bg: rgba(0, 0, 0, 0.9);
--foldbox-accent: #ffcc00;
--foldbox-top: 32px; /* leave room for a fixed header */
}See Themes and styling for all properties and how to make your own theme.
Foldbox.open() inserts captions as HTML, so escape anything that comes from users (or pass htmlCaptions: false). Foldbox.bind() shows captions as plain text by default, because they come from page markup.
Current versions of Chrome, Edge, Firefox and Safari, on desktop and mobile.
Issues and pull requests are welcome. See CONTRIBUTING.md for the full guide, the code of conduct, and SECURITY.md for reporting vulnerabilities privately.
npm install
npm run build # dist/foldbox.min.js, dist/foldbox.mjs and dist/foldbox.min.css
npm run site # assemble the website into _site/
npm test # TypeScript types, unit tests and browser tests (run `npx playwright install chromium firefox webkit` once)
npm run size # check the built files against their size limitsOpen demo/index.html (development demo, uses src/) or _site/index.html (the website) through a local web server.
- In a PR, change
src/,site/and docs only. Don't commitdist/orCHANGELOG.md, and don't change version numbers; the release workflow does that. CI fails if a PR touchesdist/orCHANGELOG.md. - Link your PR to its issue (
Fixes #12): the changelog lists one line per issue closed since the previous release. - Version: patch by default. Label the PR
release: minororrelease: majorfor a bigger bump.
Releases are automatic. When a change to src/ is merged into main, the release workflow bumps the version, rebuilds dist/, writes the CHANGELOG.md entry, publishes a GitHub release with the minified files and publishes the package to npm. To publish an existing release to npm again, run the Publish to npm workflow with its tag. The website in site/ is published to GitHub Pages when it changes and after every release, so the demos always use the latest version.
The demos on the website and in demo/ use photos from the WordPress Photo Directory, shared under CC0. Thank you to the photographers:
- Antonio López Chacón: Birds
- Brandon Zhang: Birds
- Mutebi Ivan Junior: Big animals
- RawKreative: Big animals
- Sujata Paul: Big animals
- jose3001: Waterfalls & forests
- dangrijal: Waterfalls & forests
- jbarquero90228: Waterfalls & forests, Beaches & sunsets
- Jessica Brenes: Waterfalls & forests, Flowers
- Mohithcharan V: Flowers
- Tawhid Sadman: Flowers
- jdaraya: Mountains & lakes
- xbullscm: Mountains & lakes
- vvega27: Mountains & lakes
- Francisco Mora: Mountains & lakes
- mhernandez10314: Beaches & sunsets
- Keily Nuñez Chaves: Beaches & sunsets
- Makarand Mane: Ceremony
- Anis: Ceremony, Celebrations
- Sharankrishna VP: Celebrations
- Bibek KC: Celebrations
- Javier Salinas: Celebrations
- Snehal Kashid: Indian flavours
- Tilak Bahadur Karki: Indian flavours
- Vishnu Chandra: Indian flavours
- Bigul Malayi: Indian flavours
- David Plaza: Bistro plates
- Joan Namunina: Bistro plates
- Swetha B Chandran: Bistro plates
- Alina Kakshapati: Bistro plates
Videos in the demos:
- Blender open movies by the Blender Foundation / Blender Studio, Creative Commons Attribution, embedded from their official channels: Big Buck Bunny (Vimeo), Spring, Sintel and Coffee Run (YouTube).
- Anna's hummingbird (Calypte anna) in the rain by Love Star Production, CC0, via Wikimedia Commons (the MP4 example, a trimmed copy hosted in the Coverfold repository).
MIT © WPGenius