bootstrap
  1. bootstrap-carousel

Bootstrap Carousel

Bootstrap Carousel is a slideshow component that allows you to showcase a set of images or other content in a rotating carousel.

Syntax

To use Bootstrap Carousel, you first need to include the following code in the head section of your HTML file:

<div id="carouselExample" class="carousel slide">
  <div class="carousel-inner">
    <div class="carousel-item active">
      <img src="..." class="d-block w-100" alt="...">
    </div>
    <div class="carousel-item">
      <img src="..." class="d-block w-100" alt="...">
    </div>
    <div class="carousel-item">
      <img src="..." class="d-block w-100" alt="...">
    </div>
  </div>
  <button class="carousel-control-prev" type="button" data-bs-target="#carouselExample" data-bs-slide="prev">
    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
    <span class="visually-hidden">Previous</span>
  </button>
  <button class="carousel-control-next" type="button" data-bs-target="#carouselExample" data-bs-slide="next">
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="visually-hidden">Next</span>
  </button>
</div>

Example

Here is an example of how to create a simple Bootstrap Carousel.

<div id="carouselExampleIndicators" class="carousel slide">
  <div class="carousel-indicators">
    <button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
    <button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="1" aria-label="Slide 2"></button>
    <button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="2" aria-label="Slide 3"></button>
  </div>
  <div class="carousel-inner">
    <div class="carousel-item active">
      <img src="https://static.additionalsheet.com/images//others/hills.jpg" class="d-block w-100" alt="...">
    </div>
    <div class="carousel-item">
      <img src="https://static.additionalsheet.com/images//others/beach.jpg" class="d-block w-100" alt="...">
    </div>
    <div class="carousel-item">
      <img src="https://static.additionalsheet.com/images//others/clouds.jpg" class="d-block w-100" alt="...">
    </div>
  </div>
  <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="prev">
    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
    <span class="visually-hidden">Previous</span>
  </button>
  <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="next">
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="visually-hidden">Next</span>
  </button>
</div>
Try Playground

Autoplaying

Here’s a carousel with slides only.

<div id="carouselExampleIndicators" data-bs-ride="true" class="carousel slide">
    <div class="carousel-inner">
        <div class="carousel-item active">
            <img src="https://static.additionalsheet.com/images//others/hills.jpg" class="d-block w-100" alt="...">
        </div>
        <div class="carousel-item">
            <img src="https://static.additionalsheet.com/images//others/beach.jpg" class="d-block w-100" alt="...">
        </div>
        <div class="carousel-item">
            <img src="https://static.additionalsheet.com/images//others/clouds.jpg" class="d-block w-100" alt="...">
        </div>
    </div>
    <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleIndicators"
        data-bs-slide="prev">
        <span class="carousel-control-prev-icon" aria-hidden="true"></span>
        <span class="visually-hidden">Previous</span>
    </button>
    <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleIndicators"
        data-bs-slide="next">
        <span class="carousel-control-next-icon" aria-hidden="true"></span>
        <span class="visually-hidden">Next</span>
    </button>
</div>
Try Playground

Explanation

In the code above, we used the following classes to create the Carousel:

  • carousel: this is the main class that indicates that this is a Carousel.
  • carousel-slide: this class tells Bootstrap to slide the elements in the Carousel.
  • carousel-indicators: this is a list of the number of slides or pages in the Carousel.
  • carousel-inner: this is a container for the Carousel items.
  • carousel-item: this is a container for each slide in the Carousel.
  • active : this class tells Bootstrap to set the first slide as active to display on the page.
  • carousel-control-prev, carousel-control-next: these classes are used to display control arrows for navigating the Carousel.

Use

Bootstrap Carousel can be used to create a range of features like photo galleries, product sliders, and more. It provides bright, graceful, and easily functional tools that are visually pleasing and user-friendly.

Important Points

  • Bootstrap Carousel is a slideshow component used to showcase a set of images or other content in a rotating carousel.
  • Bootstrap Carousel is easy to use and has pre-built components that can be easily customized to suit your needs.
  • Bootstrap Carousel provides many customization options that can be used to create your desired results

Summary

Bootstrap Carousel is an excellent tool for presenting your content in a visually appealing manner. By using Bootstrap Carousel, you can save time and create beautiful, user-friendly rotating slides that help promote your brand and products.

Published on: