search results:

    • Standard
    • React
    Pricing Learn Community
    • + D
    • Light
    • Dark
    • System
    logo TW Elements
    • Getting started
      • Quick start
      • Tutorials
      • Design system
      • Local installation
      • Optimization
      • Dark mode
      • Theming
      • Changelog
      • Migrating to v2
      • Internationalization guide
      • Class customization
      • Icons Integration
    • CommercialNew
      • Pricing
      • License
      • Installation
      • Git & repository
      • Premium Support
    • Integrations
      • Angular
      • ASP.NET
      • Django
      • Express
      • Laravel
      • Next
      • Nuxt
      • Qwik
      • React
      • Remix
      • Solid
      • Svelte
      • SvelteKit
      • Vue
    • Content & styles
      • Animations
      • Animations Extended
      • Colors
      • Dividers
      • Figures
      • Headings
      • Hover effects
      • Icons
      • Images
      • Mask
      • Shadows
      • Typography
    • Navigation
      • Breadcrumbs
      • Footer
      • Headers
      • Mega menu
      • Navbar
      • Offcanvas
      • Pagination
      • Pills
      • Scrollspy
      • Sidenav
      • Tabs
    • Components
      • Accordion
      • Alerts
      • Avatar
      • Badges
      • Button group
      • Buttons
      • Cards
      • Carousel
      • Chips
      • Collapse
      • Dropdown
      • Gallery
      • Jumbotron
      • Lightbox
      • Link
      • List group
      • Modal
      • Notifications
      • Paragraphs
      • Placeholders
      • Popconfirm
      • Popover
      • Progress
      • Rating
      • Scroll back to top button
      • Social buttons
      • Spinners
      • Stepper
      • Testimonials
      • Timeline
      • Toast
      • Tooltip
      • Video
      • Video carousel
    • Forms
      • Autocomplete
      • Checkbox
      • Datepicker
      • Datetimepicker
      • File input
      • Form templates
      • Input Group
      • Inputs
      • Login form
      • Multi range slider
      • Radio
      • Range
      • Registration form
      • Search
      • Select
      • Switch
      • Textarea
      • Timepicker
      • Validation
    • Data
      • Charts
      • Charts advanced
      • Datatables
      • Tables
    • Methods
      • Clipboard
      • Infinite scroll
      • Lazy loading
      • Loading management
      • Ripple
      • Scrollbar
      • Smooth scroll
      • Sticky
      • Touch
    • Design Blocks
      • Admin Charts
      • Admin Complex
      • Admin Forms
      • Admin Maps
      • Admin Navigation
      • Admin tables
      • Banners
      • Contact
      • Content
      • CTA
      • FAQ
      • Features
      • Headers
      • Hero / Intro sections
      • Logo clouds
      • Mega menu
      • News
      • Newsletter
      • Pricing
      • Projects
      • Stats
      • Stats admin
      • Team
      • Testimonials
    • Tools
      • Button generator
      • Card generator
      • Flexbox generator
      • Footer generator
      • Form builder
      • Grid generator
      • Icon generator
      • Instagram Filters generator
      • Logo generator
      • Table generator
      • Typography generator
    • Coming Soon
      • Angular
      • Builder
      • Templates
      • Vue
    • Resources
      • Playground
      • YouTube Channel
      • Private FB Group
      • Newsletter
      • UI Design course New
      • UI / UX tips
    • Overview
    • API

    Carousel

    Tailwind CSS Carousel

    Use responsive carousel component with helper examples for image carousel, carousel slider, autoplay, indicators & more. Free download, open-source license.

    Required ES init: Carousel *
    * UMD autoinits are enabled by default. This means that you don't need to initialize the component manually. However if you are using TW Elements ES format then you should pass the required components to the initTWE method.

    Basic example

    Carousel Component is useful to navigate through a collection of images in a sequential fashion, moving to the previous/next one through the arrows on the sides.

    ...
    First slide label

    Some representative placeholder content for the first slide.

    ...
    Second slide label

    Some representative placeholder content for the second slide.

    ...
    Third slide label

    Some representative placeholder content for the third slide.

    • HTML
    • javascript
            
                
          <div
            id="carouselExampleCaptions"
            class="relative"
            data-twe-carousel-init
            data-twe-ride="carousel">
            <!--Carousel indicators-->
            <div
              class="absolute bottom-0 left-0 right-0 z-[2] mx-[15%] mb-4 flex list-none justify-center p-0"
              data-twe-carousel-indicators>
              <button
                type="button"
                data-twe-target="#carouselExampleCaptions"
                data-twe-slide-to="0"
                data-twe-carousel-active
                class="mx-[3px] box-content h-[3px] w-[30px] flex-initial cursor-pointer border-0 border-y-[10px] border-solid border-transparent bg-white bg-clip-padding p-0 -indent-[999px] opacity-50 transition-opacity duration-[600ms] ease-[cubic-bezier(0.25,0.1,0.25,1.0)] motion-reduce:transition-none"
                aria-current="true"
                aria-label="Slide 1"></button>
              <button
                type="button"
                data-twe-target="#carouselExampleCaptions"
                data-twe-slide-to="1"
                class="mx-[3px] box-content h-[3px] w-[30px] flex-initial cursor-pointer border-0 border-y-[10px] border-solid border-transparent bg-white bg-clip-padding p-0 -indent-[999px] opacity-50 transition-opacity duration-[600ms] ease-[cubic-bezier(0.25,0.1,0.25,1.0)] motion-reduce:transition-none"
                aria-label="Slide 2"></button>
              <button
                type="button"
                data-twe-target="#carouselExampleCaptions"
                data-twe-slide-to="2"
                class="mx-[3px] box-content h-[3px] w-[30px] flex-initial cursor-pointer border-0 border-y-[10px] border-solid border-transparent bg-white bg-clip-padding p-0 -indent-[999px] opacity-50 transition-opacity duration-[600ms] ease-[cubic-bezier(0.25,0.1,0.25,1.0)] motion-reduce:transition-none"
                aria-label="Slide 3"></button>
            </div>
    
            <!--Carousel items-->
            <div
              class="relative w-full overflow-hidden after:clear-both after:block after:content-['']">
              <!--First item-->
              <div
                class="relative float-left -mr-[100%] w-full transition-transform duration-[600ms] ease-in-out motion-reduce:transition-none"
                data-twe-carousel-active
                data-twe-carousel-item
                style="backface-visibility: hidden">
                <img
                  src="https://tecdn.b-cdn.net/img/Photos/Slides/img%20(15).jpg"
                  class="block w-full"
                  alt="..." />
                <div
                  class="absolute inset-x-[15%] bottom-5 hidden py-5 text-center text-white md:block">
                  <h5 class="text-xl">First slide label</h5>
                  <p>
                    Some representative placeholder content for the first slide.
                  </p>
                </div>
              </div>
              <!--Second item-->
              <div
                class="relative float-left -mr-[100%] hidden w-full transition-transform duration-[600ms] ease-in-out motion-reduce:transition-none"
                data-twe-carousel-item
                style="backface-visibility: hidden">
                <img
                  src="https://tecdn.b-cdn.net/img/Photos/Slides/img%20(22).jpg"
                  class="block w-full"
                  alt="..." />
                <div
                  class="absolute inset-x-[15%] bottom-5 hidden py-5 text-center text-white md:block">
                  <h5 class="text-xl">Second slide label</h5>
                  <p>
                    Some representative placeholder content for the second slide.
                  </p>
                </div>
              </div>
              <!--Third item-->
              <div
                class="relative float-left -mr-[100%] hidden w-full transition-transform duration-[600ms] ease-in-out motion-reduce:transition-none"
                data-twe-carousel-item
                style="backface-visibility: hidden">
                <img
                  src="https://tecdn.b-cdn.net/img/Photos/Slides/img%20(23).jpg"
                  class="block w-full"
                  alt="..." />
                <div
                  class="absolute inset-x-[15%] bottom-5 hidden py-5 text-center text-white md:block">
                  <h5 class="text-xl">Third slide label</h5>
                  <p>
                    Some representative placeholder content for the third slide.
                  </p>
                </div>
              </div>
            </div>
    
            <!--Carousel controls - prev item-->
            <button
              class="absolute bottom-0 left-0 top-0 z-[1] flex w-[15%] items-center justify-center border-0 bg-none p-0 text-center text-white opacity-50 transition-opacity duration-150 ease-[cubic-bezier(0.25,0.1,0.25,1.0)] hover:text-white hover:no-underline hover:opacity-90 hover:outline-none focus:text-white focus:no-underline focus:opacity-90 focus:outline-none motion-reduce:transition-none"
              type="button"
              data-twe-target="#carouselExampleCaptions"
              data-twe-slide="prev">
              <span class="inline-block h-8 w-8">
                <svg
                  xmlns="http://www.w3.org/2000/svg"
                  fill="none"
                  viewBox="0 0 24 24"
                  stroke-width="1.5"
                  stroke="currentColor"
                  class="h-6 w-6">
                  <path
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    d="M15.75 19.5L8.25 12l7.5-7.5" />
                </svg>
              </span>
              <span
                class="!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]"
                >Previous</span
              >
            </button>
            <!--Carousel controls - next item-->
            <button
              class="absolute bottom-0 right-0 top-0 z-[1] flex w-[15%] items-center justify-center border-0 bg-none p-0 text-center text-white opacity-50 transition-opacity duration-150 ease-[cubic-bezier(0.25,0.1,0.25,1.0)] hover:text-white hover:no-underline hover:opacity-90 hover:outline-none focus:text-white focus:no-underline focus:opacity-90 focus:outline-none motion-reduce:transition-none"
              type="button"
              data-twe-target="#carouselExampleCaptions"
              data-twe-slide="next">
              <span class="inline-block h-8 w-8">
                <svg
                  xmlns="http://www.w3.org/2000/svg"
                  fill="none"
                  viewBox="0 0 24 24"
                  stroke-width="1.5"
                  stroke="currentColor"
                  class="h-6 w-6">
                  <path
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    d="M8.25 4.5l7.5 7.5-7.5 7.5" />
                </svg>
              </span>
              <span
                class="!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]"
                >Next</span
              >
            </button>
          </div>
          
            
        
            
                
          // Initialization for ES Users
          import {
            Carousel,
            initTWE,
          } from "tw-elements";
          
          initTWE({ Carousel });
          
            
        

    Hey there 👋 we're excited about TW elements and want to see it grow! If you enjoy it, help the project grow by sharing it with your peers. Every share counts, thank you!

    Slides only

    Carousel slides only allows you to automatically and smoothly switch between gallery images without controls. It is a useful component for dynamic design where user involvement is important.

    Wild Landscape
    Camera
    Exotic Fruits
    • HTML
    • javascript
            
                
          <div
            id="carouselExampleSlidesOnly"
            class="relative"
            data-twe-carousel-init
            data-twe-ride="carousel">
            <!--Carousel items-->
            <div
              class="relative w-full overflow-hidden after:clear-both after:block after:content-['']">
              <!--First item-->
              <div
                class="relative float-left -mr-[100%] w-full transition-transform duration-[600ms] ease-in-out motion-reduce:transition-none"
                data-twe-carousel-item
                data-twe-carousel-active>
                <img
                  src="https://mdbcdn.b-cdn.net/img/new/slides/041.webp"
                  class="block w-full"
                  alt="Wild Landscape" />
              </div>
              <!--Second item-->
              <div
                class="relative float-left -mr-[100%] hidden w-full transition-transform duration-[600ms] ease-in-out motion-reduce:transition-none"
                data-twe-carousel-item>
                <img
                  src="https://mdbcdn.b-cdn.net/img/new/slides/042.webp"
                  class="block w-full"
                  alt="Camera" />
              </div>
              <!--Third item-->
              <div
                class="relative float-left -mr-[100%] hidden w-full transition-transform duration-[600ms] ease-in-out motion-reduce:transition-none"
                data-twe-carousel-item>
                <img
                  src="https://mdbcdn.b-cdn.net/img/new/slides/043.webp"
                  class="block w-full"
                  alt="Exotic Fruits" />
              </div>
            </div>
          </div>
          
            
        
            
                
          // Initialization for ES Users
          import {
            Carousel,
            initTWE,
          } from "tw-elements";
          
          initTWE({ Carousel });
          
            
        

    With controls

    Previous and next controls allow you to control automatically moving gallery items.

    Wild Landscape
    Camera
    Exotic Fruits
    • HTML
    • javascript
            
                
          <div
            id="carouselExampleControls"
            class="relative"
            data-twe-carousel-init
            data-twe-ride="carousel">
            <!--Carousel items-->
            <div
              class="relative w-full overflow-hidden after:clear-both after:block after:content-['']">
              <!--First item-->
              <div
                class="relative float-left -mr-[100%] w-full transition-transform duration-[600ms] ease-in-out motion-reduce:transition-none"
                data-twe-carousel-item
                data-twe-carousel-active>
                <img
                  src="https://mdbcdn.b-cdn.net/img/new/slides/041.webp"
                  class="block w-full"
                  alt="Wild Landscape" />
              </div>
              <!--Second item-->
              <div
                class="relative float-left -mr-[100%] hidden w-full transition-transform duration-[600ms] ease-in-out motion-reduce:transition-none"
                data-twe-carousel-item>
                <img
                  src="https://mdbcdn.b-cdn.net/img/new/slides/042.webp"
                  class="block w-full"
                  alt="Camera" />
              </div>
              <!--Third item-->
              <div
                class="relative float-left -mr-[100%] hidden w-full transition-transform duration-[600ms] ease-in-out motion-reduce:transition-none"
                data-twe-carousel-item>
                <img
                  src="https://mdbcdn.b-cdn.net/img/new/slides/043.webp"
                  class="block w-full"
                  alt="Exotic Fruits" />
              </div>
            </div>
    
            <!--Carousel controls - prev item-->
            <button
              class="absolute bottom-0 left-0 top-0 z-[1] flex w-[15%] items-center justify-center border-0 bg-none p-0 text-center text-white opacity-50 transition-opacity duration-150 ease-[cubic-bezier(0.25,0.1,0.25,1.0)] hover:text-white hover:no-underline hover:opacity-90 hover:outline-none focus:text-white focus:no-underline focus:opacity-90 focus:outline-none motion-reduce:transition-none"
              type="button"
              data-twe-target="#carouselExampleControls"
              data-twe-slide="prev">
              <span class="inline-block h-8 w-8">
                <svg
                  xmlns="http://www.w3.org/2000/svg"
                  fill="none"
                  viewBox="0 0 24 24"
                  stroke-width="1.5"
                  stroke="currentColor"
                  class="h-6 w-6">
                  <path
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    d="M15.75 19.5L8.25 12l7.5-7.5" />
                </svg>
              </span>
              <span
                class="!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]"
                >Previous</span
              >
            </button>
            <!--Carousel controls - next item-->
            <button
              class="absolute bottom-0 right-0 top-0 z-[1] flex w-[15%] items-center justify-center border-0 bg-none p-0 text-center text-white opacity-50 transition-opacity duration-150 ease-[cubic-bezier(0.25,0.1,0.25,1.0)] hover:text-white hover:no-underline hover:opacity-90 hover:outline-none focus:text-white focus:no-underline focus:opacity-90 focus:outline-none motion-reduce:transition-none"
              type="button"
              data-twe-target="#carouselExampleControls"
              data-twe-slide="next">
              <span class="inline-block h-8 w-8">
                <svg
                  xmlns="http://www.w3.org/2000/svg"
                  fill="none"
                  viewBox="0 0 24 24"
                  stroke-width="1.5"
                  stroke="currentColor"
                  class="h-6 w-6">
                  <path
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    d="M8.25 4.5l7.5 7.5-7.5 7.5" />
                </svg>
              </span>
              <span
                class="!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]"
                >Next</span
              >
            </button>
          </div>
          
            
        
            
                
          // Initialization for ES Users
          import {
            Carousel,
            initTWE,
          } from "tw-elements";
          
          initTWE({ Carousel });
          
            
        

    With indicators

    Adding indicators to the carousel, alongside the controls, can make it easier to navigate between the available images.

    Wild Landscape
    Camera
    Exotic Fruits
    • HTML
    • javascript
            
                
          <div
            id="carouselExampleIndicators"
            class="relative"
            data-twe-carousel-init
            data-twe-ride="carousel">
            <!--Carousel indicators-->
            <div
              class="absolute bottom-0 left-0 right-0 z-[2] mx-[15%] mb-4 flex list-none justify-center p-0"
              data-twe-carousel-indicators>
              <button
                type="button"
                data-twe-target="#carouselExampleIndicators"
                data-twe-slide-to="0"
                data-twe-carousel-active
                class="mx-[3px] box-content h-[3px] w-[30px] flex-initial cursor-pointer border-0 border-y-[10px] border-solid border-transparent bg-white bg-clip-padding p-0 -indent-[999px] opacity-50 transition-opacity duration-[600ms] ease-[cubic-bezier(0.25,0.1,0.25,1.0)] motion-reduce:transition-none"
                aria-current="true"
                aria-label="Slide 1"></button>
              <button
                type="button"
                data-twe-target="#carouselExampleIndicators"
                data-twe-slide-to="1"
                class="mx-[3px] box-content h-[3px] w-[30px] flex-initial cursor-pointer border-0 border-y-[10px] border-solid border-transparent bg-white bg-clip-padding p-0 -indent-[999px] opacity-50 transition-opacity duration-[600ms] ease-[cubic-bezier(0.25,0.1,0.25,1.0)] motion-reduce:transition-none"
                aria-label="Slide 2"></button>
              <button
                type="button"
                data-twe-target="#carouselExampleIndicators"
                data-twe-slide-to="2"
                class="mx-[3px] box-content h-[3px] w-[30px] flex-initial cursor-pointer border-0 border-y-[10px] border-solid border-transparent bg-white bg-clip-padding p-0 -indent-[999px] opacity-50 transition-opacity duration-[600ms] ease-[cubic-bezier(0.25,0.1,0.25,1.0)] motion-reduce:transition-none"
                aria-label="Slide 3"></button>
            </div>
    
            <!--Carousel items-->
            <div
              class="relative w-full overflow-hidden after:clear-both after:block after:content-['']">
              <!--First item-->
              <div
                class="relative float-left -mr-[100%] w-full transition-transform duration-[600ms] ease-in-out motion-reduce:transition-none"
                data-twe-carousel-item
                data-twe-carousel-active>
                <img
                  src="https://mdbcdn.b-cdn.net/img/new/slides/041.webp"
                  class="block w-full"
                  alt="Wild Landscape" />
              </div>
              <!--Second item-->
              <div
                class="relative float-left -mr-[100%] hidden w-full transition-transform duration-[600ms] ease-in-out motion-reduce:transition-none"
                data-twe-carousel-item>
                <img
                  src="https://mdbcdn.b-cdn.net/img/new/slides/042.webp"
                  class="block w-full"
                  alt="Camera" />
              </div>
              <!--Third item-->
              <div
                class="relative float-left -mr-[100%] hidden w-full transition-transform duration-[600ms] ease-in-out motion-reduce:transition-none"
                data-twe-carousel-item>
                <img
                  src="https://mdbcdn.b-cdn.net/img/new/slides/043.webp"
                  class="block w-full"
                  alt="Exotic Fruits" />
              </div>
            </div>
    
            <!--Carousel controls - prev item-->
            <button
              class="absolute bottom-0 left-0 top-0 z-[1] flex w-[15%] items-center justify-center border-0 bg-none p-0 text-center text-white opacity-50 transition-opacity duration-150 ease-[cubic-bezier(0.25,0.1,0.25,1.0)] hover:text-white hover:no-underline hover:opacity-90 hover:outline-none focus:text-white focus:no-underline focus:opacity-90 focus:outline-none motion-reduce:transition-none"
              type="button"
              data-twe-target="#carouselExampleIndicators"
              data-twe-slide="prev">
              <span class="inline-block h-8 w-8">
                <svg
                  xmlns="http://www.w3.org/2000/svg"
                  fill="none"
                  viewBox="0 0 24 24"
                  stroke-width="1.5"
                  stroke="currentColor"
                  class="h-6 w-6">
                  <path
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    d="M15.75 19.5L8.25 12l7.5-7.5" />
                </svg>
              </span>
              <span
                class="!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]"
                >Previous</span
              >
            </button>
            <!--Carousel controls - next item-->
            <button
              class="absolute bottom-0 right-0 top-0 z-[1] flex w-[15%] items-center justify-center border-0 bg-none p-0 text-center text-white opacity-50 transition-opacity duration-150 ease-[cubic-bezier(0.25,0.1,0.25,1.0)] hover:text-white hover:no-underline hover:opacity-90 hover:outline-none focus:text-white focus:no-underline focus:opacity-90 focus:outline-none motion-reduce:transition-none"
              type="button"
              data-twe-target="#carouselExampleIndicators"
              data-twe-slide="next">
              <span class="inline-block h-8 w-8">
                <svg
                  xmlns="http://www.w3.org/2000/svg"
                  fill="none"
                  viewBox="0 0 24 24"
                  stroke-width="1.5"
                  stroke="currentColor"
                  class="h-6 w-6">
                  <path
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    d="M8.25 4.5l7.5 7.5-7.5 7.5" />
                </svg>
              </span>
              <span
                class="!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]"
                >Next</span
              >
            </button>
          </div>
          
            
        
            
                
          // Initialization for ES Users
          import {
            Carousel,
            initTWE,
          } from "tw-elements";
          
          initTWE({ Carousel });
          
            
        

    Crossfade

    Use fade transition on your slides easily by adding the [data-twe-carousel-fade] attribute to [data-twe-carousel-item].

    Wild Landscape
    Camera
    Exotic Fruits
    • HTML
    • javascript
            
                
          <div
            id="carouselExampleCrossfade"
            class="relative"
            data-twe-carousel-init
            data-twe-ride="carousel">
            <!--Carousel indicators-->
            <div
              class="absolute inset-x-0 bottom-0 z-[2] mx-[15%] mb-4 flex list-none justify-center p-0"
              data-twe-carousel-indicators>
              <button
                type="button"
                data-twe-target="#carouselExampleCrossfade"
                data-twe-slide-to="0"
                data-twe-carousel-active
                class="mx-[3px] box-content h-[3px] w-[30px] flex-initial cursor-pointer border-0 border-y-[10px] border-solid border-transparent bg-white bg-clip-padding p-0 -indent-[999px] opacity-50 transition-opacity duration-[600ms] ease-[cubic-bezier(0.25,0.1,0.25,1.0)] motion-reduce:transition-none"
                aria-current="true"
                aria-label="Slide 1"></button>
              <button
                type="button"
                data-twe-target="#carouselExampleCrossfade"
                data-twe-slide-to="1"
                class="mx-[3px] box-content h-[3px] w-[30px] flex-initial cursor-pointer border-0 border-y-[10px] border-solid border-transparent bg-white bg-clip-padding p-0 -indent-[999px] opacity-50 transition-opacity duration-[600ms] ease-[cubic-bezier(0.25,0.1,0.25,1.0)] motion-reduce:transition-none"
                aria-label="Slide 2"></button>
              <button
                type="button"
                data-twe-target="#carouselExampleCrossfade"
                data-twe-slide-to="2"
                class="mx-[3px] box-content h-[3px] w-[30px] flex-initial cursor-pointer border-0 border-y-[10px] border-solid border-transparent bg-white bg-clip-padding p-0 -indent-[999px] opacity-50 transition-opacity duration-[600ms] ease-[cubic-bezier(0.25,0.1,0.25,1.0)] motion-reduce:transition-none"
                aria-label="Slide 3"></button>
            </div>
    
            <!--Carousel items-->
            <div
              class="relative w-full overflow-hidden after:clear-both after:block after:content-['']">
              <!--First item-->
              <div
                class="relative float-left -mr-[100%] w-full !transform-none opacity-0 transition-opacity duration-[600ms] ease-in-out motion-reduce:transition-none"
                data-twe-carousel-fade
                data-twe-carousel-item
                data-twe-carousel-active>
                <img
                  src="https://mdbcdn.b-cdn.net/img/new/slides/041.webp"
                  class="block w-full"
                  alt="Wild Landscape" />
              </div>
              <!--Second item-->
              <div
                class="relative float-left -mr-[100%] hidden w-full !transform-none opacity-0 transition-opacity duration-[600ms] ease-in-out motion-reduce:transition-none"
                data-twe-carousel-fade
                data-twe-carousel-item>
                <img
                  src="https://mdbcdn.b-cdn.net/img/new/slides/042.webp"
                  class="block w-full"
                  alt="Camera" />
              </div>
              <!--Third item-->
              <div
                class="relative float-left -mr-[100%] hidden w-full !transform-none opacity-0 transition-opacity duration-[600ms] ease-in-out motion-reduce:transition-none"
                data-twe-carousel-fade
                data-twe-carousel-item>
                <img
                  src="https://mdbcdn.b-cdn.net/img/new/slides/043.webp"
                  class="block w-full"
                  alt="Exotic Fruits" />
              </div>
            </div>
    
            <!--Carousel controls - prev item-->
            <button
              class="absolute bottom-0 left-0 top-0 z-[1] flex w-[15%] items-center justify-center border-0 bg-none p-0 text-center text-white opacity-50 transition-opacity duration-150 ease-[cubic-bezier(0.25,0.1,0.25,1.0)] hover:text-white hover:no-underline hover:opacity-90 hover:outline-none focus:text-white focus:no-underline focus:opacity-90 focus:outline-none motion-reduce:transition-none"
              type="button"
              data-twe-target="#carouselExampleCrossfade"
              data-twe-slide="prev">
              <span class="inline-block h-8 w-8">
                <svg
                  xmlns="http://www.w3.org/2000/svg"
                  fill="none"
                  viewBox="0 0 24 24"
                  stroke-width="1.5"
                  stroke="currentColor"
                  class="h-6 w-6">
                  <path
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    d="M15.75 19.5L8.25 12l7.5-7.5" />
                </svg>
              </span>
              <span
                class="!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]"
                >Previous</span
              >
            </button>
            <!--Carousel controls - next item-->
            <button
              class="absolute bottom-0 right-0 top-0 z-[1] flex w-[15%] items-center justify-center border-0 bg-none p-0 text-center text-white opacity-50 transition-opacity duration-150 ease-[cubic-bezier(0.25,0.1,0.25,1.0)] hover:text-white hover:no-underline hover:opacity-90 hover:outline-none focus:text-white focus:no-underline focus:opacity-90 focus:outline-none motion-reduce:transition-none"
              type="button"
              data-twe-target="#carouselExampleCrossfade"
              data-twe-slide="next">
              <span class="inline-block h-8 w-8">
                <svg
                  xmlns="http://www.w3.org/2000/svg"
                  fill="none"
                  viewBox="0 0 24 24"
                  stroke-width="1.5"
                  stroke="currentColor"
                  class="h-6 w-6">
                  <path
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    d="M8.25 4.5l7.5 7.5-7.5 7.5" />
                </svg>
              </span>
              <span
                class="!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]"
                >Next</span
              >
            </button>
          </div>
          
            
        
            
                
          // Initialization for ES Users
          import {
            Carousel,
            initTWE,
          } from "tw-elements";
          
          initTWE({ Carousel });
          
            
        

    Dark variant

    If your carousel photo gallery only contains bright images, to make controls, indicators, and captions have more contrast, modify their classes as in the example below.

    Motorbike Smoke
    First slide label

    Some representative placeholder content for the first slide.

    Mountaintop
    Second slide label

    Some representative placeholder content for the second slide.

    Woman Reading a Book
    Third slide label

    Some representative placeholder content for the third slide.

    • HTML
    • javascript
            
                
          <div
            id="carouselDarkVariant"
            class="relative"
            data-twe-carousel-init
            data-twe-ride="carousel">
            <!-- Carousel indicators -->
            <div
              class="absolute inset-x-0 bottom-0 z-[2] mx-[15%] mb-4 flex list-none justify-center p-0"
              data-twe-carousel-indicators>
              <button
                data-twe-target="#carouselDarkVariant"
                data-twe-slide-to="0"
                data-twe-carousel-active
                class="mx-[3px] box-content h-[3px] w-[30px] flex-initial cursor-pointer border-0 border-y-[10px] border-solid border-transparent bg-black bg-clip-padding p-0 -indent-[999px] opacity-50 transition-opacity duration-[600ms] ease-[cubic-bezier(0.25,0.1,0.25,1.0)] motion-reduce:transition-none"
                aria-current="true"
                aria-label="Slide 1"></button>
              <button
                data-twe-target="#carouselDarkVariant"
                class="mx-[3px] box-content h-[3px] w-[30px] flex-initial cursor-pointer border-0 border-y-[10px] border-solid border-transparent bg-black bg-clip-padding p-0 -indent-[999px] opacity-50 transition-opacity duration-[600ms] ease-[cubic-bezier(0.25,0.1,0.25,1.0)] motion-reduce:transition-none"
                data-twe-slide-to="1"
                aria-label="Slide 1"></button>
              <button
                data-twe-target="#carouselDarkVariant"
                class="mx-[3px] box-content h-[3px] w-[30px] flex-initial cursor-pointer border-0 border-y-[10px] border-solid border-transparent bg-black bg-clip-padding p-0 -indent-[999px] opacity-50 transition-opacity duration-[600ms] ease-[cubic-bezier(0.25,0.1,0.25,1.0)] motion-reduce:transition-none"
                data-twe-slide-to="2"
                aria-label="Slide 1"></button>
            </div>
    
            <!-- Carousel items -->
            <div
              class="relative w-full overflow-hidden after:clear-both after:block after:content-['']">
              <!-- First item -->
              <div
                class="relative float-left -mr-[100%] w-full !transform-none opacity-0 transition-opacity duration-[600ms] ease-in-out motion-reduce:transition-none"
                data-twe-carousel-fade
                data-twe-carousel-item
                data-twe-carousel-active>
                <img
                  src="https://mdbcdn.b-cdn.net/img/Photos/Slides/img%20(19).webp"
                  class="block w-full"
                  alt="Motorbike Smoke" />
                <div
                  class="absolute inset-x-[15%] bottom-5 hidden py-5 text-center text-black md:block">
                  <h5 class="text-xl">First slide label</h5>
                  <p>
                    Some representative placeholder content for the first slide.
                  </p>
                </div>
              </div>
              <!-- Second item -->
              <div
                class="relative float-left -mr-[100%] hidden w-full !transform-none opacity-0 transition-opacity duration-[600ms] ease-in-out motion-reduce:transition-none"
                data-twe-carousel-fade
                data-twe-carousel-item>
                <img
                  src="https://mdbcdn.b-cdn.net/img/Photos/Slides/img%20(35).webp"
                  class="block w-full"
                  alt="Mountaintop" />
                <div
                  class="absolute inset-x-[15%] bottom-5 hidden py-5 text-center text-black md:block">
                  <h5 class="text-xl">Second slide label</h5>
                  <p>
                    Some representative placeholder content for the second slide.
                  </p>
                </div>
              </div>
              <!-- Third item -->
              <div
                class="relative float-left -mr-[100%] hidden w-full !transform-none opacity-0 transition-opacity duration-[600ms] ease-in-out motion-reduce:transition-none"
                data-twe-carousel-fade
                data-twe-carousel-item>
                <img
                  src="https://mdbcdn.b-cdn.net/img/Photos/Slides/img%20(40).webp"
                  class="block w-full"
                  alt="Woman Reading a Book" />
                <div
                  class="absolute inset-x-[15%] bottom-5 hidden py-5 text-center text-black md:block">
                  <h5 class="text-xl">Third slide label</h5>
                  <p>
                    Some representative placeholder content for the third slide.
                  </p>
                </div>
              </div>
            </div>
    
            <!-- Carousel controls - prev item-->
            <button
              class="absolute bottom-0 left-0 top-0 z-[1] flex w-[15%] items-center justify-center border-0 bg-none p-0 text-center text-black opacity-50 transition-opacity duration-150 ease-[cubic-bezier(0.25,0.1,0.25,1.0)] hover:text-black hover:no-underline hover:opacity-90 hover:outline-none focus:text-black focus:no-underline focus:opacity-90 focus:outline-none motion-reduce:transition-none"
              type="button"
              data-twe-target="#carouselDarkVariant"
              data-twe-slide="prev">
              <span class="inline-block h-8 w-8 dark:grayscale">
                <svg
                  xmlns="http://www.w3.org/2000/svg"
                  fill="none"
                  viewBox="0 0 24 24"
                  stroke-width="1.5"
                  stroke="currentColor"
                  class="h-6 w-6">
                  <path
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    d="M15.75 19.5L8.25 12l7.5-7.5" />
                </svg>
              </span>
              <span
                class="!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]"
                >Previous</span
              >
            </button>
            <!-- Carousel controls - next item-->
            <button
              class="absolute bottom-0 right-0 top-0 z-[1] flex w-[15%] items-center justify-center border-0 bg-none p-0 text-center text-black opacity-50 transition-opacity duration-150 ease-[cubic-bezier(0.25,0.1,0.25,1.0)] hover:text-black hover:no-underline hover:opacity-90 hover:outline-none focus:text-black focus:no-underline focus:opacity-90 focus:outline-none motion-reduce:transition-none"
              type="button"
              data-twe-target="#carouselDarkVariant"
              data-twe-slide="next">
              <span class="inline-block h-8 w-8 dark:grayscale">
                <svg
                  xmlns="http://www.w3.org/2000/svg"
                  fill="none"
                  viewBox="0 0 24 24"
                  stroke-width="1.5"
                  stroke="currentColor"
                  class="h-6 w-6">
                  <path
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    d="M8.25 4.5l7.5 7.5-7.5 7.5" />
                </svg>
              </span>
              <span
                class="!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]"
                >Next</span
              >
            </button>
          </div>
          
            
        
            
                
          // Initialization for ES Users
          import {
            Carousel,
            initTWE,
          } from "tw-elements";
          
          initTWE({ Carousel });
          
            
        

    Related resources

    Tutorials:

    fullscreen background image dark theme arbitrary values flexbox text spacing masks buttons ripple effect carousel rounded corners sizing

    Extended Docs:

    animations headings images mask shadows typography headers avatar button group buttons gallery jumbotron rating testimonials video video carousel background image background position box sizing parallax spacing text bold text color text size

    Generators and builders:

    Form drag & drop Typography SVG icon Instagram Filters button card table flexbox logo grid footer

    Design System (Figma):

    introduction size matters let it breathe user experience do not start with the roof primary questions secondary questions project personality design system plan the process principles tips and tricks
    • Basic example
    • Slides only
    • With controls
    • With indicators
    • Crossfade
    • Dark variant
    • Related resources

    Carousel - API


    Import

    Importing components depends on how your application works. If you intend to use the TW elements ES format, you must first import the component and then initialize it with the initTWE method. If you are going to use the UMD format, just import the tw-elements package.

    • javascript
    • umd
            
                
            import { Carousel, initTWE } from "tw-elements";
            initTWE({ Carousel });
            
            
        
            
                
            import "tw-elements";
            
            
        

    Usage

    Via data attributes

    Use data attributes to easily control the position of the carousel. data-twe-slide accepts the keywords prev or next, which alters the slide position relative to its current position. Alternatively, use data-twe-slide-to to pass a raw slide index to the carousel data-twe-slide-to="2", which shifts the slide position to a particular index beginning with 0.

    The data-twe-carousel-init and data-twe-ride="carousel" attributes are used to mark a carousel as animating starting at page load. If you don’t use these attributes to initialize your carousel, you have to initialize it yourself. It cannot be used in combination with (redundant and unnecessary) explicit JavaScript initialization of the same carousel.

    • HTML
            
                
            <div
              id="carouselExampleCaptions"
              class="relative"
              data-twe-carousel-init
              data-twe-carousel-slide>
              <div
                class="absolute bottom-0 left-0 right-0 z-[2] mx-[15%] mb-4 flex list-none justify-center p-0"
                data-twe-carousel-indicators>
                <button
                  type="button"
                  data-twe-target="#carouselExampleCaptions"
                  data-twe-slide-to="0"
                  data-twe-carousel-active
                  class="mx-[3px] box-content h-[3px] w-[30px] flex-initial cursor-pointer border-0 border-y-[10px] border-solid border-transparent bg-white bg-clip-padding p-0 -indent-[999px] opacity-50 transition-opacity duration-[600ms] ease-[cubic-bezier(0.25,0.1,0.25,1.0)] motion-reduce:transition-none"
                  aria-current="true"
                  aria-label="Slide 1"></button>
                <button
                  type="button"
                  data-twe-target="#carouselExampleCaptions"
                  data-twe-slide-to="1"
                  class="mx-[3px] box-content h-[3px] w-[30px] flex-initial cursor-pointer border-0 border-y-[10px] border-solid border-transparent bg-white bg-clip-padding p-0 -indent-[999px] opacity-50 transition-opacity duration-[600ms] ease-[cubic-bezier(0.25,0.1,0.25,1.0)] motion-reduce:transition-none"
                  aria-label="Slide 2"></button>
                <button
                  type="button"
                  data-twe-target="#carouselExampleCaptions"
                  data-twe-slide-to="2"
                  class="mx-[3px] box-content h-[3px] w-[30px] flex-initial cursor-pointer border-0 border-y-[10px] border-solid border-transparent bg-white bg-clip-padding p-0 -indent-[999px] opacity-50 transition-opacity duration-[600ms] ease-[cubic-bezier(0.25,0.1,0.25,1.0)] motion-reduce:transition-none"
                  aria-label="Slide 3"></button>
              </div>
              <div
                class="relative w-full overflow-hidden after:clear-both after:block after:content-['']">
                <div
                  class="relative float-left -mr-[100%] w-full transition-transform duration-[600ms] ease-in-out motion-reduce:transition-none"
                  data-twe-carousel-active
                  data-twe-carousel-item
                  style="backface-visibility: hidden">
                  <img
                    src="https://tecdn.b-cdn.net/img/Photos/Slides/img%20(15).jpg"
                    class="block w-full"
                    alt="..." />
                  <div
                    class="absolute inset-x-[15%] bottom-5 hidden py-5 text-center text-white md:block">
                    <h5 class="text-xl">First slide label</h5>
                    <p>
                      Some representative placeholder content for the first slide.
                    </p>
                  </div>
                </div>
                <div
                  class="relative float-left -mr-[100%] hidden w-full transition-transform duration-[600ms] ease-in-out motion-reduce:transition-none"
                  data-twe-carousel-item
                  style="backface-visibility: hidden">
                  <img
                    src="https://tecdn.b-cdn.net/img/Photos/Slides/img%20(22).jpg"
                    class="block w-full"
                    alt="..." />
                  <div
                    class="absolute inset-x-[15%] bottom-5 hidden py-5 text-center text-white md:block">
                    <h5 class="text-xl">Second slide label</h5>
                    <p>
                      Some representative placeholder content for the second slide.
                    </p>
                  </div>
                </div>
                <div
                  class="relative float-left -mr-[100%] hidden w-full transition-transform duration-[600ms] ease-in-out motion-reduce:transition-none"
                  data-twe-carousel-item
                  style="backface-visibility: hidden">
                  <img
                    src="https://tecdn.b-cdn.net/img/Photos/Slides/img%20(23).jpg"
                    class="block w-full"
                    alt="..." />
                  <div
                    class="absolute inset-x-[15%] bottom-5 hidden py-5 text-center text-white md:block">
                    <h5 class="text-xl">Third slide label</h5>
                    <p>
                      Some representative placeholder content for the third slide.
                    </p>
                  </div>
                </div>
              </div>
              <button
                class="absolute bottom-0 left-0 top-0 z-[1] flex w-[15%] items-center justify-center border-0 bg-none p-0 text-center text-white opacity-50 transition-opacity duration-150 ease-[cubic-bezier(0.25,0.1,0.25,1.0)] hover:text-white hover:no-underline hover:opacity-90 hover:outline-none focus:text-white focus:no-underline focus:opacity-90 focus:outline-none motion-reduce:transition-none"
                type="button"
                data-twe-target="#carouselExampleCaptions"
                data-twe-slide="prev">
                <span class="inline-block h-8 w-8">
                  <svg
                    aria-hidden="true"
                    xmlns="http://www.w3.org/2000/svg"
                    viewBox="0 0 16 16"
                    fill="#fff">
                    <path
                      d="M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0z" />
                  </svg>
                </span>
                <span
                  class="!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]"
                  >Previous</span
                >
              </button>
              <button
                class="absolute bottom-0 right-0 top-0 z-[1] flex w-[15%] items-center justify-center border-0 bg-none p-0 text-center text-white opacity-50 transition-opacity duration-150 ease-[cubic-bezier(0.25,0.1,0.25,1.0)] hover:text-white hover:no-underline hover:opacity-90 hover:outline-none focus:text-white focus:no-underline focus:opacity-90 focus:outline-none motion-reduce:transition-none"
                type="button"
                data-twe-target="#carouselExampleCaptions"
                data-twe-slide="next">
                <span class="inline-block h-8 w-8">
                  <svg
                    aria-hidden="true"
                    xmlns="http://www.w3.org/2000/svg"
                    viewBox="0 0 16 16"
                    fill="#fff">
                    <path
                      d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z" />
                  </svg>
                </span>
                <span
                  class="!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]"
                  >Next</span
                >
              </button>
            </div>
            
            
        

    Via JavaScript

    You can access an instance from your Javascript code, by using the getInstance static method of the Carousel class - it allows making use of all the public methods listed in the Methods section.

    • javascript
    • umd
            
                
            const myCarousel = new Carousel(document.getElementById("myCarousel"), options);
            
            
        
            
                
            const myCarousel = new twe.Carousel(document.getElementById("myCarousel"), options);
            
            
        

    Options

    Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-twe-, as in data-twe-interval="4000".

    Name Type Default Description
    interval number 5000 The amount of time to delay between automatically cycling an item. If false, carousel will not automatically cycle.
    keyboard boolean true Whether the carousel should react to keyboard events.
    pause string | boolean "hover"

    If set to "hover", pauses the cycling of the carousel on mouseenter and resumes the cycling of the carousel on mouseleave. If set to false, hovering over the carousel won't pause it.

    On touch-enabled devices, when set to "hover", cycling will pause on touchend (once the user finished interacting with the carousel) for two intervals, before automatically resuming. Note that this is in addition to the above mouse behavior.

    ride string | boolean false If set to true, autoplays the carousel after the user manually cycles the first item. If set to "carousel", autoplays the carousel on load.
    wrap boolean true Whether the carousel should cycle continuously or have hard stops.
    touch boolean true Whether the carousel should support left/right swipe interactions on touchscreen devices.

    Classes

    Custom classes can be passed via data attributes or JavaScript. For data attributes, append the class name to data-twe-class, as in data-twe-class-pointer="touch-pan-x" (in default there is a touch-pan-y).

    Name Default Description
    pointer touch-pan-y Sets styles for controlling a carousel element's behavior on touchscreens.
    block !block Style the display of active carousel slide.
    visible data-[twe-carousel-fade]:opacity-100 data-[twe-carousel-fade]:z-[1] Sets transition styles on carousel slides visible.
    invisible data-[twe-carousel-fade]:z-0 data-[twe-carousel-fade]:opacity-0 data-[twe-carousel-fade]:duration-0 data-[twe-carousel-fade]:delay-600 Sets transition styles on carousel slides invisible.
    slideRight translate-x-full Utilities for translating a carousel element.
    slideLeft -translate-x-full Utilities for translating a carousel element.

    Methods

    Asynchronous methods and transitions:
    All API methods are asynchronous and start a transition. They return to the caller as soon as the transition is started but before it ends. In addition, a method call on a transitioning component will be ignored.

    You can create a carousel instance with the carousel constructor, for example, to initialize with additional options and start cycling through items:

    Method Description Example
    cycle Cycles through the carousel items from left to right. myCarousel.cycle()
    pause Stops the carousel from cycling through items. myCarousel.pause()
    prev Cycles to the previous item. Returns to the caller before the previous item has been shown (e.g., before the slid.twe.carousel event occurs). myCarousel.prev()
    next Cycles to the next item. Returns to the caller before the next item has been shown (e.g., before the slid.twe.carousel event occurs). myCarousel.next()
    nextWhenVisible Don’t cycle the carousel to next when the page isn’t visible or the carousel or its parent isn’t visible. Returns to the caller before the next item has been shown (e.g., before the slid.twe.carousel event occurs). myCarousel.nextWhenVisible()
    to Cycles the carousel to a particular frame (0 based, similar to an array). Returns to the caller before the target item has been shown (e.g., before the slid.twe.carousel event occurs). myCarousel.to(0)
    dispose Destroys an element's carousel. myCarousel.dispose()
    getInstance Static method which allows you to get the carousel instance associated with a DOM element. Carousel.getInstance()
    getOrCreateInstance Static method which allows you to get the carousel instance associated with a DOM element or create a new one in case it wasn't initialized. Carousel.getOrCreateInstance()
    • javascript
    • umd
            
                
            const myCarouselEl = document.getElementById("myCarousel");
            const myCarousel = new Carousel(myCarouselEl);
            carousel.pause();              
            
            
        
            
                
            const myCarouselEl = document.getElementById("myCarousel");
            const myCarousel = new twe.Carousel(myCarouselEl);
            carousel.pause();              
            
            
        

    Events

    Bootstrap’s carousel class exposes two events for hooking into carousel functionality. Both events have the following additional properties:

    • direction: The direction in which the carousel is sliding (either "left" or "right").
    • relatedTarget: The DOM element that is being slid into place as the active item.
    • from: The index of the current item
    • to: The index of the next item
    Event type Description
    slide.twe.carousel Fires immediately when the slide instance method is invoked.
    slid.twe.carousel Fired when the carousel has completed its slide transition.
    • JavaScript
            
                
              const myCarousel = document.getElementById('#myCarousel');
              myCarousel.addEventListener('slide.twe.carousel', () => {
                // do something...
              });
              
            
        
    • Import
    • Usage
    • Options
    • Classes
    • Methods
    • Events
    Get useful tips & free resources directly to your inbox along with exclusive subscriber-only content.
    Join our mailing list now
    © 2024 Copyright: MDBootstrap.com

    Access restricted

    To view this section you must have an active PRO account

    Log in to your account or purchase an TWE subscription if you don't have one.

    Buy TWE PRO