Animated Slideshow App in HTML CSS & JavaScript Last Updated : 29 Jul, 2024 Comments Improve Suggest changes Like Article Like Report We will learn to create a slideshow of multiple images. This slideshow will transition between the images every few seconds. we will further learn to align the images, style the images, and make the animation look better.PrerequisitesHTMLCSSJSApproachCreate 3 files one for HTML, one for CSS, and one for JS in a single folder.In HTML file, Add the below HTML code. In this code, we have two main tags one is Heading and the other is a Division with 6 images. Adding the CSS Stylesheet link and the script to the JS file which is created in the same folder. Also, add slide, and fade classes to every image div.In CSS, we define the classes mentioned in the HTML class attributes. To create animation we have used a class called fade which creates a fading effect. Inside the fade class, we have an animation property with a duration of 2 seconds and triggered infinity. Using @keyframes we toggle the opacity of the slide between 0.4 to 1.0 and create fade effect.In JS file, we have nextSlide( ) function that is invoked every 2 seconds using setInterval( ) and is used to call other function showSlide( ) in the same file. showSlide( ) iterates through every slide and toggles the display of the slide which matches with the passed index. The index is generated by taking the modulus between currentSlide (Starts with zero) number and 6 as there are 6 slides and this generates numbers in sequential order starting from 1.Example: This example shows the implementation of the above-explained approach. HTML <!DOCTYPE html> <html> <head> <title>GFG</title> <link rel="stylesheet" href="style.css" /> </head> <body> <h1>Slide Show</h1> <div class="slideshow-container"> <div class="slide fade"> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20231126110234/ezgifcom-gif-maker-1.webp" alt="Slide 1"> </div> <div class="slide fade"> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20231217134958/Group-23.png" alt="Slide 2"> </div> <div class="slide fade"> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20240106180224/Screenshot-2024-01-06-174436.gif" alt="Slide 3"> </div> <div class="slide fade"> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20240109190054/Screenshot-2024-01-09-185442.gif" alt="Slide 3"> </div> <div class="slide fade"> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20231123180952/Group-18.png" alt="Slide 3"> </div> <div class="slide fade"> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20231121180023/Group-17.png" alt="Slide 3"> </div> </div> <script src="./script.js"></script> </body> </html> CSS body { padding-bottom: 20px; font-family: Arial, sans-serif; display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100vh; box-sizing: border-box; overflow: hidden; } h1 { font-size: 4vw; } .slideshow-container { width: 60%; aspect-ratio: 1; position: relative; margin: auto; overflow: hidden; border-radius: 10px; box-shadow: 2px 2px 5px } .slide { display: none; width: 100%; height: 100%; overflow: hidden; justify-content: center; align-items: center; } img { width: 100%; height: 100%; object-fit: contains; } .fade { animation: fade 2s ease-in-out infinite; } @keyframes fade { from { opacity: 0.4; } to { opacity: 1; } } JavaScript let currentSlide = 0; function showSlide(index) { const slides = document.querySelectorAll('.slide'); slides.forEach((slide, i) => { slide.style.display = i === index ? 'flex' : 'none'; }); } function nextSlide() { currentSlide = (currentSlide + 1) % 6; showSlide(currentSlide); } setInterval(nextSlide, 2000); Output: Comment More infoAdvertise with us Next Article Animated Slideshow App in HTML CSS & JavaScript nikhilkalburgi Follow Improve Article Tags : Project JavaScript Web Technologies Dev Scripter JavaScript-Projects Dev Scripter 2024 +2 More Similar Reads Create a Splash Page App in HTML CSS & JavaScript The Splash Screen is the UI element that appears as the initial screen or the loading screen. Splash Page Application consists of a styled animative splash screen effect which automatically makes the curtain opening splash effect into the application for a specific time and renders the dynamic conte 4 min read 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 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 Top JavaScript Animation Libraries Sometimes you have seen some amazing cool animations on different websites or landing pages. It gives an appealing look to your websites when you add eye-catching animations. And animations are one of the most effective and efficient ways to attract users' attention to your website.But have you guys 6 min read How to Create a Quotes Slideshow with CSS and JavaScript? A quotes slideshow is a web component that displays a series of quotes in a sequential manner. Users can either view these quotes automatically or interactively through navigation controls. we'll explore how to create a quotes slideshow using HTML, CSS, and JavaScript.Approach Create a basic HTML do 4 min read Design a Video Slide Animation Effect using HTML CSS and JavaScript Nowadays, Video Slide animations are very popular. In this article, we will see how to make Video Slide Animation using HTML, CSS, and JavaScript on any webpage. Below are the two steps on how to do it. It will help the beginner to build some awesome Video Slide animations using HTML, CSS, and JS by 4 min read Design Joke Generator App in HTML CSS & JavaScript We will go to learn how can we create a Joke generator app using HTML, CSS, and JavaScript. We will also add a feature to copy the generated joke. We will use API to fetch the jokes and will show those jokes on the screen. PrerequisitesHTMLCSSJavaScriptApproachCreate the Joke Generator Application U 3 min read Automatic Image Slider using JavaScript In this article, we will discuss how to create an automatic image slider using JavaScript. An image slider is a popular component of modern websites that allows the display of multiple images in a single location, usually in a sliding motion. With the use of JavaScript, creating an automatic image s 3 min read Create a Single Page Application using HTML CSS & JavaScript In this article, we are going to design and build a cool and user-friendly single-page application (SPA) using just HTML, CSS, and JavaScript. A single-page application contains multiple pages which can be navigated or visited without loading the page every time. This makes things faster and more in 4 min read How to make Animated Click Effect using HTML CSS and JavaScript ? In this article, we will see how to make an Animated Click Effect using HTML CSS, and JavaScript. We generally see animations on modern websites that are smooth and give users a good experience. Here, we will see when the user clicks on the button only then some animation would appear. The animation 3 min read Like