Step 1 – Add The Following Customized Code to Your Page:
Add this code inside the<head>
of your page, just before the closing </head>
tag:Note: If you're using WordPress, you can add this code to the head.php template file.
<body>
of your page, just before the closing </body>
tag:Note: If you're using WordPress, you can add this code to the footer.php template file.
Step 2 – Enable Lightbox for Specific Images
To enable the lightbox effect for a given image, simply add
class="fancybox"
to the image's <img>
tag. For example:<img src="my-image.jpg" />
Becomes:<img class="fancybox" src="my-image.jpg" />
For each lightbox-enabled image, you may also want to set some custom options:
Because you selected the 'all images' option above, no additional changes are needed. The lightbox effect will automatically be applied to all photos in your page. You may want to set some custom options, though:
Setting Big-Image SourcesBy default, the same image that is included in your page will be shown in the lightbox, but at full size. Often, though, you will want to have a low-resolution version inline in your page, and display a higher-resolution version in the lightbox. To set a custom image source for lightbox display, set the
data-big
attribute on the <img>
tag. For example:<img class="fancybox" src="small-image.jpg" />
Becomes:<img class="fancybox" src="small-image.jpg" data-big="big-image.jpg" />
Setting CaptionsAs exemplified in the first demo image above, you can optionally specify captions for your lightbox-enabled images. To control the caption displayed for a photo, set the title attribute on its
<img>
tag.For example:
<img class="fancybox" src="my-image.jpg" />
Becomes:<img class="fancybox" src="my-image.jpg" title="Image Caption Text" />