Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • jQuery Tutorial
  • jQuery Selectors
  • jQuery Events
  • jQuery Effects
  • jQuery Traversing
  • jQuery HTML & CSS
  • jQuery AJAX
  • jQuery Properties
  • jQuery Examples
  • jQuery Interview Questions
  • jQuery Plugins
  • jQuery Cheat Sheet
  • jQuery UI
  • jQuery Mobile
  • jQWidgets
  • Easy UI
  • Web Technology
Open In App
Next Article:
How to Design Image Slider using jQuery ?
Next article icon

How to Design Image Slider using jQuery ?

Last Updated : 28 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

A slideshow container that cycles through a list of images on a web page. The following article will guide you to implement an image slider using HTML, CSS, and jQuery. The jQuery image slider contains images that run them using the previous and next icons. Previous and Next arrows are used to traverse back and forth on the mouse hover events on the images. The following example code is implemented in a simple and flexible way of showing the images one by one in the carousel by using HTML, CSS, and jQuery. We will accomplish the task in two sections first we will create the structure in HTML Design the structure in CSS and make it interactive by jQuery.
Creating Structure: In this section, we will create the structure of the image slider. 

HTML Code: HTML is used to create the structure of an image slider. 

html
<!DOCTYPE html> <html>  <head>     <title>         How to Design Image         Slider using jQuery ?     </title>      <meta name="viewport"            content="width=device-width, initial-scale=1">      <link rel="stylesheet"            href= "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> </head>  <body>     <center>         <h1 style="color:green">             GeeksforGeeks         </h1>          <b>             How to code Image             Slider using jQuery         </b>          <br><br>     </center>      <!-- Image container of the image slider -->     <div class="image-container">         <div class="slide">             <div class="slideNumber">1</div>             <img src= "https://www.geeksforgeeks.org/wp-content/uploads/html-768x256.png">         </div>         <div class="slide">             <div class="slideNumber">2</div>             <img src= "https://www.geeksforgeeks.org/wp-content/uploads/CSS-768x256.png">         </div>         <div class="slide">             <div class="slideNumber">3</div>             <img src= "https://www.geeksforgeeks.org/wp-content/uploads/jquery-banner.png">         </div>          <!-- Next and Previous icon to change images -->         <a class="previous" onclick="moveSlides(-1)">             <i class="fa fa-chevron-circle-left"></i>         </a>         <a class="next" onclick="moveSlides(1)">             <i class="fa fa-chevron-circle-right"></i>         </a>     </div>     <br>      <div style="text-align:center">         <span class="footerdot" onclick="activeSlide(1)">         </span>         <span class="footerdot" onclick="activeSlide(2)">         </span>         <span class="footerdot" onclick="activeSlide(3)">         </span>     </div> </body>  </html> 


Designing Structure: Here we will be done the designing part of the image slider by using CSS and make the slider interactive by using jQuery. 

CSS Code: Designing the structure on the basis of tags and classes of all the elements. 

CSS
img {     width: 100%; }  .height {     height: 10px; }  /* Image-container design */ .image-container {     max-width: 800px;     position: relative;     margin: auto; }  .next {     right: 0; }  /* Next and previous icon design */ .previous, .next {     cursor: pointer;     position: absolute;     top: 50%;     padding: 10px;     margin-top: -25px; }  /* caption decorate */ .captionText {     color: #000000;     font-size: 14px;     position: absolute;     padding: 12px 12px;     bottom: 8px;     width: 100%;     text-align: center; }  /* Slider image number */ .slideNumber {     background-color: #5574C5;     color: white;     border-radius: 25px;     right: 0;     opacity: .5;     margin: 5px;     width: 30px;     height: 30px;     text-align: center;     font-weight: bold;     font-size: 24px;     position: absolute; }  .fa {     font-size: 32px; }  .fa:hover {     transform: rotate(360deg);     transition: 1s;     color: white; }  .footerdot {     cursor: pointer;     height: 15px;     width: 15px;     margin: 0 2px;     background-color: #bbbbbb;     border-radius: 50%;     display: inline-block;     transition: background-color 0.5s ease; }  .active, .footerdot:hover {     background-color: black; } 

jQuery Code: jQuery is used to design the slider interactive. 

javascript
let slideIndex = 1; displaySlide(slideIndex);  function moveSlides(n) {     displaySlide(slideIndex += n); }  function activeSlide(n) {     displaySlide(slideIndex = n); }  /* Main function */ function displaySlide(n) {     let i;     let totalslides =         document.getElementsByClassName("slide");     let totaldots =         document.getElementsByClassName("footerdot");      if (n > totalslides.length) {         slideIndex = 1;     }      if (n < 1) {         slideIndex = totalslides.length;     }     for (i = 0; i < totalslides.length; i++) {         totalslides[i].style.display = "none";     }     for (i = 0; i < totaldots.length; i++) {         totaldots[i].className =             totaldots[i].className.replace(" active", "");     }     totalslides[slideIndex - 1].style.display = "block";     totaldots[slideIndex - 1].className += " active"; } 

Complete Solution: In this section, we will combine the above sections together that will be an Image Slider. 

html
<!DOCTYPE html> <html>  <head>     <title>         How to Design Image         Slider using jQuery ?     </title>      <meta name="viewport" content="width=device-width, initial-scale=1">      <link rel="stylesheet"            href= "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">      <style>         img {             width: 100%;         }          .height {             height: 10px;         }          /* Image-container design */         .image-container {             max-width: 800px;             position: relative;             margin: auto;         }          .next {             right: 0;         }          /* Next and previous icon design */         .previous,         .next {             cursor: pointer;             position: absolute;             top: 50%;             padding: 10px;             margin-top: -25px;         }          /* caption decorate */         .captionText {             color: #000000;             font-size: 14px;             position: absolute;             padding: 12px 12px;             bottom: 8px;             width: 100%;             text-align: center;         }          /* Slider image number */         .slideNumber {             background-color: #5574C5;             color: white;             border-radius: 25px;             right: 0;             opacity: .5;             margin: 5px;             width: 30px;             height: 30px;             text-align: center;             font-weight: bold;             font-size: 24px;             position: absolute;         }          .fa {             font-size: 32px;         }          .fa:hover {             transform: rotate(360deg);             transition: 1s;             color: white;         }          .footerdot {             cursor: pointer;             height: 15px;             width: 15px;             margin: 0 2px;             background-color: #bbbbbb;             border-radius: 50%;             display: inline-block;             transition: background-color 0.5s ease;         }          .active,         .footerdot:hover {             background-color: black;         }     </style> </head>  <body>     <center>         <h1 style="color:green">             GeeksforGeeks         </h1>          <b>             How to code Image             Slider using jQuery         </b>          <br><br>     </center>      <!-- Image container of the image slider -->     <div class="image-container">         <div class="slide">             <div class="slideNumber">1</div>             <img src= "https://www.geeksforgeeks.org/wp-content/uploads/html-768x256.png">         </div>         <div class="slide">             <div class="slideNumber">2</div>             <img src= "https://www.geeksforgeeks.org/wp-content/uploads/CSS-768x256.png">         </div>         <div class="slide">             <div class="slideNumber">3</div>             <img src= "https://www.geeksforgeeks.org/wp-content/uploads/jquery-banner.png">         </div>          <!-- Next and Previous icon to change images -->         <a class="previous" onclick="moveSlides(-1)">             <i class="fa fa-chevron-circle-left"></i>         </a>         <a class="next" onclick="moveSlides(1)">             <i class="fa fa-chevron-circle-right"></i>         </a>     </div>     <br>      <div style="text-align:center">         <span class="footerdot" onclick="activeSlide(1)">         </span>         <span class="footerdot" onclick="activeSlide(2)">         </span>         <span class="footerdot" onclick="activeSlide(3)">         </span>     </div>      <script>         let slideIndex = 1;         displaySlide(slideIndex);          function moveSlides(n) {             displaySlide(slideIndex += n);         }          function activeSlide(n) {             displaySlide(slideIndex = n);         }          /* Main function */         function displaySlide(n) {             let i;             let totalslides =                 document.getElementsByClassName("slide");              let totaldots =                 document.getElementsByClassName("footerdot");              if (n > totalslides.length) {                 slideIndex = 1;             }             if (n < 1) {                 slideIndex = totalslides.length;             }             for (i = 0; i < totalslides.length; i++) {                 totalslides[i].style.display = "none";             }             for (i = 0; i < totaldots.length; i++) {                 totaldots[i].className =                     totaldots[i].className.replace(" active", "");             }             totalslides[slideIndex - 1].style.display = "block";             totaldots[slideIndex - 1].className += " active";         }     </script> </body>  </html> 

Output: 


Next Article
How to Design Image Slider using jQuery ?

G

geetanjali16
Improve
Article Tags :
  • Web Technologies
  • JQuery
  • jQuery-Questions

Similar Reads

    How to Create a Custom Image Magnifier using jQuery ?
    Glimpse of Image magnifier: An image magnifier is the zooming capability of your cursor point. Where you placed your cursor in the define div the image will be popped out in zoom mode. Like in the shopping sites, when you want to purchase any kind of cloth and want to check the material or print on
    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
    How to create a Basic Slider using jQuery Mobile ?
    jQuery Mobile is a web based technology used to make responsive content that can be accessed on all smartphones, tablets and desktops. In this article, we will be creating a Basic Slider using jQuery Mobile. Approach: Add jQuery Mobile scripts needed for your project. <link rel=”stylesheet” href=
    1 min read
    jQuery UI Slider stop Event
    jQuery UI consists of GUI widgets, visual effects, and themes implemented using HTML, CSS, and jQuery. jQuery UI is great for building UI interfaces for the webpages. jQuery UI provides us a slider control through the slider widget. The slider widget helps us to get a certain value using a given ran
    2 min read
    How to compare two images using Image comparison slider?
    In this project, we are going to create an image slider with which we can check 2 images. If we are making an exact copy of them. We can compare every single boundary of the first image with the second image in both the vertical and horizontal directions.Approach:Create an HTML file in which we are
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences