Skip to main content

Usage

The Carousel component provides a flexible way to display content in a scrollable carousel format. It uses Embla Carousel under the hood.
<template>
  <UCarousel
    :items="items"
    arrows
    dots
  >
    <template #default="{ item }">
      <img :src="item.image" :alt="item.title" />
    </template>
  </UCarousel>
</template>

<script setup lang="ts">
const items = [
  { image: '/img/slide1.jpg', title: 'Slide 1' },
  { image: '/img/slide2.jpg', title: 'Slide 2' },
  { image: '/img/slide3.jpg', title: 'Slide 3' }
]
</script>

Orientation

Control the carousel direction with the orientation prop.
<UCarousel
  :items="items"
  orientation="vertical"
  arrows
>
  <template #default="{ item }">
    <div>{{ item.title }}</div>
  </template>
</UCarousel>

Arrows

Enable navigation arrows with the arrows prop.
<UCarousel :items="items" arrows>
  <template #default="{ item }">
    <div>{{ item.content }}</div>
  </template>
</UCarousel>
Customize the arrow buttons:
<UCarousel
  :items="items"
  arrows
  :prev="{ color: 'primary', variant: 'solid' }"
  :next="{ color: 'primary', variant: 'solid' }"
  prev-icon="i-heroicons-chevron-left"
  next-icon="i-heroicons-chevron-right"
>
  <template #default="{ item }">
    <div>{{ item.content }}</div>
  </template>
</UCarousel>

Dots

Enable dot indicators with the dots prop.
<UCarousel :items="items" dots>
  <template #default="{ item }">
    <div>{{ item.content }}</div>
  </template>
</UCarousel>

Plugins

Embla Carousel supports various plugins that can be enabled through props.

Autoplay

Enable autoplay to automatically cycle through slides.
<UCarousel :items="items" :autoplay="{ delay: 3000 }">
  <template #default="{ item }">
    <div>{{ item.content }}</div>
  </template>
</UCarousel>

Auto Scroll

Enable auto scroll for continuous scrolling.
<UCarousel :items="items" :auto-scroll="{ speed: 1 }">
  <template #default="{ item }">
    <div>{{ item.content }}</div>
  </template>
</UCarousel>

Fade

Enable fade transition between slides.
<UCarousel :items="items" fade>
  <template #default="{ item }">
    <div>{{ item.content }}</div>
  </template>
</UCarousel>

Events

Listen to the select event to track when the selected slide changes.
<UCarousel :items="items" @select="onSelect">
  <template #default="{ item }">
    <div>{{ item.content }}</div>
  </template>
</UCarousel>

<script setup lang="ts">
function onSelect(index: number) {
  console.log('Selected slide:', index)
}
</script>

Props

as
any
default:"'div'"
The element or component this component should render as.
items
CarouselItem[]
Array of items to display in the carousel.
orientation
'horizontal' | 'vertical'
default:"'horizontal'"
The orientation of the carousel.
arrows
boolean
default:"false"
Display prev and next buttons to scroll the carousel.
dots
boolean
default:"false"
Display dots to scroll to a specific slide.
prev
ButtonProps
Configure the prev button when arrows are enabled.
prevIcon
string
default:"appConfig.ui.icons.arrowLeft"
The icon displayed in the prev button.
next
ButtonProps
Configure the next button when arrows are enabled.
nextIcon
string
default:"appConfig.ui.icons.arrowRight"
The icon displayed in the next button.

Embla Options

align
'start' | 'center' | 'end'
default:"'center'"
Align slides within the viewport.
loop
boolean
default:"false"
Enable infinite looping.
slidesToScroll
number
default:"1"
Number of slides to scroll at once.
dragFree
boolean
default:"false"
Enable free dragging without scroll snapping.
containScroll
'trimSnaps' | 'keepSnaps' | false
default:"'trimSnaps'"
Contain scroll to viewport.

Plugins

autoplay
boolean | AutoplayOptionsType
default:"false"
Enable Autoplay plugin. See Embla Autoplay docs.
autoScroll
boolean | AutoScrollOptionsType
default:"false"
Enable Auto Scroll plugin. See Embla Auto Scroll docs.
autoHeight
boolean | AutoHeightOptionsType
default:"false"
Enable Auto Height plugin. See Embla Auto Height docs.
classNames
boolean | ClassNamesOptionsType
default:"false"
Enable Class Names plugin. See Embla Class Names docs.
fade
boolean | FadeOptionsType
default:"false"
Enable Fade plugin. See Embla Fade docs.
wheelGestures
boolean | WheelGesturesPluginOptions
default:"false"
Enable Wheel Gestures plugin. See Embla Wheel Gestures docs.
class
any
Custom class to apply to the root element.
ui
Partial<typeof theme>
Override default theme classes.

Slots

default
{ item: T, index: number }
Slot for rendering each carousel item.

Emits

select
(selectedIndex: number) => void
Emitted when the selected slide changes.

Expose

emblaRef
Ref<HTMLElement>
Reference to the Embla viewport element.
emblaApi
Ref<EmblaCarouselType>
Reference to the Embla API instance.

Build docs developers (and LLMs) love