hydroxy

Carousel

Slides in a scroll-snap strip. Swipe, scroll, use the arrow keys, or press the buttons and dots. Optional autoplay pauses on hover and focus, and never starts under reduced motion.

Slide 1 of 4

Usage

use hydroxy_leptos::carousel::{Carousel, Slide};
use leptos::prelude::*;

fn card(title: &'static str, body: &'static str, tint: &'static str) -> impl IntoView {
    view! {
        <div style=format!("display: grid; align-content: center; gap: var(--space-2); height: 180px; padding: var(--space-8); background: {tint};")>
            <strong style="font: var(--text-h3); color: var(--text-1);">{title}</strong>
            <span style="font: var(--text-sm); color: var(--text-2);">{body}</span>
        </div>
    }
}

pub fn demo() -> AnyView {
    let (index, set_index) = signal(0_usize);

    view! {
        <div style="display: grid; gap: var(--space-8);">
            // Controlled, stops at the ends.
            <div style="display: grid; gap: var(--space-3);">
                <Carousel
                    label="Release highlights"
                    slides=vec![
                        Slide::new(|| card("Faster search", "Results appear as you type.", "var(--accent-soft)")),
                        Slide::new(|| card("Shared boards", "Invite a teammate to any board.", "var(--status-info-soft)")),
                        Slide::new(|| card("Dark mode", "Follows your system setting.", "var(--status-success-soft)")),
                        Slide::new(|| card("Keyboard first", "Every action has a shortcut.", "var(--status-warning-soft)")),
                    ]
                    index=index
                    on_index_change=move |i| set_index.set(i)
                />
                <p style="margin: 0; font: var(--text-label); color: var(--text-3);">{move || format!("Slide {} of 4", index.get() + 1)}</p>
            </div>

            // Looping, with autoplay that pauses on hover and focus.
            <Carousel
                label="Customer stories"
                looping=true
                autoplay_ms=4000
                slides=vec![
                    Slide::new(|| card("“It paid for itself in a week.”", "Maya, ops lead", "var(--surface-sunken)")),
                    Slide::new(|| card("“We stopped using spreadsheets.”", "Jon, finance", "var(--accent-soft)")),
                    Slide::new(|| card("“Setup took ten minutes.”", "Priya, founder", "var(--status-info-soft)")),
                ]
            />
        </div>
    }
    .into_any()
}

Anatomy

Componentdata-partRenders
Carouselrootrole=region, aria-roledescription=carousel
viewportScroll-snap strip, tabindex=0. aria-live is off while autoplay is running
sliderole=group, aria-roledescription=slide, labelled "2 of 4". Slides other than the current one are inert. data-state=current|idle
controlsRow holding the buttons and dots
prev, nextButtons. Disabled at the ends unless looping
dotsOne button per slide, aria-current on the current one
playPause and play button. Only rendered with autoplay

Keyboard

KeyDoes
ArrowLeft / ArrowRightPrevious or next slide
Home / EndFirst or last slide
TabMoves through the viewport, the buttons and the dots

Props

PropTypeNotes
slidesVec<Slide>Required. Slide::new(content)
labelStringAccessible name. Default "Carousel"
indexOption<usize>Controlled slide. Pair with on_index_change
default_indexusizeInitial slide when uncontrolled
loopingboolWrap past the first and last slide
autoplay_msOption<u32>Advance this often. Pauses on hover and focus. Autoplay wraps
on_index_changeCallback<usize>Called as the slide changes, including after a swipe
Actions
Button
Icon button
Toolbar
Theme menu
Display
Avatar
Badge
Card
Chip
Code block
Markdown
Doc card
Due pill
Kbd
Priority mark
Source chip
Space icon
Status diamond
Tag
Value diff
Carousel
Reveal
Media timeline
QR code
Transcript viewer
Audio waveform
Audio player
Forms
Calendar
Checkbox
Combobox
Date picker
Color picker
Cron builder
Theme editor
Mention input
Signature pad
Image cropper
Date field
Date range picker
Duration field
Quantity stepper
Filter chip
Input
Markdown editor
Radio group
Search field
Segmented control
Select
Slider
Range slider
Rating
Toggle button
File dropzone
Upload queue
Attachment
Switch
Tags input
Number field
Money field
Phone field
Time field
OTP input
Password field
Questionnaire
Availability picker
Voice input
Recording control
Inline edit
Async validated input
Shortcut recorder
Data
Spreadsheet grid
Week scheduler
Virtual list
Stat card
Step track
Kanban board
Sortable list
Filter builder
Data table
Grid
Access editor
File manager
Gantt chart
Log stream
Diff viewer
JSON inspector
Terminal
Node editor
Whiteboard
Navigation
Table of contents
Breadcrumb
Tabs
Wizard
Nav item
Nav section
Tree view
Pagination
Menubar
Navigation menu
Saved views
Layout
Master detail
App shell
Sidebar layout
Resizable panels
Dashboard layout
Dock layout
Feedback
Callout
Check list
Empty state
Progress bar
Toast
Approval card
Skeleton
Notification center
Bars
Bar chart
Diverging bar chart
Span chart
Pictogram chart
Stacked bar chart
Funnel chart
Bullet chart
Waffle chart
Marimekko chart
Dot plot chart
Error bar chart
Pareto chart
Waterfall chart
Lollipop chart
Grouped bar chart
Bar race chart
KPIs and frames
Chart frame
Metric card
Sparkline
Points
Scatter chart
Smith chart
Strip plot
Beeswarm chart
Parallel coordinates
Ternary chart
Bland-Altman chart
Quiver chart
Connected scatter chart
Grids and tables
Heatmap chart
Chart table
Cohort chart
Radial
Radial charts
Radar chart
Polar area chart
Stat ring
Clock chart
Spiral chart
Lines and areas
Bump chart
Slope chart
Line chart
Composed chart
Small multiples
Cycle plot chart
Horizon chart
Stacked area chart
Threshold chart
Split line chart
Linked charts
Confidence band chart
Forecast fan chart
Step chart
Range area chart
Distributions
Contour chart
Histogram
Box plot
Density chart
Ridgeline chart
Violin chart
Q-Q chart
Survival chart
ECDF chart
Raincloud plot
Forest plot
Maps
Geo map
Bubble map
Hexbin map
Cartogram
Flow map
Parts of a whole
Donut chart
Voronoi treemap
Nested donut chart
Treemap chart
Sunburst chart
Bubble pack chart
Icicle chart
Flame graph chart
Pie chart
Word cloud
Relationships
Sankey chart
Network chart
Chord chart
UpSet chart
Venn chart
Alluvial chart
Adjacency matrix chart
Dependency graph chart
Tree chart
Arc diagram
Hive plot
Edge bundling
Finance
Candlestick chart
OHLC chart
Depth chart
Renko chart
Time
Timeline chart
Calendar heatmap chart
Spectrogram chart
Marey chart
Overlays
Tour
Lightbox
Alert dialog
Command palette
Dialog
Menu
Popover
Tooltip
Sheet
Hover card
Context menu
Utilities
Pacer
Hotkeys
Disclosure
Accordion
Collapsible
Chat
Chat bubble
Voice session
Composer
Thread
Thread list
Assistant composer
Assistant MCP
Assistant modal
Assistant thread
Assistant thread list
Message scroller
Insight note
Emoji picker
Tool trace
Model picker
Citation popover
Activity
Activity feed
Comment thread
Timeline
Presence bar
Live cursors
Reaction bar
Guides
Getting started
All components
All charts