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
  • BS5 Tutorial
  • BS5 Interview Questions
  • BS5 Layout
  • BS5 Content
  • BS5 Components
  • BS5 Helpers
  • BS5 Utilities
  • BS4 Tutorial
  • BS Tutorial
  • Bootstrap Cheatsheet
  • Tailwind
  • CSS Frameworks
  • HTML Formatter
Open In App
Next Article:
Bootstrap 5 Carousel With Indicators
Next article icon

Bootstrap 5 Carousel With Controls

Last Updated : 31 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Bootstrap 5 Carousel With controls means we can add controls to the Carousel for changing the slides of the carousel. 

Note: This can be achieved using HTML <button> as well as HTML <a> tag.

Bootstrap 5 Carousel With Controls Classes:

  • carousel-control-prev: This class is used for the carousel previous control.
  • carousel-control-next: This class is used for the carousel next control.
  • carousel-control-prev-icon: This class is used for the carousel previous icon image.
  • carousel-control-next-icon: This class is used for the carousel next icon image.

Syntax:

<button class="carousel-control-prev" type="button"
data-bs-target="#GFG" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true">
...
</span>
<span class="visually-hidden">...</span>
</button>

Example 1: In this example, we will learn about Carousel Controls using the HTML <button> tag.

HTML
<!DOCTYPE html> <html>  <head>     <!-- Bootstrap CDN -->     <link rel="stylesheet"           href= "https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/css/bootstrap.min.css"            integrity="sha384-r4NyP46KrjDleawBgD5tp8Y7UzmLA05oM1iAEQ17CSuDqnUK2+k9luXQOfXJCJ4I"            crossorigin="anonymous">     <script src= "https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/js/bootstrap.min.js"              integrity="sha384-oesi62hOLfzrys4LxRF63OJCXdXDipiYWBnvTl9Y9/TRlw5xlKIEHpNyvvDShgf/"             crossorigin="anonymous">     </script> </head>  <body class="m-2 text-center">     <div>         <h1 class="text-success">             GeeksforGeeks         </h1>         <h3>Bootstrap 5 Carousel With controls</h3>         <div id="GFG" class="carousel slide carousel-fade"               data-ride="carousel">              <!-- The slideshow -->             <div class="carousel-inner">                     <div class="carousel-item active">                         <img src= "https://media.geeksforgeeks.org/wp-content/cdn-uploads/Java.png"                               height="400px" width="400px"                               alt="Java" class="d-block w-100">                     </div>                     <div class="carousel-item">                         <img src= "https://media.geeksforgeeks.org/wp-content/cdn-uploads/20220401124017/HTML-Tutorial.png"                               height="400px" width="400px"                              alt="HTML" class="d-block w-100">                     </div>                     <div class="carousel-item">                         <img src= "https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210322182256/AngularJS-Tutorial.png"                               height="400px" width="400px"                               alt="Angular" class="d-block w-100">                     </div>                 <button class="carousel-control-prev" href="#GFG"                          data-slide="prev">                     <span class="carousel-control-prev-icon">                     </span>                 </button>                 <button class="carousel-control-next" href="#GFG" data-slide="next">                     <span class="carousel-control-next-icon">                     </span>                 </button>             </div>         </div>     </div> </body>  </html> 

Output:

Example 2: In this example, we will learn about Carousel Controls using an HTML <a> tag. We need to add role="button" in <a> tag.

HTML
<!DOCTYPE html> <html>  <head>     <!-- Bootstrap CDN -->     <link rel="stylesheet"           href= "https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/css/bootstrap.min.css"            integrity="sha384-r4NyP46KrjDleawBgD5tp8Y7UzmLA05oM1iAEQ17CSuDqnUK2+k9luXQOfXJCJ4I"            crossorigin="anonymous">     <script src= "https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/js/bootstrap.min.js"              integrity="sha384-oesi62hOLfzrys4LxRF63OJCXdXDipiYWBnvTl9Y9/TRlw5xlKIEHpNyvvDShgf/"             crossorigin="anonymous">     </script> </head>  <body class="m-2 text-center">     <div>         <h1 class="text-success">             GeeksforGeeks         </h1>         <h3>Bootstrap 5 Carousel With Controls</h3>         <div id="GFG" class="carousel slide carousel-fade"               data-ride="carousel">              <!-- The slideshow -->             <div class="carousel-inner">                     <div class="carousel-item active">                         <img src= "https://media.geeksforgeeks.org/wp-content/cdn-uploads/Java.png"                              height="400px" width="400px"                               alt="Java" class="d-block w-100">                     </div>                     <div class="carousel-item">                         <img src= "https://media.geeksforgeeks.org/wp-content/cdn-uploads/20220401124017/HTML-Tutorial.png"                               height="400px" width="400px"                               alt="HTML" class="d-block w-100">                     </div>                     <div class="carousel-item">                         <img src= "https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210322182256/AngularJS-Tutorial.png"                              height="400px" width="400px"                               alt="Angular" class="d-block w-100">                     </div>                 <a class="carousel-control-prev" href="#GFG"                     data-slide="prev" role="button">                     <span class="carousel-control-prev-icon">                     </span>                 </a>                 <a class="carousel-control-next" href="#GFG"                     data-slide="next" role="button">                     <span class="carousel-control-next-icon">                     </span>                 </a>             </div>         </div>     </div> </body>  </html> 

Output:

References: https://getbootstrap.com/docs/5.0/components/carousel/#with-controls


Next Article
Bootstrap 5 Carousel With Indicators
author
21mcsrltd
Improve
Article Tags :
  • Technical Scripter
  • Web Technologies
  • Bootstrap
  • Technical Scripter 2022

Similar Reads

    Bootstrap 5 Carousel Slides only
    Bootstrap 5 Carousel Slides only is a type of carousel where there is nothing in the slides of the carousel like the previous, next buttons, captions, and indicators. This carousel is the easiest one to implement as it has the least amount of components but this has the least user accessibility.Boot
    3 min read
    Bootstrap 5 Carousel With Controls
    Bootstrap 5 Carousel With controls means we can add controls to the Carousel for changing the slides of the carousel. Note: This can be achieved using HTML <button> as well as HTML <a> tag.Bootstrap 5 Carousel With Controls Classes:carousel-control-prev: This class is used for the carous
    2 min read
    Bootstrap 5 Carousel With Indicators
    Bootstrap 5 Carousel With indicators are used to create indicators in the carousel. We can click on these indicators, to change from one slide to another.Bootstrap 5 Carousel With Indicators Classes:carousel-indicators: This class is used for including carousel indicators in the HTML div container.S
    2 min read
    Bootstrap 5 Carousel With Captions
    Bootstrap 5 Carousel With captions means we can add a class carousel-caption to the carousel items to add a caption for them.Bootstrap 5 Carousel With Captions Class:carousel-caption: This class is used for giving carousel captions.Syntax<div class="carousel-caption"> ...</div>Example 1:
    2 min read
    Bootstrap 5 Carousel Crossfade
    Bootstrap 5 Carousel Crossfade is used to create a carousel animate slide show effect in Crossfade style. To make this effect, the .carousel-fade class is used.Carousel Crossfade used Class:.carousel-fade: This class is used to add the fade effect in the carousel slide animation.Syntax:<div id="G
    2 min read
    Bootstrap 5 Carousel Individual .carousel-item interval
    Bootstrap 5 Carousel Individual .carousel-item interval is used to give time intervals to individual carousel items by which the carousel items will be automatically cycled at the given intervals of time.Bootstrap 5 Carousel Classes:carousel-item: This class specifies each item of the carousel.Boots
    2 min read
    Bootstrap 5 Carousel Disable Touch Swiping
    Bootstrap5 Carousel Disable Touch Swiping can be used to disable the left/right swipe of the slides with touch on a touchscreen, by specifying the data-bs-touch attribute. Setting the data-bs-interval attribute as false will stop the autoplay of the slides.Disable touch swiping Class: There is no cl
    3 min read
    Bootstrap 5 Carousel Dark variant
    Bootstrap 5 Carousel Dark variant is by default, controls, indicators, and captions have white colors. But, for Darker controls, indicators, and captions, we can add a class carousel-dark to the carousel. Used class:carousel-dark: This class is used to include the dark variant for the carousel conta
    2 min read
    Bootstrap 5 Carousel Custom Transition
    Bootstrap 5 Carousel transition can be customized with the help of the SASS variables that help to set the duration of the transition. The transform transition will need to be defined first if multiple transitions are implemented. In other words, the transition can be set to a custom setting using t
    3 min read
    Bootstrap 5 Carousel SASS
    Bootstrap 5  Carousel SASS has a set of variables with default values that can be changed to customize the Carousel.Bootstrap 5 Carousel SassVariables: Carousel variables have a default value that can be customized to make a new Carousel layout.Default values of Carousel SASS variables$carousel-cont
    4 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