Liking cljdoc? Tell your friends :D

x-carousel

A themeable, accessible carousel (slideshow) component with swipe/drag navigation, arrow buttons, dot indicators, autoplay, keyboard interaction, and support for slide/fade transitions and horizontal/vertical orientation.


Tag

<x-carousel></x-carousel>

Attributes

AttributeTypeDefaultDescription
autoplaybooleanfalseEnable auto-advance
intervalnumber5000Auto-advance interval in ms (minimum 100)
loopbooleanfalseWrap around at ends
arrowsboolean*trueShow prev/next arrow buttons
dotsboolean*trueShow dot indicators
disabledbooleanfalseDisable all interaction
currentnumber0Zero-based current slide index
transitionenum"slide""slide" or "fade"
directionenum"horizontal""horizontal" or "vertical"
peekCSS length"0px"Show edges of adjacent slides (e.g. "40px")
aria-labelstring"Carousel"Accessible label for the carousel region

*arrows and dots use default-true semantics: absent or empty = true; "false" = false.


Properties

PropertyTypeRead-onlyReflects attribute
currentSlidenumbernocurrent
autoplaybooleannoautoplay
intervalnumbernointerval
loopbooleannoloop
arrowsbooleannoarrows
dotsbooleannodots
disabledbooleannodisabled
transitionstringnotransition
directionstringnodirection
peekstringnopeek
slideCountnumberyes-

Events

EventBubblesComposedCancelableDetail
x-carousel-changeyesyesyes{ index, previousIndex, reason }

detail.reason values: "arrow", "dot", "drag", "keyboard", "autoplay", "api".

Calling preventDefault() on the event prevents the slide change.


Methods

MethodDescription
next()Navigate to the next slide
previous()Navigate to the previous slide
goTo(index)Navigate to a specific slide

Slots

SlotDescription
(default)Slide content. Each direct child becomes a slide

Parts

PartDescription
viewportScrollable viewport container
trackFlex/grid track holding all slides
prev-btnPrevious slide arrow button
next-btnNext slide arrow button
dotsDot indicator container
dotIndividual dot indicator button

CSS Custom Properties

PropertyDefaultDescription
--x-carousel-height300pxViewport height
--x-carousel-arrow-size40pxArrow button size
--x-carousel-arrow-bgvar(--x-color-surface, ...)Arrow background
--x-carousel-arrow-colorvar(--x-color-text, ...)Arrow icon color
--x-carousel-arrow-hover-bgvar(--x-color-surface-hover, ...)Arrow hover bg
--x-carousel-dot-size10pxDot indicator size
--x-carousel-dot-colorvar(--x-color-border, ...)Inactive dot color
--x-carousel-dot-active-colorvar(--x-color-primary, ...)Active dot color
--x-carousel-transition-durationvar(--x-transition-duration, 300ms)Slide/fade duration
--x-carousel-radiusvar(--x-radius-md, 8px)Border radius
--x-carousel-gap16pxDot gap spacing
--x-carousel-focus-ringvar(--x-color-focus-ring, #60a5fa)Focus ring color
--x-carousel-disabled-opacity0.5Opacity when disabled

Accessibility

  • Host has role="region" and aria-roledescription="carousel"
  • Viewport is focusable (tabindex="0")
  • Arrow buttons have descriptive aria-label values
  • Dot indicators use role="tab" with aria-current and aria-label
  • Live region announces current slide (set to aria-live="off" during autoplay)
  • Dots container has aria-orientation matching the carousel direction

Keyboard

KeyHorizontalVertical
ArrowLeftPrevious slide-
ArrowRightNext slide-
ArrowUp-Previous slide
ArrowDown-Next slide
HomeFirst slideFirst slide
EndLast slideLast slide

Transition Modes

Slide (default)

Slides are positioned in a flex row (or column for vertical). Navigation applies transform: translateX/Y() on the track element with a CSS transition.

Drag/swipe is supported in slide mode. The carousel detects swipe direction based on distance and velocity.

Fade

Slides are stacked and cross-fade using opacity. No drag support in fade mode.

The direction attribute is ignored in fade mode.


Peek Mode

Set peek="40px" (or any CSS length) to reveal the edges of adjacent slides, hinting that more content is available.


Autoplay

When autoplay is set, the carousel advances automatically at the interval rate.

Autoplay pauses on:

  • Pointer hover over the carousel
  • Keyboard focus inside the carousel
  • Active drag interaction

Examples

Basic carousel

<x-carousel>
  <img src="slide1.jpg" alt="Slide 1">
  <img src="slide2.jpg" alt="Slide 2">
  <img src="slide3.jpg" alt="Slide 3">
</x-carousel>

Autoplay with loop

<x-carousel autoplay interval="3000" loop aria-label="Product showcase">
  <div>Slide 1</div>
  <div>Slide 2</div>
  <div>Slide 3</div>
</x-carousel>

Fade transition

<x-carousel transition="fade">
  <div>Slide 1</div>
  <div>Slide 2</div>
</x-carousel>

Vertical carousel

<x-carousel direction="vertical" style="--x-carousel-height: 400px;">
  <div>Slide 1</div>
  <div>Slide 2</div>
</x-carousel>

Peek mode

<x-carousel peek="40px">
  <div>Slide 1</div>
  <div>Slide 2</div>
  <div>Slide 3</div>
</x-carousel>

Prevent navigation programmatically

document.querySelector('x-carousel').addEventListener('x-carousel-change', e => {
  if (e.detail.index === 2) e.preventDefault(); // block slide 2
});

ClojureScript (hiccup)

[:x-carousel {:autoplay true :loop true :interval 4000}
 [:div "Slide 1"]
 [:div "Slide 2"]
 [:div "Slide 3"]]

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close