Skip to content
IzzyBlazor

Enter all results ↑ ↓ move Esc close

Carousel

Since 0.1.0-alpha.21
Shows slides in a row that swipes and scrolls a slide at a time.

Slides in a row that scrolls a slide at a time, with previous and next buttons and a dot for each slide.

Slides

Put a CarouselItem for each slide in a Carousel, and name the carousel with Label. To put the dots below the slides, set Dots to Below, or None for no dots.

Info:
Reduced motion
When the browser asks for reduced motion, the buttons and dots move straight to the slide rather than sliding there; a swipe still slides, since the browser runs it. Windows asks for it when Animation effects is off, and macOS when Reduce motion is on.

The slides swipe and scroll a slide at a time, and the arrow keys move them once the track has focus. With one slide in view, the dots sit on the slide by default.

The previous and next buttons and the dots need IzzyBlazor's script. With JavaScript off, the track still scrolls.

Several at once

To show several slides at once, set ItemsPerView, per breakpoint; Gap sets the space between them. The buttons then move a page, and the dots count pages. To wrap from the last slide to the first, set Loop.

Thumbnails

For a gallery, set Dots to Thumbnails and give each CarouselItem a Thumbnail. A small picture of each slide replaces the dots.

The row scrolls when the pictures don't fit, and keeps the current one in view. Each picture's button is named by its slide's Label. DarkThumbnail is the picture for the dark scheme.

Binding the slide

To know in C# which slide is in view, and to move to one from C#, bind @bind-Index. A starting Index other than 0 is scrolled to when the script runs.

Autoplay and fade

To move on a slide every few seconds, set Autoplay. Interval sets how long each slide shows, and a CarouselItem can set its own.

Info:
Reduced motion
When the browser asks for reduced motion, the rotation starts stopped, and a fade switches slides without fading. The button still starts it.

To fade from one slide to the next instead of sliding, set Transition to Fade.

Details

The track is the browser's own scroller, snapping to each slide, so swiping, a trackpad and the arrow keys move it even with no script. ItemsPerView shows several slides at once, per breakpoint; the buttons then move a page and the dots count pages. Loop wraps from the last slide to the first. Dots="CarouselDots.Thumbnails" replaces the dots with a row of small pictures, one for each slide (CarouselItem's Thumbnail). @bind-Index follows the slide in view on an interactive page; a starting Index other than 0 is scrolled to when the script runs. Autoplay moves on a slide every Interval, with a button to stop it. Transition.Fade cross-fades one slide at a time: drag, swipe or scroll sideways to move it.

Parts

Written inside Carousel. The API page lists their parameters.

Mode support

What works in each mode, Carousel
FeatureStaticInteractive
Slides that swipe and scroll a slide at a time, several at once per breakpointYesYes
Previous and next buttons, and a dot or a thumbnail for each slideYesYes
The slide in view bound to C#NoYes
Autoplay, with a button that stops and starts itYesYes
Slides that fade from one to the nextYesYes

Static: static server-side rendering, with no circuit and no WebAssembly. Interactive: Server, WebAssembly or Auto.

Without JavaScript

Every page starts as plain HTML: before IzzyBlazor's script loads on a static page, while an interactive page prerenders, and with JavaScript off. With JavaScript off, the slides scroll and swipe, and the previous and next buttons and dots don't show.

Accessibility

  • A region named by Label, which is required, with "carousel" as its role description. Each slide is a group named "3 of 5", or by its own Label.
  • The previous and next buttons, then the slides, then the dots are in the Tab order. Slides out of view are inert, so Tab doesn't land on what can't be seen.
  • The dots are buttons named "Slide 3", the one in view marked as current. Thumbnails are the same buttons, each named by its slide's Label.
  • When a person moves the carousel, the slide they move to is announced.
  • Autoplay adds a button that stops and starts the rotation, first in the Tab order. Rotation pauses while the pointer is over the carousel and while the page is hidden, stops when keyboard focus moves into it or a person touches or clicks in it (until the button starts it again), and doesn't start when the browser asks for reduced motion.

Keyboard navigation

On the slides, with Transition.Fade

Carousel keys, On the slides, with Transition.Fade
Press this keyTo do this
Left or RightGo to the previous or next slide (reversed on right-to-left pages)
Home or EndGo to the first or last slide

On the slides, otherwise

Carousel keys, On the slides, otherwise
Press this keyTo do this
Left or RightScroll the slides, with the browser's own keys

Parameters

Carousel parameters
PropTypeDefault
LabelWhat the carousel shows, such as "Featured trips": its accessible name.stringRequired
@bind-IndexThe slide in view (the first, when several show), from 0.int0
ItemsPerViewHow many slides show at once, per breakpoint.Responsive<int>1
GapSpace between slides, in spacing steps (0 to 16), per breakpoint.Responsive<int>4
LoopWraps from the last slide to the first, and back.boolfalse
ArrowsShows the previous and next buttons.booltrue
DotsWhere the dots go, a dot for each slide (each page, with several in view): CarouselDots.Auto, the default, puts them on the slide when one shows at a time and below when several do.CarouselDotsCarouselDots.Auto
AutoplayMoves on a slide every Interval, from the last back to the first, with a button that stops and starts it.boolfalse
IntervalHow long each slide shows with Autoplay.TimeSpanTimeSpan.FromMilliseconds(5000)
TransitionHow one slide gives way to the next: CarouselTransition.Slide, the default, or CarouselTransition.Fade, which shows one slide at a time and cross-fades.CarouselTransitionCarouselTransition.Slide
ChildContentThe CarouselItems.RenderFragment?

See also

  • CarouselItem: one slide of a Carousel.
  • Image: loads an image lazily and keeps its space.
  • Card: groups media, a header, body sections, actions and a footer in a box.

Connection lost

Rejoining the server…