Two individual images
Four image set
Download a zip of the latest release (or any previous one) from the Github Releases page.
Or install using npm:
npm install lightbox2 --save
Open up the zip file and take a peek at the barebones, working example that is included in the
- Include the CSS at the top of your page in your
Make sure jQuery, which is required by Lightbox, is also loaded.
- If you already use jQuery on your page, make sure it is loaded before
lightbox.js. jQuery 1.7 or greater is required, and since the effects module is utilized, the jQuery slim build is not supported.
- If you are not currently using jQuery, I've created a packaged file that includes both Lightbox and jQuery. Include
dist/js/lightbox-plus-jquery.js instead of
- Confirm that the four images loaded by
lightbox.css are in the correct location. You can grab the images from the
Initialize with HTML
- Single images. Add a
data-lightbox attribute to any image link to enable Lightbox. For the value of the attribute, use a unique name for each image. For example:
- Add a
data-title attribute if you want to show a caption.
- Add a
data-alt attribute if you want to set the alt attribute of the linked image.
- Image sets. If you have a group of related images that you would like to combine into a set, use the same
data-lightbox attribute value for all of the images. For example:
If you want to change any of the default options, call the option method.
||If true, the left and right navigation arrows which appear on mouse hover when viewing image sets will always be visible on devices which support touch.
||"Image %1 of %2"
||The text displayed below the caption when viewing an image set. The default text shows the current image number and the total number of images in the set.
||If true, prevent the page from scrolling while Lightbox is open. This works by settings overflow hidden on the body.
||The time it takes for the Lightbox container and overlay to fade in and out, in milliseconds.
||If true, resize images that would extend outside of the viewport so they fit neatly inside of it. This saves the user from having to scroll to see the entire image.
||The time it takes for the image to fade in once loaded, in milliseconds.
||If set, the image width will be limited to this number, in pixels. Aspect ratio will not be maintained.
||If set, the image height will be limited to this number, in pixels. Aspect ratio will not be maintained.
||The distance from top of viewport that the Lightbox container will appear, in pixels.
||The time it takes for the Lightbox container to animate its width and height when transition between different size images, in milliseconds.
||If false, the text indicating the current image number and the total number of images in set (Ex. "image 2 of 4") will be hidden.
||If true, when a user reaches the last image in a set, the right navigation arrow will appear and they will be to continue moving forward which will take them back to the first image in the set.
Lightbox2 has been tested successfully in the following browsers:
- Internet Explorer.
lightbox-plus-jquery.js file includes jQuery v2.x and supports IE 9+. If you want to support IE 6, 7, and 8, use your own copy of jQuery v1.x with
- iOS Safari
- iOS Chrome
- Android Browser
- Android Chrome
Lightbox2 is licensed under The MIT License.
- 100% Free. Lightbox is free to use in both commercial and non-commercial work.
- Attribution is required. This means you must leave my name, my homepage link, and the license info intact. None of these items have to be user-facing and can remain within the code.
Have a question about how to use Lightbox?
Follow the steps below to get help. Make sure you have read the documentation on this page and looked at the included example first.
- Search Stackoverflow to see if other people have run into the same issue you are having.
- If your issue is unique, then post a new question on Stackoverflow. Use the
Do not use Github Issues to report personal support requests.
Found a bug?
If you find a bug, please file a Github issue.