Carousel
Slides, indicators, arrows, fade, auto-scrolling and control via Svelte ref.
When to use
Carousel displays multiple equal images or cards in a limited area. Important actions and information should remain available without waiting for automatic changes. Tabs is suitable for explicitly selecting named sections.
Slides and transitions
items describes slides with children, class/style and, if necessary, width. children can also be a snippet or an array of contents; items takes precedence. The component does not parse the Svelte snippet as a tree of React elements.
| Problem | Setting | Example |
|---|---|---|
| Show sequence | items |
Main carousel |
| Stop at the borders | arrows, infinite={false} |
Arrows |
| Change the position of points | dotPlacement |
Indicators |
| Replace movement with appearance | effect="fade" |
Transparency |
| Enable time shift | autoplay, autoplaySpeed |
Automatic change |
| Go from external button | bind:ref, goTo |
Methods |
Indexes start from zero. beforeChange reports the current and next index before the transition, afterChange reports the completed one. speed specifies the duration of the transition in milliseconds. Do not consider the callback as confirmation of the network download of the slide content.
Auto scroll and control
autoplay includes a timer; the dotDuration object shows the progress of the current indicator. autoplaySpeed specifies the interval, not the animation speed. Hover and focus can pause the shift via pauseOnHover/pauseOnFocus. In the examples, the launch is explicit so that the documentation page does not move without user selection.
Provide an accessible stop button: pausing only on hover does not help the touch user. External control is available after mount via bind:ref: prev(), next(), goTo(index, dontAnimate). slickGoTo is present in types, but is not a control of the current slide.
innerSlider provides advanced methods and state, including slickPause/slickPlay. It is missing in responsive unslick: check the ref before calling it. RTL retains the indexing features of the original Slick; do not calculate the index on DOM clones.
In vertical mode, RTL does not mirror the flipping direction and does not add an RTL class to the wrapper. When you return to horizontal viewing, RTL styling is applied.
Own controls and adaptability
prevArrow/nextArrow and customPaging - snippets. They receive properties and handlers; move class/style/onClick to your own native buttons. The inaccessible direction has no onClick. appendDots must save the passed hover handlers. Your controls features this composition.
slidesToShow and slidesToScroll set the number of visible and scrollable slides. responsive includes breakpoint rules when mount, so the server geometry may differ from the client one. Don't hide focusable elements by cropping without checking their accessibility.
ConfigProvider.carousel sets the class/style of the internal slider, locale.carousel — the arrow labels. The external node is accessible via bind:nativeElement. Carousel design tokens control the arrows and indicators; semantic classNames/styles are not added to the separate public API.
prefixCls specifies the full local prefix of the Carousel's outer wrapper, its RTL/vertical classes, and progress animation names. The empty string and undefined use ConfigProvider.prefixCls with the -carousel suffix. The Slick classes remain the same: the local prefix does not rename track, slides, arrows, or dots. Carousel prefixes show independent areas, public ref, saving slide, draft and focus. Switching the prefix does not itself trigger a slide change event.
Nested Radio/Checkbox CSS selectors follow the common provider prefix separately from the local Carousel.prefixCls. This does not declare the migration of the Radio and Checkbox prefixes themselves complete. Namespace theme.cssVar.prefix is set independently of the carousel CSS classes.
Examples
Basic carousel
Four slides and indicators; afterChange reports the completed transition.
<script lang="ts">
import { Carousel, type CarouselItem } from '@woodger/antd';
const items = [1, 2, 3, 4].map(number => ({ children: String(number), class: 'gallery-slide' }));
let current = $state(0);
const slides: readonly CarouselItem[] = items;
</script>
<style>
.preview { min-width:0; }
.preview :global(.gallery-slide) {
height:160px;
line-height:160px;
text-align:center;
background:#364d79;
color:#fff;
font-size:28px;
font-weight:600;
}
output {
display: block;
margin-top: 16px;
}
</style>
<div
class="preview"
role="region"
aria-label={("Basic carousel")}
><Carousel
items={(slides)}
afterChange={index => { current = index; }}
/></div>
<output aria-label={("Basic slide")}>{("Slide ")}{(current + 1)}{(" of 4")}</output>
Arrows and borders
When infinite is turned off, it stops transitions on the first and last slides.
<script lang="ts">
import { Carousel, Checkbox } from '@woodger/antd';
const items = [1, 2, 3, 4].map(number => ({ children: String(number), class: 'gallery-slide' }));
let infinite = $state(false);
let current = $state(0);
</script>
<style>
.preview { min-width:0; }
.preview :global(.gallery-slide) {
height:160px;
line-height:160px;
text-align:center;
background:#364d79;
color:#fff;
font-size:28px;
font-weight:600;
}
.controls {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 12px;
margin-bottom: 16px;
}
output {
display: block;
margin-top: 16px;
}
</style>
<div
class="controls"
><Checkbox
bind:checked={infinite}
>{("Loop carousel")}</Checkbox></div>
<div
class="preview"
role="region"
aria-label={("Carousel with arrows")}
><Carousel
items={(items)}
arrows
{infinite}
afterChange={index => { current = index; }}
/></div>
<output aria-label={("Slide with arrows")}>{("Slide ")}{(current + 1)}{(" of 4")}</output>
Indicator position
top, bottom, start and end; Side indicators switch the carousel to vertical mode.
<script lang="ts">
import { Carousel, Select, type DotPlacement } from '@woodger/antd';
const items = [1, 2, 3, 4].map(number => ({ children: String(number), class: 'gallery-slide' }));
let dotPlacement = $state<DotPlacement>('bottom');
</script>
<style>
.preview { min-width:0; }
.preview :global(.gallery-slide) {
height:160px;
line-height:160px;
text-align:center;
background:#364d79;
color:#fff;
font-size:28px;
font-weight:600;
}
.controls {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 12px;
margin-bottom: 16px;
}
</style>
<div
class="controls"
><Select
aria-label={("Indicator position")}
bind:value={dotPlacement}
options={([
{ value: 'top', label: "Top" }, { value: 'bottom', label: "Bottom" },
{ value: 'start', label: "At the beginning" }, { value: 'end', label: "At the end" }
])}
/></div>
<div class="preview"><Carousel items={(items)} {dotPlacement} arrows /></div>
Autoscroll
Turn on autoscroll. Pointing or focusing pauses it; The switch allows you to stop explicitly.
<script lang="ts">
import { Carousel, Checkbox } from '@woodger/antd';
const items = [1, 2, 3, 4].map(number => ({ children: String(number), class: 'gallery-slide' }));
let playing = $state(false);
let current = $state(0);
</script>
<style>
.preview { min-width:0; }
.preview :global(.gallery-slide) {
height:160px;
line-height:160px;
text-align:center;
background:#364d79;
color:#fff;
font-size:28px;
font-weight:600;
}
.controls {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 12px;
margin-bottom: 16px;
}
output {
display: block;
margin-top: 16px;
}
</style>
<div
class="controls"
><Checkbox
bind:checked={playing}
>{("Automatically change slides")}</Checkbox></div>
<div
class="preview"
><Carousel
items={(items)}
autoplay={playing}
autoplaySpeed={2000}
speed={300}
pauseOnHover
pauseOnFocus
afterChange={index => { current = index; }}
/></div>
<output aria-label={("Automatic slide")}>{("Slide ")}{(current + 1)}{(" of 4")}</output>
Smooth appearance
effect="fade" replaces horizontal movement with a change in transparency.
<script lang="ts">
import { Carousel, type CarouselRef } from '@woodger/antd';
const items = [1, 2, 3, 4].map(number => ({ children: String(number), class: 'gallery-slide' }));
let current = $state(0);
let ref = $state<CarouselRef>();
</script>
<style>
.preview { min-width:0; }
.preview :global(.gallery-slide) {
height:160px;
line-height:160px;
text-align:center;
background:#364d79;
color:#fff;
font-size:28px;
font-weight:600;
}
output {
display: block;
margin-top: 16px;
}
</style>
<div
class="preview"
><Carousel
items={(items)}
effect="fade"
arrows
bind:ref
afterChange={index => { current = index; }}
/></div>
<output aria-label={("Slide with appearance")}>{("Slide ")}{(current + 1)}{(" of 4")}</output>
Progress indicators
autoplay.dotDuration shows the duration of the current slide. Start - by switch.
<script lang="ts">
import { Carousel, Checkbox } from '@woodger/antd';
const items = [1, 2, 3, 4].map(number => ({ children: String(number), class: 'gallery-slide' }));
let playing = $state(false);
</script>
<style>
.preview { min-width:0; }
.preview :global(.gallery-slide) {
height:160px;
line-height:160px;
text-align:center;
background:#364d79;
color:#fff;
font-size:28px;
font-weight:600;
}
.controls {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 12px;
margin-bottom: 16px;
}
</style>
<div class="controls">
<Checkbox bind:checked={playing}>
{("Show automatic progress")}
</Checkbox>
</div>
<div class="preview"><Carousel items={(items)} autoplay={playing ? {
dotDuration: true
} : false} autoplaySpeed={3000} /></div>
Methods and events
bind:ref provides prev, next and goTo; indexes are counted from scratch.
<script lang="ts">
import { Carousel, Button, type CarouselRef } from '@woodger/antd';
const items = [1, 2, 3, 4].map(number => ({ children: String(number), class: 'gallery-slide' }));
let ref = $state<CarouselRef>();
let current = $state(0);
let transition = $state('—');
</script>
<style>
.preview { min-width:0; }
.preview :global(.gallery-slide) {
height:160px;
line-height:160px;
text-align:center;
background:#364d79;
color:#fff;
font-size:28px;
font-weight:600;
}
.controls {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 12px;
margin-bottom: 16px;
}
output {
display: block;
margin-top: 16px;
}
</style>
<div class="controls">
<Button onclick={() => ref?.prev()}>{("Back")}</Button><Button onclick={() => ref
?.next()}>{("Forward")}</Button>
<Button onclick={() => ref?.goTo(2, true)}>{("To the third slide")}</Button>
</div>
<div class="preview"><Carousel items={(items)} bind:ref beforeChange={(
from,
to
) => { transition = ("" + String((from)) + " → " + String((to)) + ""); }} afterChange={index => {
current = index;
}} /></div>
<output aria-label={("Carousel events")}>{("Slide ")}{(current + 1)}{(". Transition: ")}{transition}.</output>
Own hands and indicators
Snippets explicitly apply class, style and handlers to native buttons.
<script lang="ts">
import { Carousel, type CarouselArrowProps } from '@woodger/antd';
const items = [1, 2, 3, 4].map(number => ({ children: String(number), class: 'gallery-slide' }));
let current = $state(0);
</script>
<style>
.preview { min-width:0; }
.preview :global(.gallery-slide) {
height:160px;
line-height:160px;
text-align:center;
background:#364d79;
color:#fff;
font-size:28px;
font-weight:600;
}
output {
display: block;
margin-top: 16px;
}
</style>
{#snippet previous(props: CarouselArrowProps)}<button type="button" class={props.class} style={props
.style} onclick={props.onClick} disabled={!props
.onClick} aria-label={("Back by cards")}></button>{/snippet}
{#snippet next(props: CarouselArrowProps)}<button type="button" class={props.class} style={props
.style} onclick={props.onClick} disabled={!props
.onClick} aria-label={("Forward on cards")}></button>{/snippet}
{#snippet paging(index: number, props: { onClick: (event: MouseEvent) => void })}<button
type="button"
onclick={props.onClick}
aria-label={("Open slide " + String((index + 1)) + "")}
>{(index + 1)}</button>{/snippet}
<div
class="preview"
><Carousel
items={(items)}
arrows
prevArrow={previous}
nextArrow={next}
customPaging={paging}
afterChange={index => { current = index; }}
/></div>
<output
aria-label={("Slide with its own buttons")}
>{("Slide ")}{(current + 1)}{(" of 4")}</output>
Several slides
Three slides on a wide screen; up to 768 px one is shown. The responsive rules are connected at mount.
<script lang="ts">
import { Carousel, type CarouselResponsiveObject } from '@woodger/antd';
const items = [1, 2, 3, 4].map(number => ({ children: String(number), class: 'gallery-slide' }));
const responsive: readonly CarouselResponsiveObject[] = [{
breakpoint: 768, settings: {
slidesToShow: 1
}
}];
</script>
<style>
.preview { min-width:0; }
.preview :global(.gallery-slide) {
height:160px;
line-height:160px;
text-align:center;
background:#364d79;
color:#fff;
font-size:28px;
font-weight:600;
}
</style>
<div
class="preview"
><Carousel
id="carousel-responsive"
items={(items)}
{responsive}
slidesToShow={3}
infinite={false}
arrows
/></div>
RTL and general settings
ConfigProvider sets the direction, arrow labels and design of the internal slider.
<script lang="ts">
import { Carousel, ConfigProvider } from '@woodger/antd';
const items = [1, 2, 3, 4].map(number => ({ children: String(number), class: 'gallery-slide' }));
</script>
<style>
.preview { min-width:0; }
.preview :global(.gallery-slide) {
height:160px;
line-height:160px;
text-align:center;
background:#364d79;
color:#fff;
font-size:28px;
font-weight:600;
}
</style>
<ConfigProvider
direction="rtl"
carousel={{ style: `
border-radius: 8px;
overflow: hidden;
` }}
locale={({ carousel: { prevSlide: "Previous frame", nextSlide: "Next frame" } })}
>
<div class="preview"><Carousel items={(items)} arrows /></div>
</ConfigProvider>
Both scopes use the same local class. The prefix changes the outer wrapper and animation of the indicators; the classes of Slick and its child components are preserved.
In vertical mode, RTL does not mirror flipping. The RTL class is used for horizontal viewing.
Carousel and progress prefixes
General and local prefixCls, RTL and vertical indicators. The current slide and draft are preserved when changing the prefix; autoscrolling is triggered explicitly.
<script lang="ts">
import { Button, Carousel, Checkbox, ConfigProvider, Input, type CarouselRef } from '@woodger/antd';
let custom = $state(true);
let local = $state(true);
let vertical = $state(false);
let rtl = $state(false);
let playing = $state(false);
let draft = $state('');
let ref = $state<CarouselRef>();
let current = $state(0);
let changes = $state(0);
let transition = $state('—');
const prefix = $derived(custom ? 'suite' : 'ant');
</script>
<style>
.example {
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: 20px;
min-width: 0;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
.preview { min-width: 0; }
.slide {
display: grid;
box-sizing: border-box;
height: 160px;
align-content: center;
justify-items: center;
padding: 24px;
background: #364d79;
color: #fff;
}
label {
display: grid;
gap: 8px;
width: 100%;
max-width: 220px;
min-width: 0;
}
.preview :global(.prefix-neighbor-slide) {
box-sizing: border-box;
height: 100px;
padding: 32px;
background: #364d79;
color: #fff;
text-align: center;
}
p { margin: 0; }
output { overflow-wrap: anywhere; }
</style>
{#snippet cover()}<div class="slide">{("Start viewing")}</div>{/snippet}
{#snippet details()}<div class="slide">{("Project Description")}</div>{/snippet}
{#snippet editor()}
<div class="slide">
<label>{("Draft slide\n ")}<Input bind:value={draft} aria-label={("Carousel draft with prefix")} style="width:100%" />
</label>
</div>
{/snippet}
<div class="example">
<div class="controls">
<Checkbox bind:checked={custom}>{("Common prefix Carousel suite")}</Checkbox>
<Checkbox bind:checked={local}>{("Carousel local prefix")}</Checkbox>
<Checkbox
bind:checked={vertical}
>{("Vertical Carousel with Prefix")}</Checkbox>
<Checkbox bind:checked={rtl}>{("RTL Carousel with prefix")}</Checkbox>
<Checkbox
bind:checked={playing}
>{("Autoscroll Carousel with prefix")}</Checkbox>
</div>
<div>
<Button
disabled={!ref}
onclick={() => ref?.goTo(2, true)}
>{("Go to slide draft")}</Button>
</div>
<ConfigProvider prefixCls={prefix} direction={rtl ? 'rtl' : 'ltr'}
theme={{ cssVar: { prefix: 'carousel-theme' } }}>
<section class="preview" aria-label={("Main carousel with prefix")}>
<Carousel
bind:ref
prefixCls={local ? 'project-carousel' : ''}
rootClassName="prefix-carousel-main"
speed={0}
arrows
dotPlacement={vertical ? 'start' : 'bottom'}
autoplay={playing ? { dotDuration: true } : false}
autoplaySpeed={5000}
items={([{ children: cover }, { children: details }, { children: editor }])}
beforeChange={(from, to) => { transition = ("" + String((from)) + " → " + String((to)) + ""); }}
afterChange={index => {
current = index;
changes += 1;
}}
/>
</section>
</ConfigProvider>
<ConfigProvider prefixCls="neighbor">
<section class="preview" aria-label={("Neighboring carousel with prefix")}>
<Carousel prefixCls={local ? 'project-carousel' : ''} rootClassName="prefix-carousel-neighbor"
speed={0} arrows items={([
{ children: "Neighboring area", class: 'prefix-neighbor-slide' },
{ children: "Independent viewing", class: 'prefix-neighbor-slide' }
])} />
</section>
</ConfigProvider>
<output
aria-label={("Carousel slide with prefix")}
>{("\n Slide ")}{(current + 1)}{(" from 3; transitions: ")}{changes}{("; last: ")}{transition}
</output>
<output
aria-label={("Carousel Prefix")}
>{("\n General: ")}{prefix}{("; class: ")}{(local ? 'project-carousel' : prefix + '-carousel')}
</output>
<p>
{("Both scopes use the same local class. The prefix changes the outer wrapper and animation of the indicators; the classes of Slick and its child components are preserved.")}
</p>
<p>
{("In vertical mode, RTL does not mirror flipping. The RTL class is used for horizontal viewing.")}
</p>
</div>
Guided View
Saved review example: external buttons, autoscroll, fade and current index.
<script lang="ts">
import { Button, Carousel, type CarouselRef } from '@woodger/antd';
let ref = $state<CarouselRef>();
let current = $state(0);
let autoplay = $state(false);
let fade = $state(false);
</script>
<style>
.example {
max-width: 720px;
min-width: 0;
}
.controls {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 12px;
margin-bottom: 16px;
}
.controls label {
display: flex;
align-items: center;
gap: 8px;
}
.slide {
display: grid;
height: 160px;
place-items: center;
background: #364d79;
color: #fff;
font-size: 32px;
font-weight: 600;
}
output {
display: block;
margin-top: 16px;
}
</style>
{#snippet first()}<div class="slide">1</div>{/snippet}
{#snippet second()}<div class="slide">2</div>{/snippet}
{#snippet third()}<div class="slide">3</div>{/snippet}
{#snippet fourth()}<div class="slide">4</div>{/snippet}
<div class="example">
<div class="controls" role="group" aria-label={("Carousel control")}>
<Button onclick={() => ref?.prev()}>{("Previous slide")}</Button>
<Button onclick={() => ref?.next()}>{("Next slide")}</Button>
<label><input
type="checkbox"
bind:checked={autoplay}
/>{(" Autoscroll")}</label>
<label><input
type="checkbox"
bind:checked={fade}
/>{(" Smooth appearance")}</label>
</div>
<Carousel
bind:ref
items={([{ children: first }, { children: second }, { children: third }, {
children: fourth
}])}
{autoplay}
effect={fade ? 'fade' : 'scrollx'}
arrows
afterChange={index => { current = index; }}
/>
<output aria-label={("Current slide")}>{("Slide ")}{(current + 1)}{(" of 4")}</output>
</div>
API
Examples are checked against the current ant.design page and the public API of the installed package. Full definitions of Props are in @woodger/antd.
| Theme | Example or limitation |
|---|---|
| Basic | Four slides and a change event. |
| Position | All four positions. |
| Scroll automatically | Controlled start, hover/focus pause. |
| Fade in | Transparency transition. |
| Arrows for switching | Arrows and final list. |
| Progress of dots | autoplay with dotDuration. |
| CSS prefix | Local wrapper and progress, common prefix and independent neighbor; saving the current slide and editor. |
| Property | Description | Type | Default |
|---|---|---|---|
prefixCls | Full local prefix for wrapper, RTL/vertical states and progress animations. The empty string and undefined use the provider prefix; Slick classes are preserved. | string | ConfigProvider.prefixCls + "-carousel" |
items | Slide array; takes precedence over children. | readonly CarouselItem[] | — |
children | Value, Snippet or array; explicit items are preferable. | CarouselContent | — |
arrows | Transition arrows. | boolean | false |
dots | Indicators of the current slide. | boolean | { class?, className? } | true |
dotPlacement | Indicator position; start/end enable vertical mode. | top | bottom | start | end | bottom |
effect | Movement or transparency. | scrollx | fade | scrollx |
autoplay | Auto-scrolling and progress of indicators. | boolean | { dotDuration?: boolean } | false |
autoplaySpeed | Autoscroll interval in ms; Slick adds 50 ms. | number | 3000 |
speed | Duration of transition and afterChange timer. | number | 500 |
infinite | Repeat slides in a circle. | boolean | true |
beforeChange | Indexes before transition. | (from, to) => void | — |
afterChange | Index after the transition is completed. | (index) => void | — |
responsive | Slick settings for viewport width. | readonly CarouselResponsiveObject[] | — |
customPaging | Own indicator button. | Snippet<[index, props]> | — |
prevArrow | Own previous arrow. | Snippet<[CarouselArrowProps]> | — |
nextArrow | Own next arrow. | Snippet<[CarouselArrowProps]> | — |
ref | bind:ref with control methods after mount. | CarouselRef | — |
Methods
ref.goTo(index, dontAnimate?), ref.next(), ref.prev() control transitions. ref.nativeElement - outer div; innerSlider provides a delegated Slick API. Additional settings are available in the public CarouselSlickSettings; the full contract is not duplicated here.
Semantic DOM
The outer div contains the inner slider, viewport, track, slides, arrows and indicators. Named classNames/styles slots no. For the internal slider, class/style and ConfigProvider.carousel are available; rootClassName refers to the outer div.
prefixCls changes the outer wrapper, its RTL/vertical states and duration keyframes names. The slick-slider, slick-track, slick-slide and controls classes are retained. Nested Radio/Checkbox selectors use a common provider prefix, regardless of the theme's local Carousel.prefixCls and namespace.
Wrap the carousel in a named area. The arrow buttons have labels from locale.carousel; You need to name your own buttons yourself. Hidden slide content gets aria-hidden; interactive slide elements require a separate Tab order check. For autoscrolling, leave explicit stop control.
Registration tokens
theme.components.Carousel applies seven component tokens: arrow sizes and paddings, geometry and position of indicators. class/style and ConfigProvider.carousel are available for local styling.
| Token | Purpose |
|---|---|
arrowOffset | Indentation of the arrow from the edge. |
arrowSize | Hand size. |
dotActiveWidth | Active indicator width. |
dotGap | Interval between indicators. |
dotHeight | Indicator height. |
dotOffset | Indicator distance from the edge. |
dotWidth | Width of a regular indicator. |
| Token | Current value |
|---|---|
colorBgContainer | #ffffff |
colorText | rgba(0,0,0,0.88) |
borderRadius | 6 |
motionDurationSlow | 0.3s |
FAQ
How to move to the desired slide?
After mount, call ref.goTo(index, dontAnimate). Prev/next are available for neighbors; indexes start from zero.
Why didn't slickGoTo prop switch the slide?
It is saved in upstream types, but the goTo method via ref is intended for control.
How to add your own arrows?
Pass snippets prevArrow/nextArrow and apply the resulting handlers and styling to the native buttons.
Why did autoscroll stop?
Check pauseOnHover/pauseOnFocus and autoplay status. For accessible control, leave an explicit pause button for the user.