
A lightbox gallery is basically used to view the gallery images in detail specifically. You can code the JavaScript to do so but also we can use some downloaded JS and CSS. In this article, we will download the lightbox and attach the JS and CSS files into our code. For our own design satisfaction, we can also use the CSS code as we want. We will divide the task into three sections. In the first section, we will create the structure in the second section we sill add som CSS for our own purpose. In the last section, we will link the downloaded JS snd CSS files.
We have to download the lightbox, we can dowonload that from the link: https://github.com/lokesh/lightbox2/releases
Creating Structure: In this section, we will code only in HTML to create a normal HTML gallary.
- HTML Code:
<!DOCTYPE html><html><head><title>Lightbox Gallery</title></head><body><h2>GeeksforGeeks</h2><b>A Computer Science Portal for Geeks</b><divclass="gallery"><ahref=<imgsrc=</a><ahref=<imgsrc=</a><ahref=<imgsrc=</a><ahref=<imgsrc=</a><ahref=<imgsrc=</a><ahref=<imgsrc=</a></div></body></html>chevron_rightfilter_none
Desing Structure: In this section, we will add some CSS property to make image gallery attractive.
- CSS Code:
<style>body {text-align:center;}h2{color:green;}.gallery {margin:10px40px;}.gallery img {width:200px;height:50px;transition:1s;padding:5px;}.gallery img:hover {filter: drop-shadow(4px4px6pxgray);transform: scale(1.1);}</style>chevron_rightfilter_none
Final Solution: In this section you have to link the downloaded CSS and JS file into your code. You can simply link the downloaded file by unzipping the file. For the CSS file, use the <link> tag with href attribute for the address of CSS and for JS file use the <script> tag with src attribute for the code. Atlast we have to put data-lightbox=”mygallery” attribute inside the <a> tag. Next and previous button will automatically attached during JS file attachment.
- Final Code:
<!DOCTYPE html><html><head><title>Lightbox Gallery</title><linkrel="stylesheet"type="text/css"href="lightbox2/dist/css/lightbox.min.css"><scriptsrc="lightbox2/dist/js/lightbox-plus-jquery.min.js"></script><style>body {text-align: center;}h2 {color: green;}.gallery {margin: 10px 40px;}.gallery img {width: 200px;height: 50px;transition: 1s;padding: 5px;}.gallery img:hover {filter: drop-shadow(4px 4px 6px gray);transform: scale(1.1);}</style></head><body><h2>GeeksforGeeks</h2><b>A Computer Science Portal for Geeks</b><divclass="gallery"><ahref=data-lightbox="mygallery"><imgsrc=</a><ahref=data-lightbox="mygallery"><imgsrc=</a><ahref=data-lightbox="mygallery"><imgsrc=</a><ahref=data-lightbox="mygallery"><imgsrc=</a><ahref=data-lightbox="mygallery"><imgsrc=</a><ahref=data-lightbox="mygallery"><imgsrc=</a></div></body></html>chevron_rightfilter_none - Output:
Recommended Posts:
- How to create responsive image gallery using HTML, CSS, jQuery and Bootstrap?
- How to Create a Tab Image Gallery ?
- How to create a Portfolio Gallery using HTML and CSS ?
- How to add filter with Portfolio Gallery using HTML, CSS and JavaScript ?
- CSS | Image Gallery
- How to create an image element dynamically using JavaScript ?
- How to create a JavaScript callback for knowing if an image is loaded ?
- How to create a Hero Image using HTML and CSS ?
- How to Create a Wave Image for a Background using HTML and CSS ?
- How to Create Image Overlay Hover using HTML & CSS ?
- How to Create an Image Overlay Icon using HTML and CSS ?
- How to Create Scroll Indicator using HTML CSS and JavaScript ?
- How to disable dragging an image from an HTML page using JavaScript/jQuery ?
- Create a Hoverable Side Navigation with HTML, CSS and JavaScript
- How to Create Shrink Header on Scroll using HTML, CSS and JavaScript ?
- How to Create Full Screen Overlay Navigation Bar using HTML CSS and JavaScript ?
- Create a Mobile Toggle Navigation Menu using HTML, CSS and JavaScript
- How to create linear-gradient color generator using HTML, CSS and JavaScript ?
- Create a Table of Content in Tree View Architecture using HTML, CSS and JavaScript
- Convert an image into grayscale image using HTML/CSS
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


