Skip to content
Nana UI

Carousel

View .md Download

A scroll-snap carousel. Compose it from nana-carousel-item slides and pick the navigation, layout and behaviour through attributes — one element covers basic, multi-item, card, gallery, hero and testimonial use-cases. Built on the native scroll container, so touch swipe, trackpad and momentum work for free; mouse drag, keyboard, autoplay and looping are layered on top.

Slide A Slide B
Terminal window
npm install @nana-tec/ui-components
import "@nana-tec/ui-components/carousel";
<nana-carousel style="width:100%">
<nana-carousel-item><img src="https://picsum.photos/seed/a/800/400" alt="Slide A" style="width:100%;display:block"></nana-carousel-item>
<nana-carousel-item><img src="https://picsum.photos/seed/b/800/400" alt="Slide B" style="width:100%;display:block"></nana-carousel-item>
</nana-carousel>

The navigation attribute controls the controls — arrows, dots, progress, numbers, or a space-separated combo. Add loop to wrap around.

Slide 1 Slide 2 Slide 3

Show several slides at once with slides-per-view, and hint the next slide with peek.

Item 1 Item 2 Item 3 Item 4 Item 5

Properties

PropertyAttributeTypeDefaultDescription
ariaLabelaria-labelstring | null'Carousel'Accessible label for the carousel region
autoplaybooleanfalseAdvance automatically
disabledbooleanfalseDisable all interaction
draggablebooleantrueAllow mouse drag-to-scroll
errorstring | undefinedError message — replaces the track with an alert
intervalnumber5000Autoplay interval (ms)
loadingbooleanfalseShow a loading skeleton instead of slides
loadingCountloading-countnumber3Number of skeleton slides while loading
loopbooleanfalseWrap around at the ends
navigationstring'arrows dots'Navigation controls — combine with spaces, e.g. "arrows dots"
orientationCarouselOrientation'horizontal'Scroll axis
pauseOnHoverpause-on-hoverbooleantruePause autoplay on hover / focus
peekbooleanfalseShow a peek of the adjacent slides (single-view only)
slidesPerViewslides-per-viewnumber1Slides visible at once (multi-item / cards)
variantCarouselVariant'default'Visual style

Events

EventDescription
nana-slide-changeFired when the active slide changes (`detail.index`, `detail.total`)

Slots

SlotDescription
(default)One or more `nana-carousel-item` slides
errorCustom error content (shown when `error` is set)

CSS parts

PartDescription
::part(base)The outer container
::part(viewport)The scrolling track
::part(nav-prev)The previous-slide button
::part(nav-next)The next-slide button
::part(pagination)The dots / numbers / progress row

CSS custom properties

PropertyDescription
--nana-carousel-gapGap between slides
--nana-carousel-radiusViewport corner radius
--nana-carousel-accentActive dot / progress colour
--nana-carousel-peekHow much of the neighbour peeks (peek mode)
--nana-carousel-heightViewport height (vertical orientation)
EventTypeDescription
nana-slide-changeCustomEventFired when the active slide changes (detail.index, detail.total)
SlotDescription
(default)One or more nana-carousel-item slides
errorCustom error content (shown when error is set)
VariableDefaultDescription
--nana-carousel-gapGap between slides
--nana-carousel-radiusViewport corner radius
--nana-carousel-accentActive dot / progress colour
--nana-carousel-peekHow much of the neighbour peeks (peek mode)
--nana-carousel-heightViewport height (vertical orientation)
PartDescription
baseThe outer container
viewportThe scrolling track
nav-prevThe previous-slide button
nav-nextThe next-slide button
paginationThe dots / numbers / progress row
  • Keyboard accessible
  • Screen-reader labels
  • Focus-visible states
  • ARIA roles and states
  • WCAG 2.2 AA contrast
Explore Carousel interactively Every state, prop, and edge case — with live controls — in Storybook.
View in Storybook