React Carousel Component

Carousel

React carousel is a slideshow component for cycling through elements—images or slides of text—like a carousel.

Other frameworks

CoreUI components are available as native Angular, Bootstrap (Vanilla JS), and Vue components. To learn more please visit the following pages.

How it works#

The React carousel is a slideshow for cycling within a group of content. It runs with a group of images, text, or html elements. It also incorporates support for previous/next buttons.

In browsers where the Page Visibility API is supported, the carousel will avoid sliding when the webpage is not visible to the user (such as when the browser tab is inactive, the browser window is minimized, etc.).

Example#

Carousels don't automatically normalize slide dimensions. As such, you may want to use extra utilities or custom methods to properly size content. While carousels support previous/next controls and indicators, they're not explicitly expected. Add and customize as you see fit.

Slides only#

<CCarousel>
<CCarouselItem>
<CImage className="d-block w-100" src={ReactImg} alt="slide 1" />
</CCarouselItem>
<CCarouselItem>
<CImage className="d-block w-100" src={VueImg} alt="slide 2" />
</CCarouselItem>
<CCarouselItem>
<CImage className="d-block w-100" src={AngularImg} alt="slide 3" />
</CCarouselItem>
</CCarousel>

With controls#

Adding in the previous and next controls by controls property.

<CCarousel controls>
<CCarouselItem>
<CImage className="d-block w-100" src={ReactImg} alt="slide 1" />
</CCarouselItem>
<CCarouselItem>
<CImage className="d-block w-100" src={VueImg} alt="slide 2" />
</CCarouselItem>
<CCarouselItem>
<CImage className="d-block w-100" src={AngularImg} alt="slide 3" />
</CCarouselItem>
</CCarousel>

With indicators#

You can attach the indicators to the carousel, lengthwise the controls, too.

<CCarousel controls indicators>
<CCarouselItem>
<CImage className="d-block w-100" src={ReactImg} alt="slide 1" />
</CCarouselItem>
<CCarouselItem>
<CImage className="d-block w-100" src={VueImg} alt="slide 2" />
</CCarouselItem>
<CCarouselItem>
<CImage className="d-block w-100" src={AngularImg} alt="slide 3" />
</CCarouselItem>
</CCarousel>

With captions#

You can add captions to slides with the <CCarouselCaption> element within any <CCarouselItem>. They can be immediately hidden on smaller viewports, as shown below, with optional display utilities. We hide them with .d-none and draw them back on medium-sized devices with .d-md-block.

<CCarousel controls indicators>
<CCarouselItem>
<CImage className="d-block w-100" src={ReactImg} alt="slide 1" />
<CCarouselCaption className="d-none d-md-block">
<h5>First slide label</h5>
<p>Some representative placeholder content for the first slide.</p>
</CCarouselCaption>
</CCarouselItem>
<CCarouselItem>
<CImage className="d-block w-100" src={VueImg} alt="slide 2" />
<CCarouselCaption className="d-none d-md-block">
<h5>Second slide label</h5>
<p>Some representative placeholder content for the first slide.</p>
</CCarouselCaption>
</CCarouselItem>
<CCarouselItem>
<CImage className="d-block w-100" src={AngularImg} alt="slide 3" />
<CCarouselCaption className="d-none d-md-block">
<h5>Third slide label</h5>
<p>Some representative placeholder content for the first slide.</p>
</CCarouselCaption>
</CCarouselItem>
</CCarousel>

Crossfade#

Add transition="crossfade" to your carousel to animate slides with a fade transition instead of a slide.

<CCarousel controls transition="crossfade">
<CCarouselItem>
<CImage className="d-block w-100" src={ReactImg} alt="slide 1" />
</CCarouselItem>
<CCarouselItem>
<CImage className="d-block w-100" src={VueImg} alt="slide 2" />
</CCarouselItem>
<CCarouselItem>
<CImage className="d-block w-100" src={AngularImg} alt="slide 3" />
</CCarouselItem>
</CCarousel>

Dark variant#

Add dark property to the CCarousel for darker controls, indicators, and captions. Controls have been inverted from their default white fill with the filter CSS property. Captions and controls have additional Sass variables that customize the color and background-color.

<CCarousel controls indicators dark>
<CCarouselItem>
<CImage className="d-block w-100" src={ReactImg} alt="slide 1" />
<CCarouselCaption className="d-none d-md-block">
<h5>First slide label</h5>
<p>Some representative placeholder content for the first slide.</p>
</CCarouselCaption>
</CCarouselItem>
<CCarouselItem>
<CImage className="d-block w-100" src={VueImg} alt="slide 2" />
<CCarouselCaption className="d-none d-md-block">
<h5>Second slide label</h5>
<p>Some representative placeholder content for the first slide.</p>
</CCarouselCaption>
</CCarouselItem>
<CCarouselItem>
<CImage className="d-block w-100" src={AngularImg} alt="slide 3" />
<CCarouselCaption className="d-none d-md-block">
<h5>Third slide label</h5>
<p>Some representative placeholder content for the first slide.</p>
</CCarouselCaption>
</CCarouselItem>
</CCarousel>

Customizing#

SASS variables#

$carousel-control-color: $white !default;
$carousel-control-width: 15% !default;
$carousel-control-opacity: .5 !default;
$carousel-control-hover-opacity: .9 !default;
$carousel-control-transition: opacity .15s ease !default;
$carousel-indicator-width: 30px !default;
$carousel-indicator-height: 3px !default;
$carousel-indicator-hit-area-height: 10px !default;
$carousel-indicator-spacer: 3px !default;
$carousel-indicator-opacity: .5 !default;
$carousel-indicator-active-bg: $white !default;
$carousel-indicator-active-opacity: 1 !default;
$carousel-indicator-transition: opacity .6s ease !default;
$carousel-caption-width: 70% !default;
$carousel-caption-color: $white !default;
$carousel-caption-padding-y: 1.25rem !default;
$carousel-caption-spacer: 1.25rem !default;
$carousel-control-icon-width: 2rem !default;
$carousel-control-prev-icon-bg: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='#{$carousel-control-color}'><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 0'/></svg>") !default;
$carousel-control-next-icon-bg: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='#{$carousel-control-color}'><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-.708'/></svg>") !default;
$carousel-transition-duration: .6s !default;
$carousel-transition: transform $carousel-transition-duration ease-in-out !default; // Define transform transition first if using multiple transitions (e.g., `transform 2s ease, opacity .5s ease-out`)

API#

CCarousel#

import { CCarousel } from '@coreui/react'
// or
import CCarousel from '@coreui/react/src/components/carousel/CCarousel'
PropertyDescriptionTypeDefault
activeIndexindex of the active item.number0
classNameA string of all className you want applied to the base component.string-
controlsAdding in the previous and next controls.boolean-
darkAdd darker controls, indicators, and captions.boolean-
indicatorsAdding indicators at the bottom of the carousel for each item.boolean-
intervalThe amount of time to delay between automatically cycling an item. If false, carousel will not automatically cycle.number | boolean5000
onSlidCallback fired when a slide transition end.(active: number, direction: string) => void-
onSlideCallback fired when a slide transition starts.(active: number, direction: string) => void-
pauseIf 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.boolean | 'hover'hover
touch
4.5.0+
Set whether the carousel should support left/right swipe interactions on touchscreen devices.booleantrue
transitionSet type of the transition.'slide' | 'crossfade'-
wrapSet whether the carousel should cycle continuously or have hard stops.booleantrue

CCarouselCaption#

import { CCarouselCaption } from '@coreui/react'
// or
import CCarouselCaption from '@coreui/react/src/components/carousel/CCarouselCaption'
PropertyDescriptionTypeDefault
classNameA string of all className you want applied to the base component.string-

CCarouselItem#

import { CCarouselItem } from '@coreui/react'
// or
import CCarouselItem from '@coreui/react/src/components/carousel/CCarouselItem'
PropertyDescriptionTypeDefault
classNameA string of all className you want applied to the base component.string-
intervalThe amount of time to delay between automatically cycling an item.number | booleanfalse