Carousel
Since 0.1.0-alpha.21Slides 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.
Static
Preview
Install the package
Add IzzyBlazor from NuGet and register it in Program.cs.
Add the stylesheet
One link in App.razor brings the theme and every component's styles.
Build a page
Components render on the server, so the page works before any script runs.
Code
@* Three slides that swipe, scroll with the arrow keys, and move with the buttons and dots. *@
<Carousel Label="Getting started" Grow>
foreach (var (title, text, color) in _slides)
{
<CarouselItem Label="title">
<Stack Gap="2" PaddingY="8" PaddingX="16" Bg="color" Radius="Radius.Md" MinHeight="Length.Rem(12)" Justify="Justify.Center">
<Heading Level="3" Size="TextSize.Lg">title</Heading>
<TextBlock Color="Color.Muted">text</TextBlock>
</Stack>
</CarouselItem>
}
</Carousel>
{
private readonly (string Title, string Text, Color Color)[] _slides =
[
("Install the package", "Add IzzyBlazor from NuGet and register it in Program.cs.", Color.FillStrong),
("Add the stylesheet", "One link in App.razor brings the theme and every component's styles.", Color.SuccessSoft),
("Build a page", "Components render on the server, so the page works before any script runs.", Color.WarningSoft),
];
}Add this example to a page with the izzy CLI:
izzy add component Carousel --at <file>:<line>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.
Static
Preview
Hobby
$0
One project and community support.
Starter
$9
Five projects and email support.
Team
$29
Unlimited projects for up to ten people.
Business
$79
Single sign-on and audit logs.
Enterprise
Custom
A contract, an agreed uptime and a named contact.
Code
@* One card on a phone, two from Sm and three from Xl; the buttons move a page, and it loops. The cards keep their text clear of the buttons. *@
<Carousel Label="Plans" ItemsPerView="new() { Base = 1, Sm = 2, Xl = 3 }" Gap="4" Loop Grow>
foreach (var (name, price, text) in _plans)
{
<CarouselItem Label="name">
<Card Height="Length.Full">
<CardBody PaddingX="12">
<TextBlock Weight="FontWeight.Semibold">name</TextBlock>
<TextBlock Size="TextSize.Xl2" Weight="FontWeight.Bold">price</TextBlock>
<TextBlock Size="TextSize.Sm" Color="Color.Muted">text</TextBlock>
</CardBody>
</Card>
</CarouselItem>
}
</Carousel>
{
private readonly (string Name, string Price, string Text)[] _plans =
[
("Hobby", "$0", "One project and community support."),
("Starter", "$9", "Five projects and email support."),
("Team", "$29", "Unlimited projects for up to ten people."),
("Business", "$79", "Single sign-on and audit logs."),
("Enterprise", "Custom", "A contract, an agreed uptime and a named contact."),
];
}Thumbnails
For a gallery, set Dots to Thumbnails and give each CarouselItem a Thumbnail. A small picture of each slide replaces the dots.
Static
Preview












Code
@* A small picture of each page under the slides, in place of the dots. *@
<Carousel Label="Page screenshots" Dots="CarouselDots.Thumbnails" Loop Grow MaxWidth="Length.Rem(40)">
foreach (var (name, title, alt) in _pages)
{
<CarouselItem Label="title" Thumbnail="($"img/blocks/{name}.webp")" DarkThumbnail="($"img/blocks/{name}-dark.webp")">
<Image Src="($"img/blocks/{name}.webp")" DarkSrc="($"img/blocks/{name}-dark.webp")" Alt="alt" Ratio="16 / 10.0" />
</CarouselItem>
}
</Carousel>
{
private readonly (string Name, string Title, string Alt)[] _pages =
[
("hero", "Home", "The home page's opening section"),
("features", "Features", "The features page"),
("pricing", "Pricing", "The pricing page"),
("articles", "Articles", "The articles page"),
("contact", "Contact", "The contact page"),
("legal", "Terms", "The terms page"),
];
}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.
Always Interactive
Preview
Spring
Summer
Autumn
Winter
C# has slide 1
Code
@* The slide moves in every mode; on an interactive page C# follows it, and can move it. *@
<Stack Gap="3" Grow>
<Carousel Label="Seasons" @bind-Index="_index">
foreach (var season in _seasons)
{
<CarouselItem Label="season">
<Center PaddingY="8" PaddingX="16" Bg="Color.FillSubtle" Radius="Radius.Md" MinHeight="Length.Rem(9)">
<Heading Level="3" Size="TextSize.Lg">season</Heading>
</Center>
</CarouselItem>
}
</Carousel>
<Row Gap="3" Align="Align.Center">
<TextBlock Size="TextSize.Sm" Color="Color.Muted">C# has slide <Code>_index</Code></TextBlock>
<Button Size="ControlSize.Sm" Variant="ButtonVariant.Outline" Accent="Accent.Neutral" OnClick="() => _index = 0">Back to the first</Button>
</Row>
</Stack>
{
private readonly string[] _seasons = ["Spring", "Summer", "Autumn", "Winter"];
private int _index = 1;
}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.
Static
Preview
“The forms worked before the page had finished loading.”
Priya, operations lead
“We moved our admin screens over in a week.”
Tomás, developer
“Our audit found nothing to fix in the components.”
Grace, accessibility consultant
Code
@* Quotes that fade from one to the next every 3 seconds; the last shows for 5. *@
<Carousel Label="What customers say" Autoplay Interval="TimeSpan.FromSeconds(3)" Transition="CarouselTransition.Fade" Loop Grow>
foreach (var (quote, name, last) in _quotes)
{
<CarouselItem Label="name" Interval="(last ? TimeSpan.FromSeconds(5) : null)">
<Stack Gap="3" PaddingY="10" PaddingX="16" Bg="Color.FillSubtle" Radius="Radius.Md" MinHeight="Length.Rem(13)" Justify="Justify.Center">
<TextBlock Size="TextSize.Lg">“quote”</TextBlock>
<TextBlock Size="TextSize.Sm" Color="Color.Muted">name</TextBlock>
</Stack>
</CarouselItem>
}
</Carousel>
{
private readonly (string Quote, string Name, bool Last)[] _quotes =
[
("The forms worked before the page had finished loading.", "Priya, operations lead", false),
("We moved our admin screens over in a week.", "Tomás, developer", false),
("Our audit found nothing to fix in the components.", "Grace, accessibility consultant", true),
];
}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.
CarouselItem: one slide of a Carousel.
Mode support
| Feature | Static | Interactive |
|---|---|---|
| Slides that swipe and scroll a slide at a time, several at once per breakpoint | Yes | Yes |
| Previous and next buttons, and a dot or a thumbnail for each slide | Yes | Yes |
| The slide in view bound to C# | No | Yes |
| Autoplay, with a button that stops and starts it | Yes | Yes |
| Slides that fade from one to the next | Yes | Yes |
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 ownLabel. - 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
| Press this key | To do this |
|---|---|
| Left or Right | Go to the previous or next slide (reversed on right-to-left pages) |
| Home or End | Go to the first or last slide |
On the slides, otherwise
| Press this key | To do this |
|---|---|
| Left or Right | Scroll the slides, with the browser's own keys |
Parameters
| Prop | Type | Default |
|---|---|---|
LabelWhat the carousel shows, such as "Featured trips": its accessible name. | string | Required |
@bind-IndexThe slide in view (the first, when several show), from 0. | int | 0 |
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. | bool | false |
ArrowsShows the previous and next buttons. | bool | true |
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. | CarouselDots | CarouselDots.Auto |
AutoplayMoves on a slide every Interval, from the last back to the first, with a button that stops and starts it. | bool | false |
IntervalHow long each slide shows with Autoplay. | TimeSpan | TimeSpan.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. | CarouselTransition | CarouselTransition.Slide |
ChildContentThe CarouselItems. | RenderFragment? |
Plus 27 surface props, 17 item props and 4 common props.
Full APISee 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.