Design a Rotating Image Gallery App in HTML CSS & JavaScript Last Updated : 29 Jul, 2024 Comments Improve Suggest changes Like Article Like Report We'll gather some images and build a gallery that can be rotated with straightforward buttons. To rotate the images to the right, we'll use the right button, and for left rotation, we'll use the left button. The process will be simple, allowing us to easily rotate the images using these buttons.Preview ImageApproachTo start, we make a folder. In this folder, we put three files for HTML, CSS, and JavaScript.In the HTML file, we design the layout of the image gallery app. We add images using a link, and we can also use the link for the images. In this case, we use the GFG image link.In the CSS file, we write some styles to make the visualization more appealing. We also set parameters for rotation.In the JavaScript file, we write the main logic. This logic enables easy rotation of images from left to right by clicking the corresponding left and right buttons. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content= "width=device-width, initial-scale=1.0"> <title>Rotating Gallery</title> <link rel="stylesheet" href="/style.css"> <style> </style> </head> <body> <div class="image-container"> <span style="--i: 1"> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20240213150115/ppp.png" alt=""> </span> <span style="--i: 2"> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20240216133007/20.jpg" alt=""> </span> <span style="--i: 3"> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20240216140352/Business-Intelligence-Tools.webp" alt=""> </span> <span style="--i: 4"> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20240216134711/stock-vector-food-chain-colored-vector-illustration-2184501363.jpg" alt=""> </span> <span style="--i: 5"> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20240216135604/file.webp" alt=""> </span> <span style="--i: 6"> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20240216135739/Data-Management-tools.webp" alt=""> </span> <span style="--i: 7"> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20240216141611/file.jpg" alt=""> </span> <span style="--i: 8"> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20240216141633/2.webp" alt=""> </span> </div> <div class="overlay" id="overlay"> <img class="popup-img" id="popup-img" src="" alt="Popup Image"> </div> <div class="btn-container"> <button class="btn" id="prev"> Left </button> <button class="btn" id="next"> Right </button> </div> <script src="/script.js"> </script> </body> </html> CSS body { margin: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; height: 100vh; overflow: hidden; } .image-container { position: relative; width: 200px; height: 200px; transform-style: preserve-3d; transform: perspective(1000px) rotate(0deg); transition: transform 0.7s; } .image-container span { position: absolute; top: 0; left: 0; width: 100%; cursor: pointer; transform: rotateY(calc(var(--i) * 45deg)) translateZ(400px); transition: transform 0.3s ease; } .image-container span img { position: absolute; left: 0; top: 0; border-radius: 10px; width: 80%; transition: transform 0.3s ease; } .overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); z-index: 10; display: none; justify-content: center; align-items: center; } .overlay.active { display: flex; } .popup-img { width: 300px; height: 300px; margin-top: -5%; margin-left: -4%; background-color: rgb(82, 80, 80); border-radius: 15px; } .btn-container { position: relative; width: 80%; } .btn { position: absolute; bottom: -80px; background-color: rgb(98, 226, 98); color: black; font-weight: bold; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; } #prev { left: 20%; } #next { right: 20%; } #btn:hover { filter: brightness(1.5); } JavaScript const imageContainer = document.querySelector('.image-container'); const prevBtn = document.getElementById('prev'); const nextBtn = document.getElementById('next'); const overlay = document.getElementById('overlay'); const popupImg = document.getElementById('popup-img'); const images = document.querySelectorAll('.image-container span img'); let x = 0; prevBtn.addEventListener('click', () => { x = x + 45; rotate(); }); nextBtn.addEventListener('click', () => { x = x - 45; rotate(); }); images.forEach(image => { image.addEventListener('click', () => { const src = image.getAttribute('src'); popupImg.setAttribute('src', src); overlay.classList.add('active'); }); }); overlay.addEventListener('click', () => { overlay.classList.remove('active'); }); function rotate() { imageContainer.style.transform = `perspective(1000px) rotateY(${x}deg)`; } Output: Comment More infoAdvertise with us Next Article Design a Rotating Image Gallery App in HTML CSS & JavaScript K kasoti2002 Follow Improve Article Tags : Project JavaScript Web Technologies Dev Scripter JavaScript-Projects Dev Scripter 2024 +2 More Similar Reads Design an Image Search App in HTML CSS & JavaScript Image Search Application contains an input field, which takes the choice or type of the image for which the user is searching. When the user enters the search string and clicks on the button, the top 10 images are shown to the user. If the user wants more images, then there is a Generate More button 4 min read How to Create Image Lightbox Gallery using HTML CSS and JavaScript ? 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, 3 min read How to preview Image on click in Gallery View using HTML, CSS and JavaScript ? In this article, we see how easily we can create an Image Gallery with a preview feature using HTML, CSS, and some JavaScript.ApproachCreate a div with a class container.Create two more div inside the first div one for the main view and the other for the side view with classes main_view and side_vie 2 min read How to Create Image Gallery using JavaScript? An Image Gallery is a collection of images displayed in a grid or slideshow format on a webpage. To create an Image Gallery using JavaScript, you can dynamically load images, create HTML elements, and use CSS for styling. JavaScript can add interactivity, like transitions and navigation controls.Her 3 min read Design an Expanding Image Gallery Template using HTML and CSS In this article, we design an expanding image gallery template using HTML and CSS. An Expanding Image Gallery provides an interactive user experience compared to static galleries. The image expands when the user hovers over the image, enhancing user experience. This template allows for an intuitive 2 min read Create a Resize and Compress Images in HTML CSS & JavaScript While using the GeeksforGeeks Write Portal to write articles, we need to upload the images. As we need to resize the image as per GeeksforGeeks's requirement, we search for different tools and websites on the internet to resize and compress the image. But, as a web developer, we can create our own i 7 min read Build an AI Image Generator Website in HTML CSS and JavaScript Create an AI image generator website using HTML, CSS, and JavaScript by developing a user interface that lets users input text prompts and generate images by AI.We incorporated API integration to fetch data, providing users with an effortless and dynamic experience in generating AI-driven images. An 4 min read Design a Layered Image Page Template using HTML and CSS The article provides a complete guide for creating a layered image layout using HTML and CSS. The Layered Image Page refers to a webpage design that contains layered structured visual elements using images. Here, the design contains two boxes with background images and some empty rounded boxes with 3 min read How to create image slider using HTML CSS and JavaScript ? An image slide, or slideshow, is a dynamic display of images that automatically transitions from one to the next, often with animations. To create an image slide, use HTML to structure the images, CSS for styling and animations, and JavaScript to control the timing and transitions between images.App 3 min read Create A Draggable Card Slider in HTML CSS & JavaScript In this article, we will demonstrate how to create a draggable card slider using HTML, CSS, and JavaScript. We'll use a GeeksforGeeks card slider as an example and implement the functionality to slide cards left and right using arrow buttons. Additionally, we'll incorporate the draggable option, all 5 min read Like