Angular Bootstrap Carousel
Angular Carousel - Bootstrap 4 & Material Design
Note: This documentation is for an older version of Bootstrap (v.4). A
newer version is available for Bootstrap 5. We recommend migrating to the latest version of our product - Material Design for
Bootstrap 5.
Go to docs v.5
A slideshow component for cycling through elements—images or slides of text—like a carousel.
How it works
The carousel is a slideshow for cycling through a series of content, built with CSS 3D transforms and a bit of JavaScript. It works with a series of images, text, or custom markup. It also includes support for previous/next controls and indicators.
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.).
Please be aware that nested carousels are not supported, and carousels are generally not compliant with accessibility standards.
Example
Carousels don’t automatically normalize slide dimensions. As such, you may need to use additional utilities or custom styles to appropriately size content. While carousels support previous/next controls and indicators, they’re not explicitly required. Add and customize as you see fit.
Slides only
Here’s a carousel with slides only. Note the presence of the .d-block
and .w-100
on carousel images to prevent browser default image alignment.
<mdb-carousel [isControls]="false" [animation]="'slide'">
<mdb-carousel-item>
<img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(130).webp" alt="First slide">
</mdb-carousel-item>
<mdb-carousel-item>
<img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(129).webp" alt="Second slide">
</mdb-carousel-item>
<mdb-carousel-item>
<img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(70).webp" alt="Third slide">
</mdb-carousel-item>
</mdb-carousel>
With controls and indicators
Adding in the previous and next controls, and the slides indicator:
<mdb-carousel [animation]="'slide'">
<mdb-carousel-item>
<img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(130).webp" alt="First slide">
</mdb-carousel-item>
<mdb-carousel-item>
<img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(129).webp" alt="Second slide">
</mdb-carousel-item>
<mdb-carousel-item>
<img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(70).webp" alt="Third slide">
</mdb-carousel-item>
</mdb-carousel>
With captions
Add captions to your slides easily with the .carousel-caption
element within any
mdb-carousel-item
. They can be easily hidden on smaller viewports, as shown below, with optional display
utilities. We
hide them initially with .d-none
and bring them back on medium-sized devices with .d-md-block
.
If your content is not visible enough, you can cover the image with a darker mask.
You can easily change the intensity and color of the mask. To learn more read our MASKS documentation.
<mdb-carousel class="carousel slide carousel-fade" [animation]="'fade'">
<mdb-carousel-item>
<div class="view w-100">
<img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(68).webp" alt="First slide">
<div class="mask rgba-black-light waves-light" mdbWavesEffect></div>
</div>
<div class="carousel-caption">
<h3 class="h3-responsive">Light mask</h3>
<p>First text</p>
</div>
</mdb-carousel-item>
<mdb-carousel-item>
<div class="view w-100">
<img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(6).webp" alt="Second slide">
<div class="mask rgba-black-strong waves-light" mdbWavesEffect></div>
</div>
<div class="carousel-caption">
<h3 class="h3-responsive">Strong mask</h3>
<p>Secondary text</p>
</div>
</mdb-carousel-item>
<mdb-carousel-item>
<div class="view w-100">
<img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(9).webp" alt="Third slide">
<div class="mask rgba-black-slight waves-light" mdbWavesEffect></div>
</div>
<div class="carousel-caption">
<h3 class="h3-responsive">Slight mask</h3>
<p>Third text</p>
</div>
</mdb-carousel-item>
</mdb-carousel>
Crossfade
Add .carousel-fade
and [animation]="'fade'"
to your carousel to animate slides with a fade transition
instead of a slide.
<mdb-carousel class="carousel slide carousel-fade" [animation]="'fade'">
<mdb-carousel-item>
<img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(68).webp" alt="First slide">
</mdb-carousel-item>
<mdb-carousel-item>
<img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(6).webp" alt="Second slide">
</mdb-carousel-item>
<mdb-carousel-item>
<img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(9).webp" alt="Third slide">
</mdb-carousel-item>
</mdb-carousel>
Multi-item carousel MDB Pro component
<mdb-carousel [isControls]="true" class="carousel-multi-item multi-animation" [type]="'carousel-multi-item'" [animation]="'slide'">
<mdb-carousel-item *ngFor="let item of slides; let i = index">
<div class="col-md-4" *ngFor="let card of item; let cardIndex = index">
<mdb-card class="my-1">
<mdb-card-img [src]="card.img" alt="Card image cap"></mdb-card-img>
<mdb-card-body>
<mdb-card-title>
<h4>{{card.title}}</h4>
</mdb-card-title>
<p>{{card.description}}</p>
<a href="#" mdbBtn color="primary" class="waves-light" mdbWavesEffect>{{card.buttonText}}</a>
</mdb-card-body>
</mdb-card>
</div>
</mdb-carousel-item>
</mdb-carousel>
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'multi-item-carousel',
templateUrl: './multi-item-carousel.component.html',
styleUrls: ['./multi-item-carousel.component.scss'],
})
export class MultiItemCarouselComponent implements OnInit {
cards = [
{
title: 'Card Title 1',
description: 'Some quick example text to build on the card title and make up the bulk of the card content',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
},
{
title: 'Card Title 2',
description: 'Some quick example text to build on the card title and make up the bulk of the card content',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
},
{
title: 'Card Title 3',
description: 'Some quick example text to build on the card title and make up the bulk of the card content',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
},
{
title: 'Card Title 4',
description: 'Some quick example text to build on the card title and make up the bulk of the card content',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
},
{
title: 'Card Title 5',
description: 'Some quick example text to build on the card title and make up the bulk of the card content',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
},
{
title: 'Card Title 6',
description: 'Some quick example text to build on the card title and make up the bulk of the card content',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
},
{
title: 'Card Title 7',
description: 'Some quick example text to build on the card title and make up the bulk of the card content',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
},
{
title: 'Card Title 8',
description: 'Some quick example text to build on the card title and make up the bulk of the card content',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
},
{
title: 'Card Title 9',
description: 'Some quick example text to build on the card title and make up the bulk of the card content',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
},
];
slides: any = [[]];
chunk(arr: any, chunkSize: number) {
let R = [];
for (let i = 0, len = arr.length; i < len; i += chunkSize) {
R.push(arr.slice(i, i + chunkSize));
}
return R;
}
ngOnInit() {
this.slides = this.chunk(this.cards, 3);
}
}
Multi-item carousel card decks MDB Pro component
<mdb-carousel [isControls]="true" class="carousel-multi-item multi-animation" [type]="'carousel-multi-item'" [animation]="'slide'">
<mdb-carousel-item *ngFor="let item of slides; let i = index">
<div class="col-md-4 pb-2" *ngFor="let card of item; let cardIndex = index">
<mdb-card class="my-1 h-100">
<mdb-card-img [src]="card.img" alt="Card image cap"></mdb-card-img>
<mdb-card-body>
<mdb-card-title>
<h4>{{card.title}}</h4>
</mdb-card-title>
<p>{{card.description}}</p>
</mdb-card-body>
<mdb-card-footer>
<a href="#" mdbBtn color="primary" class="waves-light" mdbWavesEffect>{{card.buttonText}}</a>
</mdb-card-footer>
</mdb-card>
</div>
</mdb-carousel-item>
</mdb-carousel>
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
cards = [
{
title: 'Card Title 1',
description: 'This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
},
{
title: 'Card Title 2',
description: 'This card has supporting text below as a natural lead-in to additional content.',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
},
{
title: 'Card Title 3',
description: 'This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action. This text is much longer so that you can see a significant difference between the text in previous tabs.',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
},
{
title: 'Card Title 4',
description: 'Some quick example text to build on the card title and make up the bulk of the card content',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
},
{
title: 'Card Title 5',
description: 'Some quick example text to build on the card title and make up the bulk of the card content',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
},
{
title: 'Card Title 6',
description: 'Some quick example text to build on the card title and make up the bulk of the card content',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
}
];
slides: any = [[]];
chunk(arr: any, chunkSize: number) {
let R = [];
for (let i = 0, len = arr.length; i < len; i += chunkSize) {
R.push(arr.slice(i, i + chunkSize));
}
return R;
}
ngOnInit() {
this.slides = this.chunk(this.cards, 3);
}
}
.carousel-item {
&.active, &.carousel-item-right, &.carousel-item-next {
display: flex !important;
flex-wrap: wrap
}
}
Multi-item carousel responsive MDB Pro component
Use code from this example if you need multiple carousel on bigger screens and single carousel on mobile devices.
<mdb-carousel
[animation]="'slide'"
[ngSwitch]="carouselDisplayMode"
[isControls]="true" class="carousel-multi-item multi-animation"
[type]="'carousel-multi-item'"
>
<ng-container *ngSwitchCase="'single'">
<mdb-carousel-item *ngFor="let card of cards">
<mdb-card class="my-1">
<mdb-card-img [src]="card.img" alt="Card image cap"></mdb-card-img>
<mdb-card-body>
<mdb-card-title>
<h4> {{ card.title }}</h4>
</mdb-card-title>
<p>{{ card.description }}</p>
<a href="#" mdbBtn color="primary" class="waves-light" mdbWavesEffect>{{card.buttonText}}</a>
</mdb-card-body>
</mdb-card>
</mdb-carousel-item>
</ng-container>
<ng-container *ngSwitchCase="'multiple'">
<mdb-carousel-item *ngFor="let item of slides; let i = index">
<div class="col-md-4" *ngFor="let card of item; let cardIndex = index">
<mdb-card class="my-1">
<mdb-card-img [src]="card.img" alt="Card image cap"></mdb-card-img>
<mdb-card-body>
<mdb-card-title>
<h4>{{card.title}}</h4>
</mdb-card-title>
<p>{{card.description}}</p>
<a href="#" mdbBtn color="primary" class="waves-light" mdbWavesEffect>{{card.buttonText}}</a>
</mdb-card-body>
</mdb-card>
</div>
</mdb-carousel-item>
</ng-container>
</mdb-carousel>
import { Component, OnInit, HostListener } from '@angular/core';
@Component({
selector: 'multi-item-carousel',
templateUrl: './multi-item-carousel.component.html',
styleUrls: ['./multi-item-carousel.component.scss'],
})
export class MultiItemCarouselComponent implements OnInit {
CAROUSEL_BREAKPOINT = 768;
carouselDisplayMode = 'multiple';
cards = [
{
title: 'Card Title 1',
description: 'Some quick example text to build on the card title and make up the bulk of the card content',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
},
{
title: 'Card Title 2',
description: 'Some quick example text to build on the card title and make up the bulk of the card content',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
},
{
title: 'Card Title 3',
description: 'Some quick example text to build on the card title and make up the bulk of the card content',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
},
{
title: 'Card Title 4',
description: 'Some quick example text to build on the card title and make up the bulk of the card content',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
},
{
title: 'Card Title 5',
description: 'Some quick example text to build on the card title and make up the bulk of the card content',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
},
{
title: 'Card Title 6',
description: 'Some quick example text to build on the card title and make up the bulk of the card content',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
},
{
title: 'Card Title 7',
description: 'Some quick example text to build on the card title and make up the bulk of the card content',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
},
{
title: 'Card Title 8',
description: 'Some quick example text to build on the card title and make up the bulk of the card content',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
},
{
title: 'Card Title 9',
description: 'Some quick example text to build on the card title and make up the bulk of the card content',
buttonText: 'Button',
img: 'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).webp'
},
];
slides: any = [[]];
chunk(arr: any, chunkSize: number) {
let R = [];
for (let i = 0, len = arr.length; i < len; i += chunkSize) {
R.push(arr.slice(i, i + chunkSize));
}
return R;
}
ngOnInit() {
this.slides = this.chunk(this.cards, 3);
if (window.innerWidth <= this.CAROUSEL_BREAKPOINT) {
this.carouselDisplayMode = 'single';
} else {
this.carouselDisplayMode = 'multiple';
}
}
@HostListener('window:resize')
onWindowResize() {
if (window.innerWidth <= this.CAROUSEL_BREAKPOINT) {
this.carouselDisplayMode = 'single';
} else {
this.carouselDisplayMode = 'multiple';
}
}
}
Thumbnails carousel MDB Pro component
<mdb-carousel class="carousel slide carousel-fade" [type]="'carousel-thumbnails'" [animation]="'fade'">
<mdb-carousel-item>
<img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(88).webp" alt="First slide">
</mdb-carousel-item>
<mdb-carousel-item>
<img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(121).webp" alt="Second slide">
</mdb-carousel-item>
<mdb-carousel-item>
<img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(31).webp" alt="Third slide">
</mdb-carousel-item>
</mdb-carousel>
Video carousel
<mdb-carousel class="carousel slide carousel-fade" [animation]="'fade'">
<mdb-carousel-item>
<video class="video-fluid" autoplay loop muted>
<source src="https://mdbootstrap.com/img/video/Tropical.mp4" type="video/mp4" />
</video>
</mdb-carousel-item>
<mdb-carousel-item>
<video class="video-fluid" autoplay loop muted>
<source src="https://mdbootstrap.com/img/video/forest.mp4" type="video/mp4" />
</video>
</mdb-carousel-item>
<mdb-carousel-item>
<video class="video-fluid" autoplay loop muted>
<source src="https://mdbootstrap.com/img/video/Tropical.mp4" type="video/mp4" />
</video>
</mdb-carousel-item>
</mdb-carousel>
Full page image carousel
Use atleast Full HD pictures, and add height: 100vh
style to html, body, .view, .carousel, .carousel-inner elements
.
<mdb-carousel [isControls]="true" [animation]="'slide'">
<mdb-carousel-item>
<div class="view">
<img class="d-block" src="https://wallpaper.wiki/wp-content/uploads/2017/05/wallpaper.wiki-Full-HD-1920x1080-Nature-Wallpapers-PIC-WPE0012781.webp"
alt="First slide">
<div class="mask flex-center rgba-black-light">
</div>
</div>
</mdb-carousel-item>
<mdb-carousel-item>
<div class="view">
<img class="d-block" src="http://www.kinyu-z.net/data/wallpapers/228/1502404.webp" alt="Second slide">
<div class="mask flex-center rgba-black-light">
</div>
</div>
</mdb-carousel-item>
<mdb-carousel-item>
<div class="view">
<img class="d-block" src="https://wallpaper.wiki/wp-content/uploads/2017/05/wallpaper.wiki-Beautiful-Full-HD-Images-PIC-WPE0011754.webp"
alt="Third slide">
<div class="mask flex-center rgba-black-light">
</div>
</div>
</mdb-carousel-item>
</mdb-carousel>
html,
body,
.view {
height: 100vh;
}
/* Full Page Carousel itself*/
.carousel {
height: 100vh;
}
.carousel .carousel-inner {
height: 100vh;
}
.carousel .carousel-inner .carousel-item,
.carousel .carousel-inner .active {
height: 100vh;
}
img {
&.d-block {
height: 100vh;
}
}
Full page video carousel
Use atleast Full HD pictures, and add height: 100vh
style to html, body, .view, .carousel, .carousel-inner elements
.
<mdb-carousel class="carousel slide" [animation]="'slide'">
<mdb-carousel-item>
<div class="view">
<video class="video-fluid" autoplay loop>
<source src="https://mdbootstrap.com/img/video/Lines.mp4" type="video/mp4" />
</video>
<div class="mask rgba-indigo-light waves-light" mdbWavesEffect></div>
</div>
<div class="carousel-caption">
<div class="animated fadeInDown">
<h3 class="h3-responsive">Light mask</h3>
<p>First text</p>
</div>
</div>
</mdb-carousel-item>
<mdb-carousel-item>
<div class="view">
<video class="video-fluid" autoplay loop>
<source src="https://mdbootstrap.com/img/video/animation-intro.mp4" type="video/mp4" />
</video>
<div class="mask rgba-purple-slight waves-light" mdbWavesEffect></div>
</div>
<div class="carousel-caption">
<div class="animated fadeInDown">
<h3 class="h3-responsive">Super light mask</h3>
<p>Secondary text</p>
</div>
</div>
</mdb-carousel-item>
<mdb-carousel-item>
<div class="view">
<video class="video-fluid" autoplay loop>
<source src="https://mdbootstrap.com/img/video/Tropical.mp4" type="video/mp4" />
</video>
<div class="mask rgba-black-strong waves-light" mdbWavesEffect></div>
</div>
<div class="carousel-caption">
<div class="animated fadeInDown">
<h3 class="h3-responsive">Strong mask</h3>
<p>Third text</p>
</div>
</div>
</mdb-carousel-item>
</mdb-carousel>
html,
body,
.view {
height: 100vh;
}
/* Full Page Carousel itself*/
.carousel {
height: 100vh;
}
.carousel .carousel-inner {
height: 100vh;
}
.carousel .carousel-inner .carousel-item,
.carousel .carousel-inner .active {
height: 100vh;
}
.video-fluid {
max-width: unset;
}
Mobile devices
When using mdb-carousel
on devices with touch input you need to configure hammerjs
as shown on the mobile setup docs.
Otherwise you won't be able to scroll over mdb-carousel
Angular Carousel - API
In this section you will find informations about required modules and available inputs, outputs, methods and events of carousel component.
Modules used
In order to speed up your application, you can choose to import only the modules you actually need, instead of importing the entire MDB Angular library. Remember that importing the entire library, and immediately afterwards a specific module, is bad practice, and can cause application errors.
import { CarouselModule, WavesModule } from 'ng-uikit-pro-standard'
import { CarouselModule, WavesModule } from 'angular-bootstrap-md'
Components
CarouselComponent
Selector: mdb-carousel
Type: CarouselComponent
Inputs
Name | Type | Default | Description | Example |
---|---|---|---|---|
allowSwipe
|
boolean | true | Allow to use swipe gesture. | [allowSwipe]="false" |
animation
|
string | - | Allow to specify animation type | [animation]="'fade'" |
interval
|
number | 5000 | The amount of time to delay between automatically cycling an item. If 0, carousel will not automatically cycle. | [interval]="'0'" |
noPause
|
boolean | false | No pauses the cycling of the carousel on mouseenter and resumes the cycling of the carousel on mouseleave. | [noPause]="true" |
noWrap
|
boolean | false | Whether the carousel should cycle continuously or have hard stops. | [noWrap]="true" |
keyboard
|
boolean | true | Whether the carousel should react to keyboard events. | [keyboard]="false" |
activeSlideIndex
|
number | 0 | Index of currently displayed slide (started for 0). You can tell carousel from which one slide start. (two way binding [(activeSlideIndex)] ) | [activeSlideIndex]="1" |
isControls
|
boolean | true | If set to false, carousel won't show next / previous buttons. | [isControls]="false" |
type
|
string | - | Allow to specfiy carousel type | [type]="'carousel-multi-item'" |
Methods
Below methods are available in CarouselComponent
Name | Description |
---|---|
play()
|
Cycles through the carousel items from left to right. |
pause()
|
Stops the carousel from cycling through items. |
selectSlide(number)
|
Cycles the carousel to a particular frame (0 based, similar to an array). |
previousSlide()
|
Cycles to the previous item. |
nextSlide()
|
Cycles to the next item. |
Events
Name | Type | Description | Example |
---|---|---|---|
activeSlideChange
|
any | Will be emitted when active slide has been changed | (activeSlideChange)="onActiveSlideChange($event)" |