A lightbox and filterable grid that unfolds from your thumbnails
Foldbox shows photos, MP4, YouTube and Vimeo in one gallery, with thumbnails, zoom, fullscreen and slideshow, and animates your grid between category filters. No dependencies, about 11 KB gzipped.
- No dependencies
- MIT licensed
- Touch and keyboard
- Accessible dialog
- Privacy-friendly video
Try it
Everything below is the real library. Click a cover, swipe, pinch, use the arrow keys, or press Esc to close.
Albums with an animated filter
Pick a category: cards glide into place, fade and scale. Open an album and the gallery grows out of its cover.
Images and videos in one gallery
Images, an MP4 file, YouTube and Vimeo. Video players load only when you press play; YouTube uses youtube-nocookie.com.
Plain links, one line of JavaScript
Ordinary <a href> links become a gallery with Foldbox.bind(). This one uses the fade animation.
<div id="gallery">
<a href="large-1.jpg" data-caption="Waterfall"><img src="small-1.jpg" alt="Waterfall"></a>
<a href="large-2.jpg" data-caption="Falls"><img src="small-2.jpg" alt="Falls"></a>
</div>
<script>
Foldbox.bind( '#gallery', { animation: 'fade' } );
</script>Playground
Switch options on and off, then open the gallery. The code updates as you go.
Three steps
Foldbox is two files. Include them, describe your items, and open the gallery.
Include the files
One stylesheet and one script, from a CDN or your own server.
<link rel="stylesheet" href="foldbox.min.css">
<script src="foldbox.min.js"></script>Describe your items
A list of images or videos. The type is detected from the URL.
const items = [
{ src: 'beach.jpg', caption: 'Beach' },
{ src: 'clip.mp4', poster: 'clip.jpg' },
{ src: 'https://youtu.be/aqz-KE-bpKQ' },
];Open the gallery
From a click, a button or anywhere in your code.
button.addEventListener( 'click', () => {
Foldbox.open( items, { origin: button } );
} );What's inside
Images and video
JPG, PNG, WebP with srcset, MP4 and WebM, YouTube and Vimeo in the same gallery.
Filterable grid
Animate any CSS grid, flex or float layout between filters. Cards glide, fade and scale.
Zoom and pan
Double-click, pinch, trackpad pinch or the zoom button. Drag to look around.
Fullscreen and slideshow
A slideshow with a progress bar, fullscreen mode and an optional download button.
Touch friendly
Swipe between slides, swipe down to close, pinch to zoom.
Accessible
Dialog semantics, focus trap, keyboard navigation, screen reader labels, reduced motion.
Privacy friendly
YouTube and Vimeo players load only on play. YouTube uses the no-cookie domain.
Themes
Dark, light or automatic, and CSS custom properties for your own look.
Translatable
Every label can be replaced, including the "1 / 5" counter. Works on RTL pages.
Install
Install from npm, use the jsDelivr CDN, or download the two files from the latest release.
<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 @, for production.
Download foldbox.min.js and foldbox.min.css from the latest release, put them in your project and include them:
<link rel="stylesheet" href="foldbox.min.css">
<script src="foldbox.min.js"></script>npm install foldboxThen import it in your bundle: import gets the ES module build, require( 'foldbox' ) the UMD build, and TypeScript types are included.
import Foldbox from 'foldbox';
import 'foldbox/dist/foldbox.min.css';Contributors
Foldbox is open source. Thank you to everyone who has reported issues, tested and sent code.
Want to help?
Report a bug, suggest a feature or send a pull request.




