Simple Image Slider using HTML & CSS



Hello developers, today in this blog, you'll learn to create a Simple Image Slider using HTML & CSS.

The Image Slider is also called Image Carousel or Slideshow. The Image Slider may be the convenient way to display the changing or sliding images one by one on your website. Image slider or slideshow commonly shows one large image at a time with a little scrap of text, at the bottom of the image. In the Image Slider, the images will slide one by one when the button is clicked, manually.

In this blog Image Slider, there are four images but only a single image will appear at the front. There are buttons on the bottom of the image which works manually by clicking on the button. These buttons slide the images forward and backward one by one on a button click. By clicking on the button you can see the images as you want.

The source code of this Simple Image Slider is given below, if you want the source code of this program, you can copy it. You can use this Simple Image Slider with your creativity and can take this project to the next level.

Simple Image Slider [Source Code]

To make this website, you would like to make two files: an HTML file & a CSS file. First, create an HTML file with the name of index.html and remember, you have to create a file with a .html extension.

<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <title>Basic CSS3 Slider || learningRobo</title> <link rel="stylesheet" href="./style.css"> </head> <body> <div id="slider-wrapper"> <div class="inner-wrapper"> <input checked type="radio" name="slide" class="control" id="Slide1" /> <label for="Slide1" id="s1"></label> <input type="radio" name="slide" class="control" id="Slide2" /> <label for="Slide2" id="s2"></label> <input type="radio" name="slide" class="control" id="Slide3" /> <label for="Slide3" id="s3"></label> <input type="radio" name="slide" class="control" id="Slide4" /> <label for="Slide4" id="s4"></label> <div class="overflow-wrapper"> <a class="slide" href=""><img src="https://cdn.pixabay.com/photo/2021/11/23/13/32/forest-6818683__480.jpg" /></a> <a class="slide" href=""><img src="https://cdn.pixabay.com/photo/2021/11/22/17/25/birds-6816960__480.jpg" /></a> <a class="slide" href=""><img src="https://cdn.pixabay.com/photo/2021/11/22/22/06/animal-6817499__480.jpg" /></a> <a class="slide" href=""><img src="https://cdn.pixabay.com/photo/2021/11/25/19/50/tape-6824489__480.jpg" /></a> </div> </div> </div> <div class="credit">Made with <span style="color:tomato;font-size:20px;">❤</span> by <a href="https://www.learningrobo.com/">Learning Robo</a></div> <script src="./script.js"></script> </body> </html>
CSS provides style to an HTML page. To make the page attractive create a CSS file with the name style.css and remember that you have to make a file with a .css extension.


body{
  background: #9D50BB;
  background: -webkit-linear-gradient(to right, #6E48AA, #9D50BB);
  background: linear-gradient(to right, #6E48AA, #9D50BB);

}
#slider-wrapper {
  width: 940px;
  height: 470px;
  margin: 100px auto;
  position: relative;
  margin-bottom: 0px;
  background: rgba(0, 0, 0, 0.5);
  overflow: hidden;
  border-radius: 10px;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

#s1 {
  padding: 6px;
  background: #fff;
  position: absolute;
  left: 50%;
  bottom: 25px;
  margin-left: -36px;
  border-radius: 20px;
  opacity: 0.3;
  cursor: pointer;
  z-index: 999;
}

#s2 {
  padding: 6px;
  background: #fff;
  position: absolute;
  left: 50%;
  bottom: 25px;
  margin-left: -12px;
  border-radius: 20px;
  opacity: 0.3;
  cursor: pointer;
  z-index: 999;
}

#s3 {
  padding: 6px;
  background: #fff;
  position: absolute;
  left: 50%;
  bottom: 25px;
  margin-left: 12px;
  border-radius: 20px;
  opacity: 0.3;
  cursor: pointer;
  z-index: 999;
}

#s4 {
  padding: 6px;
  background: #fff;
  position: absolute;
  left: 50%;
  bottom: 25px;
  margin-left: 36px;
  border-radius: 20px;
  opacity: 0.3;
  cursor: pointer;
  z-index: 999;
}

#s1:hover,
#s2:hover,
#s3:hover,
#s4:hover {
  opacity: 1;
}

.inner-wrapper {
  width: 940px;
  height: 470px;
  position: absolute;
  top: 0;
  left: 0;
  margin-bottom: 0px;
  overflow: hidden;
}

.control {
  display: none;
}

#Slide1:checked ~ .overflow-wrapper {
  margin-left: 0%;
}

#Slide2:checked ~ .overflow-wrapper {
  margin-left: -100%;
}

#Slide3:checked ~ .overflow-wrapper {
  margin-left: -200%;
}

#Slide4:checked ~ .overflow-wrapper {
  margin-left: -300%;
}

#Slide1:checked + #s1 {
  opacity: 1;
}

#Slide2:checked + #s2 {
  opacity: 1;
}

#Slide3:checked + #s3 {
  opacity: 1;
}

#Slide4:checked + #s4 {
  opacity: 1;
}

.overflow-wrapper {
  width: 400%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  overflow-y: hidden;
  z-index: 1;
  -webkit-transition: all 0.3s ease-in-out;
  -moz-transition: all 0.3s ease-in-out;
  -o-transition: all 0.3s ease-in-out;
  transition: all 0.3s ease-in-out;
}

.slide img {
  width: 25%;
  float: left;
}
.credit a{
  text-decoration: none;
  color: #fff;
  font-weight: 800;
  }
  
  .credit {
    font-family: Verdana, Geneva, Tahoma, sans-serif;
    margin: 10px;
    color:#000;
    text-align: center;
  }
We hope you would like this Simple Image Slider using HTML & CSS.

Thank you for reading our blog. If you face any problem in creating this Simple Image Slider using HTML & CSS, then contact us or comment us. We’ll try to provide a solution to your problem as soon as possible.

Thank you
Learning robo team

Post a Comment

Thank you
Learning robo team

Post a Comment (0)

Previous Post Next Post
Learning Robo says...
code copied
Welcome