API Docs

Dynamic variables

In dynamic mode you build the gallery from data instead of markup: set the dynamic option and pass an array of item objects as dynamicEl. The fields below are the ones each item can carry. Demo

Passing items

Each item is a plain object. Only src is required; the other fields switch on captions, video, downloads and sharing per slide.

const gallery = lightGallery(document.getElementById('dynamic-gallery'), {
    dynamic: true,
    dynamicEl: [
        {
            src: 'img/1.jpg',
            thumb: 'img/thumb-1.jpg',
            subHtml: '<h4>Image 1</h4><p>Description of image 1.</p>',
        },
        {
            src: 'img/2.jpg',
            thumb: 'img/thumb-2.jpg',
            subHtml: '<h4>Image 2</h4>',
        },
    ],
});

// Open at the second slide.
gallery.openGallery(1);

A dynamic gallery has no trigger markup, so the zoom-from-origin animation needs two things from you: the media size on the item as lgSize, and the element the slide should grow out of as the second argument of openGallery:

const gallery = lightGallery(document.getElementById('dynamic-gallery'), {
    dynamic: true,
    dynamicEl: [
        { src: 'img/1.jpg', thumb: 'img/thumb-1.jpg', lgSize: '1600-1067' },
    ],
});

document.getElementById('cover').addEventListener('click', () => {
    gallery.openGallery(0, document.getElementById('cover'));
});

A data-lg-size attribute on that element works too and takes precedence. Without a size or an element, the slide uses the default opening animation.

In React, Vue and Angular the same fields describe an item or an entry of the slides array, with caption in place of subHtml.

Available fields

Every field has an HTML attribute twin for galleries built from markup; the attributes page lists those.

Name Description
alt alt attribute for the image
disqusIdentifier Disqus page identifier

Please refer official disqus documentation for more info

disqusUrl Disqus page url

Please refer official disqus documentation for more info

download Name of the file after it is downloaded.

The HTML value of the download attribute. There are no restrictions on allowed values, and the browser will automatically detect the correct file extension and add it to the file (.img, .pdf, .txt, .html, etc.). More info

downloadUrl Download url for your image/video.

Pass false if you want to disable the download button.

facebookShareUrl Facebook share URL.

Specify only if you want to provide separate share URL for the specific slide. By default, current browser URL is taken.

fbHtml Facebook comments body html

Please refer facebook official documentation for generating the HTML markup

<div
     class="fb-comments"
     data-href="https://www.example.com/your-page/#lg=1&slide=0"
     data-width="400"
     data-numposts="5">
</div>
iframe Set true is you want to open your url in an iframe
iframeTitle Title for iframe
lgSize Original size of the media as "WIDTH-HEIGHT", for example 1600-1067.

Drives the zoom-from-origin opening and closing animation and the size of video slides. In a gallery built from markup it is read from the item element. In dynamic mode set it on the item and pass the element the slide should grow out of as the second argument of openGallery; a data-lg-size attribute on that element still wins.

pinterestShareUrl Pinterest share URL.

Specify only if you want to provide separate share URL for the specific slide. By default, current browser URL will be taken. Note?: Pinterest requires absolute URL

pinterestText Description for Pinterest post.
poster Poster url
responsive List of images and viewport's max width separated by comma.

Ex?: img/1-375.jpg 375, img/1-480.jpg 480, img/1-757.jpg 757.

shareUrl Canonical share URL for the native share sheet (Web Share API).

Specify only if you want a separate URL for the specific slide. Falls back to the network-specific share URLs, then the current browser URL.

sizes srcset sizes attribute for the main image
slideName Custom slide name to use in the url when hash plugin is enabled
sources Source attributes for the picture element
src url of the media
srcset srcset attribute values for the main image
subHtml Caption for the slide

You can either pass the HTML markup or the ID or class name of the element which contains the captions

subHtmlUrl url of the file which contain the sub html.

Note - Does not support Internet Explorer browser

thumb Thumbnail url

By default lightGallery uses the image inside gallery selector as thumbnail. But, If you want to use external image for thumbnail, pass the thumbnail url via any data attribute and pass the attribute name via exThumbImage option

<div id="lightGallery">
    <a href="a.jpg" data-external-thumb-image="images/externalThumb.jpg" ><img src="thumb.jpg" /></a>
</div>

lightGallery(document.getElementById('lightGallery'), {
    exThumbImage: 'data-external-thumb-image'
})
title Title attribute for the image or video. With the getCaptionFromTitleOrAlt setting, it is used as the caption when subHtml is not set.
tweetText Tweet text
twitterShareUrl Twitter share URL.

Specify only if you want to provide separate share URL for the specific slide. By default, current browser URL will be taken.

video Video source
width Actual size of the image in px.

This is used in zoom plugin to see the actual size of the image when double-tapped on the image.

Edit this page on GitHub