Responsive Gallery Design using HTML, CSS, and Javascript

 Hello, learner In this article, we are going to create a Responsive Gallery Design using HTML, CSS, and Javascript. In the earlier past post, we have created Login and signup Form Design using HTML and Pure CSS. Now it is time to create a Responsive Gallery Design.

In this program, we are going to create a responsive Gallery Design Using HTML, CSS, and Javascript. As you see in the above image that is the output of the code. The image is taken from an internet source. There are Five different sections width different images. If you click on fig 2 whole screen changes the image without an error.

Responsive Gallery Design using HTML, CSS, and Javascript [Source code]

To create a Responsive Gallery Design using HTML, CSS, and Javascript you have to create three HTML, CSS, and Js files named index.html, style.css, and script.js in the same folder and you have to link the CSS and JS file to HTML. after that paste the HTML code in index.htm. paste the CSS code in style.css at last paste the JS code in Style.js that’s all after pasting the code. Now your Responsive Gallery Desing is ready.

At first, you have to create an HTML file named index.html paste the below code on it and save it. Remember to give a .html extension to the HTML file.

<!DOCTYPE html>  

 <html lang="en">  


   <meta charset="UTF-8" />  

   <meta http-equiv="X-UA-Compatible" content="IE=edge" />  

   <meta name="viewport" content="width=device-width, initial-scale=1.0" />  

   <title>Accordion gallery</title>  

   <link rel="stylesheet" href="style.css" />  



   <div id="bg"></div>  

   <div id="fg"></div>  

   <script src=""></script>  

   <script src="index.js"></script>  



After pasting the HTML code the second you have to create a CSS file named style.css. Paste the below code on it and save it. Again remember to give .css extension to CSS file.

@import url('');  

 html, body, #fg, #bg {  





  font-family:'Montserrat', sans-serif;  



 div {  




 sub {  




 p {  



After pasting both HTML and CSS code Now at last You have to create a Javascript file named script.js. after creating the file now paste the Below code in the js file. Remember to give .js extension to the javascript file.

var imgs = [  







 n = imgs.length,  

 current = n-1,  

 closedWidth = Math.floor(window.innerWidth/10)  

 for (var i=0; i<n; i++){="" var="" bgimg="document.createElement('div');" bg.appendchild(bgimg);="" gsap.set(bgimg,="" {="" attr:{id:'bgimg'+i,="" class:'bgimg'},="" width:'100%',="" height:'100%',="" backgroundimage:'url('+imgs[i]+')',="" backgroundsize:'cover',="" backgroundposition:'center'="" })="" b="document.createElement('div');" fg.appendchild(b);="" gsap.fromto(b,="" attr:{id:'b'+i,="" class:'box'},="" innerhtml:'<p=""><sub>Fig.</sub> '+(i+1)+'<p></p>',  



 borderLeft:(i>0)?'solid 1px #eee':'',  



 transformOrigin:'100% 100%',  







 b.onmouseenter = b.onclick = (e)=>{    

 if (Number( return;  

 var staggerOrder = !!(current < Number(;  

 current = Number(;'.box', {  



  left:(i)=>(i<=current)? i*closedWidth: window.innerWidth-((n-i)*closedWidth),  


  stagger: staggerOrder? 0.05:-0.05  


 bg.appendChild( document.getElementById('bgImg'+current) )  

 gsap.fromTo('#bgImg'+current, {opacity:0}, {opacity:1, duration:0.3, ease:'power1.inOut'})  

 gsap.fromTo('#bgImg'+current, {scale:1.05, rotation:0.05}, {scale:1, rotation:0, duration:1.5, ease:'sine'})   



 window.onresize = (e)=>{  

 closedWidth = Math.floor(window.innerWidth/10)  

 gsap.set('.box', { x:0, left:(i)=> (i<=current)? i*closedWidth: window.innerWidth-((n-i)*closedWidth) })  


That’s all after pasting all the code in the file now your code will successfully run. If you get any kind of error/problem in the code just comment down or contact me on social media

You might like this



Post a Comment

* Please Don't Spam Here. All the Comments are Reviewed by Admin.