Skip to main content
twblazor
Home
  • Get started
  • Tailwind with Blazor
  • Why twblazor?
  • Theme
  • Class Merge
    • Configuring localization
    • RTL Provider
  • Breadcrumb
  • Card
  • Carousel
  • Collapse
  • Context Menu
  • Drawer
  • Footer
  • Menu
  • Navbar
  • On This Page
  • Separator
  • Sidebar
  • Stepper
  • Tabs
  • Tree List
  • Container
  • Flex
  • Grid
  • Text
  • Link
  • Button
  • Form
    • AutocompleteNew
    • Checkbox
    • Color Picker
    • Date Picker
    • Date Range Picker
    • Datetime Picker
    • Datetime Range Picker
    • File Upload
    • Input GroupNew
    • NumericNew
    • Masked InputNew
    • Radio Button
    • Range SliderNew
    • RatingNew
    • Select
    • Slider
    • Switch
    • Tag InputNew
    • Text EditorNew
    • Textfield
    • Time Picker
    • Time Range Picker
  • Toggle
  • Toggle Group
  • Alert
  • Avatar
  • Badge
  • Chip
  • Empty
  • Icon
  • Popover
  • Progress
  • Skeleton
  • Spinner
  • Tooltip
  • Data Table
  • SpreadsheetNew
  • Column Filter Editor
  • Pagination
  • Pick List
  • Barcode
  • QR Code
  • Calendar
  • Table
  • Attachment
  • Overview
    • Bar
    • Bullet
    • Column
    • Dot Plot
    • Dumbbell
    • Icon
    • Lollipop
    • Radial Bar
    • Range
    • Word Cloud
    • Area
    • Bump
    • Bump Area
    • Candlestick
    • Gantt
    • Horizon
    • Line
    • Slope
    • Small Multiples
    • Stream Graph
    • Funnel
    • Gauge
    • Marimekko
    • Nightingale
    • Pie
    • Treemap
    • Waffle
    • Waterfall
    • Circular Treemap
    • Convex Treemap
    • Dendrogram
    • Sunburst
    • Barcode
    • Beeswarm
    • Box Plot
    • Density Plot
    • Histogram
    • Radial Histogram
    • Ridgeline
    • Strip Plot
    • Violin Plot
    • Categorical Scatter
    • Contour
    • Hexagonal Binning
    • Quadrant
    • Scatter
    • Heatmap
    • Matrix
    • Parallel Coordinates
    • Radar
    • Arc Diagram
    • Chord Diagram
    • Flowchart
    • Network Diagram
    • Sankey
    • Euler Diagram
    • Venn Diagram
  • Bubble
  • Marker
  • Message
  • Dialog Service
  • Toast Service
API DocumentationAI Agents & Skills
Home Get Started

Layout

TwCarousel

TwCarousel is a Blazor carousel component. Bind SelectedIndex and configure AutoPlay, AutoPlayInterval, Loop, ShowArrows, ShowIndicators and swipe gestures.

Last updated 21 October 2026

Basic carousel

Use TwCarousel and TwCarouselItem to cycle through a set of slides. Only the active slide is rendered.
Slide 1
RAZOR
<TwCarousel AriaLabel="Example carousel 1" Style="height:240px;">
    <TwCarouselItem>
        <div class="flex h-full items-center justify-center bg-purple-600 text-white text-xl font-semibold">Slide 1</div>
    </TwCarouselItem>
    <TwCarouselItem>
        <div class="flex h-full items-center justify-center bg-fuchsia-600 text-white text-xl font-semibold">Slide 2</div>
    </TwCarouselItem>
    <TwCarouselItem>
        <div class="flex h-full items-center justify-center bg-blue-600 text-white text-xl font-semibold">Slide 3</div>
    </TwCarouselItem>
</TwCarousel>

Images: object fit

When a slide's content (e.g. an <img>) doesn't match the carousel's aspect ratio, use Tailwind's object-fit utilities to control how it fills the slide's h-full w-full space.
Placeholder 1
RAZOR
<div class="flex flex-wrap gap-2 mb-4">
    @foreach (var fit in _objectFitOptions)
    {
        <TwButton Label="@fit.Label" Color="Color.Primary" Variant="@(selectedObjectFit == fit.Class ? ButtonVariant.Filled : ButtonVariant.Outlined)" OnClick="@(() => selectedObjectFit = fit.Class)" />
    }
</div>
<TwCarousel AriaLabel="Example carousel 2" Style="height:500px;">
    <TwCarouselItem>
        <img src="_content/TwBlazor.Docs/images/placeholder-1.webp" alt="Placeholder 1" class="@($"h-full w-full {selectedObjectFit}")" />
    </TwCarouselItem>
    <TwCarouselItem>
        <img src="_content/TwBlazor.Docs/images/placeholder-2.webp" alt="Placeholder 2" class="@($"h-full w-full {selectedObjectFit}")" />
    </TwCarouselItem>
    <TwCarouselItem>
        <img src="_content/TwBlazor.Docs/images/placeholder-3.webp" alt="Placeholder 3" class="@($"h-full w-full {selectedObjectFit}")" />
    </TwCarouselItem>
    <TwCarouselItem>
        <img src="_content/TwBlazor.Docs/images/placeholder-4.webp" alt="Placeholder 4" class="@($"h-full w-full {selectedObjectFit}")" />
    </TwCarouselItem>
</TwCarousel>
CSHARP
@code {
    private static readonly (string Label, string Class)[] _objectFitOptions =
    [
        ("Cover", "object-cover"),
        ("Contain", "object-contain"),
        ("Fill", "object-fill"),
        ("None", "object-none"),
        ("Scale Down", "object-scale-down"),
    ];
    
    private string selectedObjectFit = "object-cover";
}

Autoplay

Set AutoPlay to automatically advance slides. A pause/play control is always shown so playback can be stopped, and it also pauses automatically while hovered or focused.
Slide 1
RAZOR
<TwCarousel AriaLabel="Example carousel 3" Style="height:240px;" AutoPlay AutoPlayInterval="TimeSpan.FromSeconds(3)">
    <TwCarouselItem>
        <div class="flex h-full items-center justify-center bg-green-800 text-white text-xl font-semibold">Slide 1</div>
    </TwCarouselItem>
    <TwCarouselItem>
        <div class="flex h-full items-center justify-center bg-yellow-600 text-white text-xl font-semibold">Slide 2</div>
    </TwCarouselItem>
    <TwCarouselItem>
        <div class="flex h-full items-center justify-center bg-red-600 text-white text-xl font-semibold">Slide 3</div>
    </TwCarouselItem>
</TwCarousel>

Indicator color

Set Color to customize the active slide indicator's color.
Slide 1
RAZOR
<TwCarousel AriaLabel="Example carousel 4" Style="height:240px;" Color="Color.Success">
    <TwCarouselItem>
        <div class="flex h-full items-center justify-center bg-gray-700 text-white text-xl font-semibold">Slide 1</div>
    </TwCarouselItem>
    <TwCarouselItem>
        <div class="flex h-full items-center justify-center bg-gray-800 text-white text-xl font-semibold">Slide 2</div>
    </TwCarouselItem>
    <TwCarouselItem>
        <div class="flex h-full items-center justify-center bg-gray-900 text-white text-xl font-semibold">Slide 3</div>
    </TwCarouselItem>
</TwCarousel>

Without arrows or indicators

Set ShowArrows and ShowIndicators to false to rely on swipe gestures or programmatic navigation only.
Slide 1
RAZOR
<TwCarousel AriaLabel="Example carousel 5" Style="height:240px;" ShowArrows="false" ShowIndicators="false">
    <TwCarouselItem>
        <div class="flex h-full items-center justify-center bg-indigo-600 text-white text-xl font-semibold">Slide 1</div>
    </TwCarouselItem>
    <TwCarouselItem>
        <div class="flex h-full items-center justify-center bg-teal-600 text-white text-xl font-semibold">Slide 2</div>
    </TwCarouselItem>
</TwCarousel>

Non-looping

Set Loop to false to disable the arrow buttons at the first and last slide instead of wrapping around.
Slide 1
RAZOR
<TwCarousel AriaLabel="Example carousel 6" Style="height:240px;" Loop="false">
    <TwCarouselItem>
        <div class="flex h-full items-center justify-center bg-orange-800 text-white text-xl font-semibold">Slide 1</div>
    </TwCarouselItem>
    <TwCarouselItem>
        <div class="flex h-full items-center justify-center bg-pink-600 text-white text-xl font-semibold">Slide 2</div>
    </TwCarouselItem>
    <TwCarouselItem>
        <div class="flex h-full items-center justify-center bg-cyan-600 text-white text-xl font-semibold">Slide 3</div>
    </TwCarouselItem>
</TwCarousel>

Bound selected index

Bind SelectedIndex to control or observe the active slide from outside the carousel.

Selected slide: 1

Slide 1
RAZOR
<p class="mb-2">Selected slide: @(selectedIndex + 1)</p>
<TwCarousel AriaLabel="Example carousel 7" Style="height:240px;" @bind-SelectedIndex="selectedIndex">
    <TwCarouselItem>
        <div class="flex h-full items-center justify-center bg-purple-700 text-white text-xl font-semibold">Slide 1</div>
    </TwCarouselItem>
    <TwCarouselItem>
        <div class="flex h-full items-center justify-center bg-purple-800 text-white text-xl font-semibold">Slide 2</div>
    </TwCarouselItem>
    <TwCarouselItem>
        <div class="flex h-full items-center justify-center bg-purple-900 text-white text-xl font-semibold">Slide 3</div>
    </TwCarouselItem>
</TwCarousel>

Custom previous/next controls

Set LeftNavigation and RightNavigation to render your own previous/next controls instead of the default arrow buttons. Each is a RenderFragment<TwCarousel>, so its context exposes the carousel's public API (PreviousSlide, NextSlide, GoToSlide, ToggleAutoPlayPaused, and more) for your own markup to call.
Slide 1
RAZOR
<TwCarousel AriaLabel="Example carousel 8" Style="height:240px;">
    <LeftNavigation>
        <TwButton Plain Class="absolute bottom-3 start-3 z-10 px-3 py-1.5 rounded-md bg-white text-purple-700 text-xs font-bold uppercase tracking-wide shadow-lg hover:bg-purple-50 transition-colors" AriaLabel="Previous slide" OnClick="context.PreviousSlide">
            Previous
        </TwButton>
    </LeftNavigation>
    <RightNavigation>
        <TwButton Plain Class="absolute bottom-3 end-3 z-10 px-3 py-1.5 rounded-md bg-white text-purple-700 text-xs font-bold uppercase tracking-wide shadow-lg hover:bg-purple-50 transition-colors" AriaLabel="Next slide" OnClick="context.NextSlide">
            Next
        </TwButton>
    </RightNavigation>
    <ChildContent>
        <TwCarouselItem>
            <div class="flex h-full items-center justify-center bg-purple-600 text-white text-xl font-semibold">Slide 1</div>
        </TwCarouselItem>
        <TwCarouselItem>
            <div class="flex h-full items-center justify-center bg-fuchsia-600 text-white text-xl font-semibold">Slide 2</div>
        </TwCarouselItem>
        <TwCarouselItem>
            <div class="flex h-full items-center justify-center bg-blue-600 text-white text-xl font-semibold">Slide 3</div>
        </TwCarouselItem>
    </ChildContent>
</TwCarousel>

Custom indicators

Set Indicators to render your own slide-picker controls instead of the default dots. Its context exposes SelectedIndex and GoToSlide so your markup can both reflect and drive the active slide.
Slide 1
RAZOR
<TwCarousel AriaLabel="Example carousel 9" Style="height:240px;">
    <Indicators>
        <div class="absolute bottom-2 inset-x-0 z-10 w-fit mx-auto flex justify-center gap-2">
            @for (var i = 0; i < 3; i++)
            {
                var index = i;
                <TwButton Plain Class="@(index == context.SelectedIndex ? "size-7 rounded-md bg-purple-600 text-white text-xs font-bold" : "size-7 rounded-md bg-gray-200 dark:bg-gray-700 text-gray-700 dark:text-gray-200 text-xs font-bold hover:bg-gray-300 dark:hover:bg-gray-600")" AriaLabel="@($"Slide {index + 1} of 3")" aria-current="@(index == context.SelectedIndex ? "true" : "false")" OnClick="@(() => context.GoToSlide(index))">
                    @(index + 1)
                </TwButton>
            }
        </div>
    </Indicators>
    <ChildContent>
        <TwCarouselItem>
            <div class="flex h-full items-center justify-center bg-orange-800 text-white text-xl font-semibold">Slide 1</div>
        </TwCarouselItem>
        <TwCarouselItem>
            <div class="flex h-full items-center justify-center bg-pink-600 text-white text-xl font-semibold">Slide 2</div>
        </TwCarouselItem>
        <TwCarouselItem>
            <div class="flex h-full items-center justify-center bg-cyan-600 text-white text-xl font-semibold">Slide 3</div>
        </TwCarouselItem>
    </ChildContent>
</TwCarousel>

Keyboard navigation

The arrow keys change slide from anywhere in the carousel, except while you are typing in a field or using a control inside a slide that needs them. An automatic slideshow pauses while the carousel has focus, and starts paused for anyone who has asked their system for reduced motion.
Key What it does
Tab or Shift+ plus Tab Moves through the pause button (when the slideshow plays automatically), the slide's own controls, the previous and next buttons, and the slide indicators.
Arrow Left or Arrow Right Shows the previous or next slide. The two keys swap in a right to left layout.
Enter or Space Presses the focused button: pause or play, previous, next, or a slide indicator.

Theme configuration

Styling is controlled by TwBlazorTheme.Components (a TwCarouselTheme), configured via the AddTwBlazor() options callback described on the Get Started page. Every property is a set of Tailwind classes, so changes are picked up by your own Tailwind build.
Property Type Controls
Container string
Viewport string
Slide string
SlideContent string
ArrowButton string
ArrowButtonStart string
ArrowButtonEnd string
PlayPauseButton string
IndicatorContainer string
Indicator string
IndicatorActive string
IndicatorInactive string

Full reference: TwCarouselTheme on the API docs.

On this page

  • Basic carousel
  • Images: object fit
  • Autoplay
  • Indicator color
  • Without arrows or indicators
  • Non-looping
  • Bound selected index
  • Custom previous/next controls
  • Custom indicators
  • Keyboard navigation
  • Theme configuration
twblazor

The Tailwind CSS component library for Blazor. Accessible, themeable and MIT licensed.

Discord (opens in a new tab) GitHub(opens in a new tab)

Get started

  • Install guide
  • Theming
  • Class merging
  • Localization

Guides

  • Tailwind CSS with Blazor
  • Why twblazor?
  • Right to left
  • AI agents and skills

Resources

  • API documentation (opens in a new tab)
  • llms.txt (opens in a new tab)
  • MIT License (opens in a new tab)

Community

  • Contributing (opens in a new tab)
  • Code of conduct (opens in a new tab)
  • Report an issue (opens in a new tab)

twblazor is and always will be free and open source.

An unhandled error has occurred. Reload