Basic example
Use these default button styles with multiple colors to indicate an action or link within your website.



<div
data-te-lightbox-init
class="flex flex-col space-y-5 lg:flex-row lg:space-x-5 lg:space-y-0">
<div class="h-full w-full">
<img
src="https://mdbcdn.b-cdn.net/img/Photos/Thumbnails/Slides/1.webp"
data-te-img="https://mdbcdn.b-cdn.net/img/Photos/Slides/1.webp"
alt="Table Full of Spices"
class="w-full cursor-zoom-in data-[te-lightbox-disabled]:cursor-auto" />
</div>
<div class="h-full w-full">
<img
src="https://mdbcdn.b-cdn.net/img/Photos/Thumbnails/Slides/2.webp"
data-te-img="https://mdbcdn.b-cdn.net/img/Photos/Slides/2.webp"
alt="Winter Landscape"
class="w-full cursor-zoom-in data-[te-lightbox-disabled]:cursor-auto" />
</div>
<div class="h-full w-full">
<img
src="https://mdbcdn.b-cdn.net/img/Photos/Thumbnails/Slides/3.webp"
data-te-img="https://mdbcdn.b-cdn.net/img/Photos/Slides/3.webp"
alt="View of the City in the Mountains"
class="w-full cursor-zoom-in data-[te-lightbox-disabled]:cursor-auto" />
</div>
</div>
// Initialization for ES Users
import {
Lightbox,
initTE,
} from "tw-elements";
initTE({ Lightbox });
Hey there 👋 we want to make TW elements a community-driven project. It's open source and free, and we would like it to stay that way. If you enjoy it, help the project grow by sharing it with your peers. Every share counts, thank you!
Image optimization
To ensure the proper performance of the page, it is recommended to include
thumbnails of images in the src attribute. Then in the
data-te-img
attribute add the path to the image with higher resolution. If the
data-te-img
attribute is omitted, the lightbox will display the
same image as in the reduced size.
<img
src="https://mdbcdn.b-cdn.net/img/Photos/Thumbnails/Slides/1.webp"
data-te-img="https://mdbcdn.b-cdn.net/img/Photos/Slides/1.webp"
alt="Table Full of Spices"
class="w-full cursor-zoom-in data-[te-lightbox-disabled]:cursor-auto" />
Shadows and rounded corners
You can improve the look of the images by adding shadows and rounded corners.



<div
data-te-lightbox-init
class="flex flex-col space-y-5 lg:flex-row lg:space-x-5 lg:space-y-0">
<div class="h-full w-full">
<img
src="https://mdbcdn.b-cdn.net/img/Photos/Thumbnails/Slides/1.webp"
data-te-img="https://mdbcdn.b-cdn.net/img/Photos/Slides/1.webp"
alt="Table Full of Spices"
class="w-full cursor-zoom-in rounded shadow-sm data-[te-lightbox-disabled]:cursor-auto" />
</div>
<div class="h-full w-full">
<img
src="https://mdbcdn.b-cdn.net/img/Photos/Thumbnails/Slides/2.webp"
data-te-img="https://mdbcdn.b-cdn.net/img/Photos/Slides/2.webp"
alt="Winter Landscape"
class="w-full cursor-zoom-in rounded shadow-sm data-[te-lightbox-disabled]:cursor-auto" />
</div>
<div class="h-full w-full">
<img
src="https://mdbcdn.b-cdn.net/img/Photos/Thumbnails/Slides/3.webp"
data-te-img="https://mdbcdn.b-cdn.net/img/Photos/Slides/3.webp"
alt="View of the City in the Mountains"
class="w-full cursor-zoom-in rounded shadow-sm data-[te-lightbox-disabled]:cursor-auto" />
</div>
</div>
// Initialization for ES Users
import {
Lightbox,
initTE,
} from "tw-elements";
initTE({ Lightbox });
Different sizes
Loaded images can have any aspect ratio. Their size will be automatically adjusted to the window when you open the lightbox.



<div
data-te-lightbox-init
class="flex flex-col space-y-5 lg:flex-row lg:space-x-5 lg:space-y-0">
<div class="flex h-full w-full flex-1 flex-col">
<img
src="https://mdbcdn.b-cdn.net/img/Photos/Thumbnails/Slides/1.webp"
data-te-img="https://mdbcdn.b-cdn.net/img/Photos/Slides/1.webp"
alt="Table Full of Spices"
class="mb-5 w-full cursor-zoom-in data-[te-lightbox-disabled]:cursor-auto" />
<img
src="https://mdbcdn.b-cdn.net/img/Photos/Thumbnails/Square/1.webp"
data-te-img="https://mdbcdn.b-cdn.net/img/Photos/Square/1.webp"
alt="Coconut with Strawberries"
class="w-full cursor-zoom-in data-[te-lightbox-disabled]:cursor-auto" />
</div>
<div class="flex h-full w-full flex-1 flex-col">
<img
src="https://mdbcdn.b-cdn.net/img/Photos/Thumbnails/Vertical/1.webp"
data-te-img="https://mdbcdn.b-cdn.net/img/Photos/Vertical/1.webp"
alt="Dark Roast Iced Coffee"
class="w-full cursor-zoom-in data-[te-lightbox-disabled]:cursor-auto" />
</div>
</div>
// Initialization for ES Users
import {
Lightbox,
initTE,
} from "tw-elements";
initTE({ Lightbox });
Zoom level
The data-te-zoom-level
attribute allows you to define the size
of a single zoom in / zoom out.



<div
data-te-lightbox-init
data-te-zoom-level="0.25"
class="flex flex-col space-y-5 lg:flex-row lg:space-x-5 lg:space-y-0">
<div class="h-full w-full">
<img
src="https://mdbcdn.b-cdn.net/img/Photos/Thumbnails/Slides/1.webp"
data-te-img="https://mdbcdn.b-cdn.net/img/Photos/Slides/1.webp"
alt="Table Full of Spices"
class="w-full cursor-zoom-in data-[te-lightbox-disabled]:cursor-auto" />
</div>
<div class="h-full w-full">
<img
src="https://mdbcdn.b-cdn.net/img/Photos/Thumbnails/Slides/2.webp"
data-te-img="https://mdbcdn.b-cdn.net/img/Photos/Slides/2.webp"
alt="Winter Landscape"
class="w-full cursor-zoom-in data-[te-lightbox-disabled]:cursor-auto" />
</div>
<div class="h-full w-full">
<img
src="https://mdbcdn.b-cdn.net/img/Photos/Thumbnails/Slides/3.webp"
data-te-img="https://mdbcdn.b-cdn.net/img/Photos/Slides/3.webp"
alt="View of the City in the Mountains"
class="w-full cursor-zoom-in data-[te-lightbox-disabled]:cursor-auto" />
</div>
</div>
// Initialization for ES Users
import {
Lightbox,
initTE,
} from "tw-elements";
initTE({ Lightbox });
Disabled image
By adding a data-te-lightbox-disabled
attribute to any image,
you can exclude it from your lightbox. In the example below, the third image
has been disabled.




<div
data-te-lightbox-init
class="flex flex-col space-y-5 lg:flex-row lg:space-x-5 lg:space-y-0">
<div class="h-full w-full">
<img
src="https://mdbcdn.b-cdn.net/img/Photos/Thumbnails/Slides/1.webp"
data-te-img="https://mdbcdn.b-cdn.net/img/Photos/Slides/1.webp"
alt="Table Full of Spices"
class="w-full cursor-zoom-in data-[te-lightbox-disabled]:cursor-auto" />
</div>
<div class="h-full w-full">
<img
src="https://mdbcdn.b-cdn.net/img/Photos/Thumbnails/Slides/2.webp"
data-te-img="https://mdbcdn.b-cdn.net/img/Photos/Slides/2.webp"
alt="Winter Landscape"
class="w-full cursor-zoom-in data-[te-lightbox-disabled]:cursor-auto" />
</div>
<div class="h-full w-full">
<img
src="https://mdbcdn.b-cdn.net/img/Photos/Thumbnails/Slides/3.webp"
data-te-img="https://mdbcdn.b-cdn.net/img/Photos/Slides/3.webp"
data-te-lightbox-disabled
alt="Disabled image"
class="w-full cursor-zoom-in data-[te-lightbox-disabled]:cursor-auto" />
</div>
<div class="h-full w-full">
<img
src="https://mdbcdn.b-cdn.net/img/Photos/Thumbnails/Slides/4.webp"
data-te-img="https://mdbcdn.b-cdn.net/img/Photos/Slides/4.webp"
alt="Place Royale Bruxelles"
class="w-full cursor-zoom-in data-[te-lightbox-disabled]:cursor-auto" />
</div>
</div>
// Initialization for ES Users
import {
Lightbox,
initTE,
} from "tw-elements";
initTE({ Lightbox });
Captions
Image captions can be added using the
data-te-caption
attribute. If it is not set, the data is taken
from the alt
attribute. When you want to disable caption, leave
the data-te-caption
empty.



<div
data-te-lightbox-init
class="flex flex-col space-y-5 lg:flex-row lg:space-x-5 lg:space-y-0">
<div class="h-full w-full">
<img
src="https://mdbcdn.b-cdn.net/img/Photos/Thumbnails/Slides/1.webp"
data-te-img="https://mdbcdn.b-cdn.net/img/Photos/Slides/1.webp"
data-te-caption="Image caption 1"
alt="Table Full of Spices"
class="w-full cursor-zoom-in data-[te-lightbox-disabled]:cursor-auto" />
</div>
<div class="h-full w-full">
<img
src="https://mdbcdn.b-cdn.net/img/Photos/Thumbnails/Slides/2.webp"
data-te-img="https://mdbcdn.b-cdn.net/img/Photos/Slides/2.webp"
data-te-caption="Image caption 2"
alt="Winter Landscape"
class="w-full cursor-zoom-in data-[te-lightbox-disabled]:cursor-auto" />
</div>
<div class="h-full w-full">
<img
src="https://mdbcdn.b-cdn.net/img/Photos/Thumbnails/Slides/3.webp"
data-te-img="https://mdbcdn.b-cdn.net/img/Photos/Slides/3.webp"
data-te-caption="Image caption 3"
alt="View of the City in the Mountains"
class="w-full cursor-zoom-in data-[te-lightbox-disabled]:cursor-auto" />
</div>
</div>
// Initialization for ES Users
import {
Lightbox,
initTE,
} from "tw-elements";
initTE({ Lightbox });
Outside access
The lightbox can be successfully operated via JavaScript. There are many
public methods available such as open
, slide
,
zoomIn
, zoomOut
, or close
. All are
described in the API tab.



<div
data-te-lightbox-init
id="lightbox"
class="flex flex-col space-y-5 lg:flex-row lg:space-x-5 lg:space-y-0">
<div class="h-full w-full">
<img
src="https://mdbcdn.b-cdn.net/img/Photos/Thumbnails/Slides/1.webp"
data-te-img="https://mdbcdn.b-cdn.net/img/Photos/Slides/1.webp"
data-te-caption="Image caption 1"
alt="Table Full of Spices"
class="w-full cursor-zoom-in data-[te-lightbox-disabled]:cursor-auto" />
</div>
<div class="h-full w-full">
<img
src="https://mdbcdn.b-cdn.net/img/Photos/Thumbnails/Slides/2.webp"
data-te-img="https://mdbcdn.b-cdn.net/img/Photos/Slides/2.webp"
data-te-caption="Image caption 2"
alt="Winter Landscape"
class="w-full cursor-zoom-in data-[te-lightbox-disabled]:cursor-auto" />
</div>
<div class="h-full w-full">
<img
src="https://mdbcdn.b-cdn.net/img/Photos/Thumbnails/Slides/3.webp"
data-te-img="https://mdbcdn.b-cdn.net/img/Photos/Slides/3.webp"
data-te-caption="Image caption 3"
alt="View of the City in the Mountains"
class="w-full cursor-zoom-in data-[te-lightbox-disabled]:cursor-auto" />
</div>
</div>
<div class="mt-3 text-center">
<button
type="button"
id="lightboxToggler"
data-te-ripple-init
data-te-ripple-color="light"
class="inline-block rounded bg-primary px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-white shadow-[0_4px_9px_-4px_#3b71ca] transition duration-150 ease-in-out hover:bg-primary-600 hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:bg-primary-600 focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:outline-none focus:ring-0 active:bg-primary-700 active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] dark:shadow-[0_4px_9px_-4px_rgba(59,113,202,0.5)] dark:hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)]">
Open second image
</button>
</div>
// Initialization for ES Users
import {
Lightbox,
initTE,
} from "tw-elements";
initTE({ Lightbox });
const lightbox = document.getElementById("lightbox");
const lightboxInstance = Lightbox.getInstance(lightbox);
const lightboxToggler = document.getElementById("lightboxToggler");
lightboxToggler.addEventListener("click", () => {
lightboxInstance.open(1);
});
const lightbox = document.getElementById("lightbox");
const lightboxInstance = te.Lightbox.getInstance(lightbox);
const lightboxToggler = document.getElementById("lightboxToggler");
lightboxToggler.addEventListener("click", () => {
lightboxInstance.open(1);
});
Related resources
If you are looking for more advanced options, try Bootstrap Lightbox from MDBootstrap.