lara-light-indigo

Carousel

Carousel is a content slider featuring various customization options.

Import via Module

import { Carousel } from 'primereact/carousel';
 
Import via CDN

<script src="https://unpkg.com/primereact/core/core.min.js"></script>
<script src="https://unpkg.com/primereact/carousel/carousel.min.js"></script>
 
Getting Started

Carousel requires a collection of items as its value along with a template to render each item.


<Carousel value={products} itemTemplate={itemTemplate}></Carousel>
 

const itemTemplate = (car) => {
    // return content;
}
 
Items per page and Scroll Items

Number of items per page is defined using the numVisible property whereas number of items to scroll is defined with the numScroll property.


<Carousel value={products} itemTemplate={itemTemplate} numVisible={3} numScroll={1}></Carousel>
 
Responsive

For responsive design, numVisible and numScroll can be defined using the responsiveOptions property that should be an array of objects whose breakpoint defines the max-width to apply the settings.


<Carousel value={products} itemTemplate={itemTemplate} numVisible={3} numScroll={1} responsiveOptions={responsiveOptions}></Carousel>
 

const responsiveOptions = [
    {
        breakpoint: '1024px',
        numVisible: 3,
        numScroll: 3
    },
    {
        breakpoint: '768px',
        numVisible: 2,
        numScroll: 2
    },
    {
        breakpoint: '560px',
        numVisible: 1,
        numScroll: 1
    }
];
 
Header and Footer

Custom content projection is available using the header and footer properties.


<Carousel value={products} itemTemplate={itemTemplate} header={<h1>Header</h1>}></Carousel>
 
Orientation

Default layout of the Carousel is horizontal, other possible option is the vertical mode that is configured with the orientation property.


<Carousel value={products} itemTemplate={itemTemplate} orientation="vertical"></Carousel>
 
AutoPlay and Circular

When autoplayInterval is defined in milliseconds, items are scrolled automatically. In addition, for infinite scrolling circular property needs to be enabled. Note that in autoplay mode, circular is enabled by default.

Controlled vs Uncontrolled

In controlled mode, page and onPageChange properties need to be defined to control the first visible item.


<Carousel value={products} itemTemplate={itemTemplate} page={page} onPageChange={(e) => setPage(e.page)}></Carousel>
 
Uncontrolled

In uncontrolled mode, no additional properties are required. Initial page can be provided using the page property in uncontrolled mode however it is evaluated at initial rendering and ignored in further updates. If you programmatically need to update the first visible item index, prefer to use the component as controlled.


<Carousel value={products} itemTemplate={itemTemplate}></Carousel>
 
Properties
NameTypeDefaultDescription
idstringnullUnique identifier of the element.
valuearraynullAn array of objects to display.
pagenumbernullIndex of the first item.
headeranynullLabel of header.
footeranynullLabel of footer.
stylestringnullInline style of the component.
classNamestringnullStyle class of the component.
itemTemplatefunctionnullFunction that gets an item in the value and returns the content for it.
circularbooleanfalseDefines if scrolling would be infinite.
autoplayIntervalnumbernullTime in milliseconds to scroll items automatically.
numVisiblenumber1Number of items per page.
numScrollnumber1Number of items to scroll.
responsiveOptionsanynullAn array of options for responsive design.
orientationstringhorizontalSpecifies the layout of the component, valid values are "horizontal" and "vertical".
verticalViewPortHeightstring300pxHeight of the viewport in vertical layout.
contentClassNamestringnullStyle class of main content.
containerClassNamestringnullStyle class of the viewport container.
indicatorsContentClassNamestringnullStyle class of the paginator items.
Events
NameParametersDescription
onPageChangeevent.page = Value of the new page.Callback to invoke after scroll.
Styling

Following is the list of structural style classes

NameElement
p-carouselContainer element.
p-carousel-headerHeader section.
p-carousel-footerFooter section.
p-carousel-contentMain content element. It contains the container of the viewport.
p-carousel-containerContainer of the viewport. It contains navigation buttons and viewport.
p-carousel-items-contentViewport.
p-carousel-indicatorsContainer of the indicators.
p-carousel-indicatorIndicator element.
Dependencies

None.

Component Scale

Input Style

Ripple Effect

Free Themes

Built-in component themes created by the PrimeReact Theme Designer.

Bootstrap
Blue
Purple
Blue
Purple
Material Design
Indigo
Deep Purple
Indigo
Deep Purple
Material Design Compact
Indigo
Deep Purple
Indigo
Deep Purple
Tailwind
Tailwind Light
Fluent UI
Blue
PrimeOne Design - 2022 NEW
Lara Indigo
Lara Blue
Lara Purple
Lara Teal
Lara Indigo
Lara Blue
Lara Purple
Lara Teal
PrimeOne Design - 2021
Saga Blue
Saga Green
Saga Orange
Saga Purple
Vela Blue
Vela Green
Vela Orange
Vela Purple
Arya Blue
Arya Green
Arya Orange
Arya Purple
Premium Themes

Premium themes are only available exclusively for PrimeReact Theme Designer subscribers and therefore not included in PrimeReact core.

Soho Light
Soho Dark
Viva Light
Viva Dark
Mira
Nano

Legacy Free Themes

Nova
Nova Alt
Nova Accent
Luna Blue
Luna Green
Luna Amber
Luna Pink
Rhea

Premium Create-React-App Templates

Beautifully crafted premium create-react-app application templates by the PrimeTek design team.

Sakai
Atlantis
Freya
Ultima
Diamond
Sapphire
Serenity
Babylon
Avalon
Apollo
Roma