Settings
lightGallery comes with a lot of settings, events, and methods to customize the gallery without touching the core code. You can find both lightGallery core settings, and the built in plugin settings here.
Passing settings
lightGallery accepts two parameters, an HTML element as the first parameter and library settings as the second parameter. You need to pass settings only if you want to modify default behaviors
lightGallery(document.getElementById('gallery-container'), {
speed: 500,
mode: 'lg-fade',
...Other settings
});
lightGallery core
LightGallery comes with modular architecture. All the basic functionalities are available in the core module. You need to include plugins such if you need additional functionalities such as thumbnails, vide support, zoom, etc. Here you can find all lightGallery core settings. If you think something is missing, please check the respective plugins settings as well.
Name | Type | Default |
---|---|---|
addClass | string | "" |
Add custom class for gallery container This can be used to set different style for different galleries |
||
allowMediaOverlap | boolean | false |
If true, toolbar, captions and thumbnails will not overlap with media element
This will not effect thumbnails if animateThumb is false
Also, toggle thumbnails button is not displayed if allowMediaOverlap is false
|
||
appendCounterTo | string | ".lg-toolbar" |
Where the counter should be appended |
||
appendSubHtmlTo | .lg-sub-html .lg-item .lg-outer | ".lg-sub-html" |
control where the sub-html should be appended. If you choose '.lg-outer', you are responsible for placing the div at the right position. '.lg-outer' is useful if you want show custom HTML outside the normal gallery |
||
ariaDescribedby | string | "" |
aria-describedby attribute for gallery |
||
ariaLabelledby | string | "" |
aria-labelledby attribute fot gallery |
||
backdropDuration | number | 300 |
Backdrop transition duration. Note - Do not change the value of backdrop via css. |
||
closable | boolean | true |
If false user won't be able to close the gallery at all This is useful for creating inline galleries. |
||
closeOnTap | boolean | true |
allows clicks on black area to close gallery. |
||
container | "" | |
Configure where the gallery should be appended. Useful to create inline galleries and more It is an empty string in the default settings and later assigned to document.body to avoid accessing document for SSR |
||
controls | boolean | true |
If false, prev/next buttons will not be displayed. |
||
counter | boolean | true |
Whether to show total number of images and index number of currently displayed image. |
||
defaultCaptionHeight | number | 0 |
Height of the caption for calculating allowMediaOverlap positions Note - this is only used to find the position of media item if allowMediaOverlap is true. Not for setting height of the captions Set 0 if you want to calculate the height of captions dynamically |
||
download | boolean | true |
Enable download button. By default download url will be taken from data-src/href attribute but it supports only for modern browsers. If you want you can provide another url for download via data-download-url. pass false in data-download-url if you want to hide download button for the particular slide. |
||
dynamic | boolean | false |
LightGallery can be instantiated and launched programmatically by setting this option to true and populating dynamicEl option (see below) with the definitions of images. |
||
dynamicEl | [] | |
An array of objects (src, iframe, subHtml, thumb, poster, responsive, srcset sizes) representing gallery elements. |
||
easing | string | "ease" |
Slide animation CSS easing property |
||
enableDrag | boolean | true |
Enables desktop mouse drag support |
||
enableSwipe | boolean | true |
Enables swipe support for touch devices |
||
escKey | boolean | true |
Whether the LightGallery could be closed by pressing the "Esc" key. |
||
exThumbImage | string | "" |
Option to fetch different thumbnail image other than first image If you want to use external image for thumbnail, add the path of that image inside "data-" attribute and set value of this option to the name of your custom attribute.
|
||
extraProps | [] | |
Fetch custom properties from the selector this is useful for plugin development By default lightGallery fetches and store all the props selectors to reduce frequent dom interaction for fetching props every time. If you need any addition data to be fetched and stored in the galleryItems variable, you can do this just by passing the prop names via extraProps
|
||
getCaptionFromTitleOrAlt | boolean | true |
Option to get captions from alt or title tags. |
||
height | string | "100%" |
Height of the gallery. example '100%' , '300px' |
||
hideBarsDelay | number | 0 |
Delay for hiding gallery controls in ms.
Pass |
||
hideControlOnEnd | boolean | false |
If true, prev/next button will be hidden on first/last image. Note - this option will be ignored if |
||
hideScrollbar | boolean | false |
Hide scrollbar when gallery is opened Minimum lightGallery version required: V2.5.0 |
||
iframeHeight | string | "100%" |
Set height for iframe. |
||
iframeMaxHeight | string | "100%" |
Set max height for iframe. |
||
iframeMaxWidth | string | "100%" |
Set max width for iframe. |
||
iframeWidth | string | "100%" |
Set width for iframe. |
||
index | number | 0 |
specify which slide should load initially |
||
isMobile | undefined | |
Function to detect mobile devices |
||
keyPress | boolean | true |
Enable keyboard navigation |
||
licenseKey | string | "0000-0000-000-0000" |
If you are using lightGallery for commercial projects, you need to purchase a commercial license to get the license key. For projects that are compatible with GPLv3 license, please contact us for getting a license key at contact@lightgalleryjs.com. If you want to test lightGallery before purchasing a commercial license, you can use `0000-0000-000-0000` as a temporary license key |
||
loadYouTubePoster | boolean | true |
Automatically load poster image for YouTube videos |
||
loop | boolean | true |
If false, will disable the ability to loop back to the beginning of the gallery from the last slide. |
||
mobileSettings | Partial | { controls: false, showCloseIcon: false, download: false, } as MobileSettings |
Separate settings for mobile devices Note - this is applied only at the time of loading by default controls and close buttons are disabled on mobile devices. use this options if you want to enable them or change any other settings for mobile devices Note - mobileSettings does not merge default values, You need to provide all mobileSettings including default values |
||
mode | lg-slide lg-fade lg-zoom-in lg-zoom-in-big lg-zoom-out lg-zoom-out-big lg-zoom-out-in lg-zoom-in-out lg-soft-zoom lg-scale-up lg-slide-circular lg-slide-circular-vertical lg-slide-vertical lg-slide-vertical-growth lg-slide-skew-only lg-slide-skew-only-rev lg-slide-skew-only-y lg-slide-skew-only-y-rev lg-slide-skew lg-slide-skew-rev lg-slide-skew-cross lg-slide-skew-cross-rev lg-slide-skew-ver lg-slide-skew-ver-rev lg-slide-skew-ver-cross lg-slide-skew-ver-cross-rev lg-lollipop lg-lollipop-rev lg-rotate lg-rotate-rev lg-tube | "lg-slide" |
Type of transition between images. |
||
mousewheel | boolean | false |
ability to navigate to next/prev slides on mousewheel |
||
nextHtml | string | "" |
Custom html for next control |
||
numberOfSlideItemsInDom | number | 10 |
Control how many slide items should be kept in dom at a time To improve performance by reducing number of gallery items in the dom, lightGallery keeps only the lowest possible number of slides in the dom at a time. This has a minimum value of 3 |
||
plugins | [] | |
preload | number | 2 |
number of preload slides will exicute only after the current slide is fully loaded. for example, if you click on 4th image and if preload = 1 then 3rd slide and 5th slide will be loaded in the background after the 4th slide is fully loaded.. if preload is 2 then 2nd 3rd 5th 6th slides will be preloaded. |
||
prevHtml | string | "" |
Custom html for prev control |
||
resetScrollPosition | boolean | true |
Reset to previous scrollPosition when lightGallery is closed By default, lightGallery doesn't hide the scrollbar for a smooth opening transition. If a user changes the scroll position, lightGallery resets it to the previous value Minimum lightGallery version required: V2.5.0 |
||
selectWithin | string | "" |
By default selector element relative to the current gallery. Instead of that you can tell lightGallery to select element relative to another element. Example - '.my-selector-container' | '#my-selector-container' In the code this become selector = document.querySelector(this.s.selectWithin ).querySelectorAll(this.s.selector); |
||
selector | "" | |
Custom selector property instead of direct children. Based on your markup structure, you can specify custom selectors to fetch media data for the gallery Pass "this" to select same element You can also pass HTMLCollection directly Example - '.my-selector' | '#my-selector' | this | document.querySelectorAll('.my-selector') |
||
showBarsAfter | number | 10000 |
Delay in hiding controls for the first time when gallery is opened |
||
showCloseIcon | boolean | true |
If false, close button won't be displayed. Useful for creating inline galleries. |
||
showMaximizeIcon | boolean | false |
Show maximize icon. Useful for creating inline galleries. |
||
slideDelay | number | 0 |
Delay slide transitions. This is useful if you want to do any action in the current slide before moving to next slide.
|
||
slideEndAnimation | boolean | true |
Enable slideEnd animation |
||
speed | number | 400 |
Transition duration (in ms). |
||
startAnimationDuration | number | 400 |
Zoom from image animation duration |
||
startClass | string | "lg-start-zoom" |
Start animation class for the gallery.
|
||
strings | LightGalleryCoreStrings | { closeGallery: 'Close gallery', toggleMaximize: 'Toggle maximize', previousSlide: 'Previous slide', nextSlide: 'Next slide', download: 'Download', playVideo: 'Play video', mediaLoadingFailed: 'Oops... Failed to load content...', } as LightGalleryCoreStrings |
Customize string. This can be useful if you want to localize the lightGallery strings to other languages. Use your own service to translate the strings and pass it via settings.strings You can find dedicated strings option for all lightGallery modules in their respective documentation. Note - You need to provide values for all the strings. For example, even if you just want to change the closeGallery string, you need to provide all the other strings as well. |
||
subHtmlSelectorRelative | boolean | false |
Set to true if the selector in "data-sub-html" should use the current item as its origin. |
||
supportLegacyBrowser | boolean | true |
Support legacy browsers Currently this is used only for adding support to srcset attribute via picturefill library If true lightGallery will show warning message to include picturefill library |
||
swipeThreshold | number | 50 |
By setting the swipeThreshold (in px) you can set how far the user must swipe for the next/prev image. |
||
swipeToClose | boolean | true |
allows vertical drag/swipe to close gallery
|
||
trapFocus | boolean | true |
Trap focus within the lightGallery Minimum lightGallery version required: V2.5.0 |
||
videoMaxSize | string | "1280-720" |
Video max size. This can be over-written by passing specific size via data-lg-size attribute Recommended video resolution and & aspect ratios https://support.google.com/youtube/answer/6375112 |
||
width | string | "100%" |
Width of the gallery. example '100%' , '300px' |
||
zoomFromOrigin | boolean | true |
Enable zoom from origin effect. You need to know the original image size upfront and provide it via data-lg-size attribute as
|