
Quick answer: Materialize ships two image components. The carousel is a rotating set of cards with prev/next controls, built from a div.carousel containing div.carousel-item elements and initialized with M.Carousel.init(). The slider is a full-width banner that fills the viewport, built from a ul.slider with li slides and initialized with M.Slider.init(). Both are JavaScript components — nothing moves until you initialize them, which is the mistake behind the vast majority of frozen carousels.
Carousel in 3 steps
Markup first, then initialization. Each item is a card-like block, so the visual options are the same ones you use on Materialize cards.
<!-- Step 1: the carousel -->
<div class="carousel">
<a class="carousel-item" href="#one!"><img src="slide1.jpg"></a>
<a class="carousel-item" href="#two!"><img src="slide2.jpg"></a>
<a class="carousel-item" href="#three!"><img src="slide3.jpg"></a>
</div>
<!-- Step 2: initialization -->
<script>
document.addEventListener('DOMContentLoaded', function () {
var elems = document.querySelectorAll('.carousel');
M.Carousel.init(elems, {
fullWidth: false,
indicators: true
});
});
</script>Set fullWidth: true and the focused item expands to the full container width while the neighbours peek in at a reduced scale — the pattern most landing pages use. The indicators option adds the row of dots under the carousel.
Carousel options that matter
| Option | Default | What it does |
|---|---|---|
| duration | 200 | Transition speed, in milliseconds |
| dist | -100 | How far each item is offset from the centre |
| shift | 0 | How much to shift the whole carousel horizontally |
| padding | 0 | Space between items |
| numVisible | 5 | How many items are visible at once |
| fullWidth | false | Focused item fills the container |
| indicators | false | Show dot navigation under the carousel |
| noWrap | false | Stop infinite wrapping at the ends |
| onCycleTo | null | Callback fired when a new item becomes focused |
M.Carousel.init(document.querySelectorAll('.carousel'), {
fullWidth: true,
indicators: true,
numVisible: 3,
onCycleTo: function (item, dragged) {
console.log('now showing', item);
}
});Controlling the carousel from JavaScript
For arrows, thumbnails or autoplay you drive the instance directly rather than waiting for a click or swipe:
var c = M.Carousel.getInstance(document.querySelector('.carousel'));
c.next();
c.prev();
c.set(2); // jump to the third item (zero-indexed)
setInterval(function () { c.next(); }, 4000);The set() method is what gallery thumbnails call to jump straight to an image, and the interval above is the simplest autoplay. A production-ready autoplay banner that pauses on hover is documented in the full-width autoplay slider guide.
Slider vs carousel: which one to use
The slider component is a fullscreen banner, not a card rack. Reach for it when you want one image at a time with optional captions and a fixed height.
| Slider option | Default | What it does |
|---|---|---|
| indicators | true | Show dot navigation |
| height | 400 | Slider height in pixels |
| duration | 500 | Transition speed, in milliseconds |
| interval | 6000 | Autoplay delay between slides |
| fullscreen | false | Fill the viewport or use the fixed height |
<ul class="slider">
<li><img src="banner1.jpg"></li>
<li><img src="banner2.jpg"></li>
</ul>
M.Slider.init(document.querySelectorAll('.slider'), {
height: 480,
interval: 7000
});Rule of thumb: use the slider for a single hero banner at the top of a page, and the carousel for browsing a set of images or cards inside the page. The responsive sizing both rely on comes from the Materialize grid system.
When the carousel does not move: four checks
- No initialization. Markup without
M.Carousel.init()is a static row of images on 1.0.0. - Wrong item class. Items must be
carousel-item(singular). A plural class or a plaindivis ignored. - Images not sized. Carousel items need explicit image dimensions; oversized images blow the layout out of the container.
- Old 0.97.x API. The removed jQuery initialization from old tutorials does nothing on 1.0.0.
Version mix-ups are the thread running through all of these; the Materialize CSS tutorial shows the correct 1.0.0 imports so the CSS and JavaScript always match.
Working on a gallery or hero banner and want the animation tuned? Ampersand Academy coaches front-end work one-to-one, using your own project as the curriculum.
Frequently asked questions
Why is my Materialize carousel not working?
The usual causes are a missing M.Carousel.init() call, items using the wrong class instead of carousel-item, or images without set dimensions that break the layout.
What is the difference between a Materialize carousel and slider?
The slider is a fullscreen banner that fills the viewport or a fixed height. The carousel is a rotating set of cards with items visible on either side. Use the slider for a hero banner and the carousel for browsing images in page.
How do I make a Materialize carousel autoplay?
Get the instance with M.Carousel.getInstance(elem) and call next() from a setInterval. There is no built-in autoplay option for the carousel, so the timer is added in JavaScript.
How do I make one Materialize carousel item fill the width?
Initialize with fullWidth set to true. The focused item then expands to the full container width while neighbouring items stay partly visible at a smaller scale.
How do I jump to a specific Materialize carousel image?
Call set() on the instance with the zero-indexed position, for example c.set(2) for the third item. Gallery thumbnails use this to link straight to an image.
