Simple and easy to use lightbox with baguetteBox.js

Simple and easy to use lightbox with baguetteBox.js


BaguetteBox is an easy to use, simple and great looking free lightbox script. Written in pure JavaScript, no dependencies required, support many advanced features such as multiple-gallery, swipe gesture, responsive and minimal look with image captions support

baquettebox lightbox


  • Written in pure JavaScript, no dependencies required
  • Multiple-gallery support, allows custom options for each
  • Supports swipe gestures on touch-screen devices
  • Modern and minimal look
  • Image captions support
  • Responsive images
  • CSS3 transitions
  • SVG buttons, no extra files to download
  • Around 2KB gzipped


bower install baguettebox.js


1. Include JavaScript & CSS

<link rel='stylesheet' href=''>
<script src=''></script>


I've taken some photos from the author's websites to make the demo

<div class="gallery">
    <a href="" data-caption="Golden Gate Bridge"><img src=""></a>
    <a href="" title="Midnight City"><img src=""></a>
    <a href=""><img src=""></a>

We make it look a little bit better with some pieces of CSS

.gallery img {
    height: 100%;

.gallery a {
    width: 240px;
    height: 180px;
    display: inline-block;
    overflow: hidden;
    margin: 4px 6px;
    box-shadow: 0 0 4px -1px #000;



See the Pen baguetteBox.js demo by Thanh Nguyen (@genievn) on CodePen.


1. Responsive images

To use this feature, simply put data-at-{width} attributes on a tags with value being a path to the desired image. {width} should be the maximum screen width the image can be displayed at. The script chooses the first image with {width} greater than or equal to the current screen width for best user experience.

Here's an example of what the HTML code can look like:

<a href="img/2-1.jpg" 
    <img src="img/thumbs/2-1.jpg">

2. Customization

You can pass an object with custom options as a second parameter. The following are available with their corresponding defaults:

  captions: true,       // true|false - Display image captions
  buttons: 'auto',      // 'auto'|true|false - Display buttons
  async: false,         // true|false - Load files asynchronously
  preload: 2,           // [number] - How many files should be preloaded from current image
  animation: 'slideIn'  // 'slideIn'|'fadeIn'|false - Animation type