Automatic Image Slider in HTML/CSS

Automatic Image Slider in HTML/CSS: Hey folks! Today in this Post we will understand how we can create a beautiful and attractive Image slider in HTML CSS. Before Deep diving into the topic lets understand some basic points as well.

Automatic Image Slider in HTML CSS

What is an Automatic Image Slider ?

An automatic image slider is a user interface element commonly used in web design to display a series of images or content in a slide-show format. It is designed to automatically transition through a set of images or content without requiring any user interaction. The images or content can be displayed in a sequential order or randomly, and the speed of the slide-show can be adjusted to match the needs of the website.

The purpose of an automatic image slider is to provide an engaging and visually appealing way to present information or products on a website, which can help to increase user engagement and improve the overall user experience.

Importance of an automatic image slider

An automatic image slider is an important element in web design as it offers several benefits that can help to enhance the user experience and improve website engagement. Some of the key benefits of an automatic image slider include:

  1. Improved User Engagement: An automatic image slider can grab the user’s attention and keep them engaged with the website. This is because the movement and transition of the images can create a visually appealing and dynamic experience that draws the user in and encourages them to explore more of the website.
  2. Efficient Use of Space: An automatic image slider can help to maximize the use of space on a web page by allowing the display of multiple images or content in a limited space. This can be particularly useful on homepages or landing pages, where there may be a need to showcase a variety of products or information.
  3. Highlighting Important Content: An automatic image slider can be used to highlight important content or products on a website. This is because the user’s attention is drawn to the moving images, which can help to emphasize the importance of the content being displayed.
  4. Easy to Use: An automatic image slider is easy to use and requires no user interaction. This means that the user can simply sit back and enjoy the content being displayed without having to manually navigate through the images.

Automatic Image Slider in HTML CSS [Source Codes]

In order to develop an automatic image slideshow effect program, you will need to create two files – an HTML file and a CSS file. Once you have created these files, you can simply copy and paste the provided code into your HTML file. Start by creating an HTML file named ‘index.html’ and ensure that it has a .html extension.

<!DOCTYPE html>
<!-- Created By GeekyBeginners -->
<html lang="en" dir="ltr">
      <meta charset="utf-8">
      <title>Automatic Image Slider in HTML CSS | GeekyBeginners</title>
      <link rel="stylesheet" href="style.css">
      <div class="content">
         <div class="images">
            <img src="#">
            <img src="#">
            <img src="#">
            <img src="#">
            <img src="#">
         var indexValue = 0;
         function slideShow(){
           setTimeout(slideShow, 2500);
           var x;
           const img = document.querySelectorAll("img");
           for(x = 0; x < img.length; x++){
             img[x].style.display = "none";
           if(indexValue > img.length){indexValue = 1}
           img[indexValue -1].style.display = "block";

Next, you should create a CSS file named ‘style.css’ and paste the provided code into it. It is important to ensure that the file is saved with a .css extension.

  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  height: 400px;
  width: 750px;
  overflow: hidden;
  box-shadow: 1px 1px 15px rgba(0,0,0,0.4);
.content .images{
  height: 100%;
  width: 100%;
.images img{
  height: 100%;
  width: 100%;

Importance of having an Automatic Image Slider in a website

Having an automatic image slider on a website can have many benefits, such as:

  1. Attracting Attention: An automatic image slider is a visually appealing element that can attract the visitor’s attention and make them more likely to engage with the content of the website. This can lead to increased time spent on the website, improved user engagement, and a higher chance of the visitor becoming a customer.
  2. Showcasing Content: An automatic image slider can showcase multiple pieces of content or products in a single space, making it ideal for websites that need to display a variety of information or products. This can help the visitor to quickly understand the offerings of the website and find what they are looking for.
  3. Providing a Professional Look: An automatic image slider can add a professional look and feel to a website, making it appear more polished and modern. This can improve the overall perception of the website and increase the trust and credibility of the brand.
  4. Enhancing User Experience: An automatic image slider can enhance the user experience by providing a dynamic and interactive element to the website. This can make the visitor feel more engaged and invested in the content of the website, leading to increased user satisfaction and loyalty.


Congratulations! You have successfully created an automatic image slider using HTML, CSS, and JavaScript. In case you encounter any errors or issues with your code, you can download the source code files from the provided download button. The download is free, and a .zip file will be downloaded, which you can extract to access the source code files.

Write for us
GeekyBeginners articles are written by software geeks like you. If you also would like to contribute to GeekyBeginners by writing paid articles, you can check the write for us page.

Leave a Comment