chrome

<tc-carousel>

Slide / fade carousel with autoplay, indicators, controls, keyboard nav, and pointer swipe. Slides go in the default slot.

import "@ra9/tan-compose-kit/carousel"

Props

NameTypeDefaultDescription
valuenumber0Current slide index. Reflects to the `value` attribute.
autoplaynumber0Autoplay interval in milliseconds. `0` disables autoplay.
loopbooleantrueWrap around at the ends. Disable to stop at first / last slide.
orientation"horizontal" | "vertical""horizontal"Slide axis. Vertical carousels require a `height`.
transition"slide" | "fade""slide"How slides change. `slide` translates the track; `fade` cross-fades stacked slides.
indicatorsbooleantrueRender dot indicators along the bottom (or right, vertical).
controlsbooleantrueRender the prev / next buttons.
swipebooleantrueEnable pointer / touch drag to change slides.
pauseOnHoverbooleantruePause autoplay while the carousel is hovered or focused.
ariaLabelstring"Carousel"Accessible region label.
heightstring""Optional explicit viewport height (any CSS length). Required for vertical and fade carousels with images.

Events

EventDetailWhen
tc-change{ index: number, previous: number }Fires when the active slide changes (user click, swipe, keyboard, autoplay, or programmatic value change).

Slots

SlotDescription
(default)One direct child per slide. The carousel observes children and updates as you add or remove slides.

CSS variables

VariableDefaultDescription
--tc-carousel-radiusvar(--tc-radius-lg, 12px)Outer corner radius.
--tc-carousel-bgvar(--tc-color-bg, #faf8f3)Background behind slides.
--tc-carousel-control-bgrgba(255, 255, 255, 0.85)Prev / next button background.
--tc-carousel-control-bg-hoverrgba(255, 255, 255, 1)Prev / next button hover background.
--tc-carousel-control-fgvar(--tc-color-ink, #14171f)Prev / next button icon color.
--tc-carousel-control-size36pxPrev / next button diameter.
--tc-carousel-indicatorrgba(20, 23, 31, 0.25)Indicator pill background.
--tc-carousel-indicator-activevar(--tc-color-accent, #a16939)Active dot fill.
--tc-carousel-duration320msTransition duration. Respected by both slide and fade modes.

Examples

Basic

The default carousel is a horizontal slide track with controls, indicators, looping, and pointer swipe. Each child of <tc-carousel> becomes a slide.

Slide 1
Slide 2
Slide 3
<tc-carousel ariaLabel="Featured"> <div>Slide 1</div> <div>Slide 2</div> <div>Slide 3</div> </tc-carousel>

Autoplay

Set autoplay to a millisecond interval. The carousel pauses on hover and on keyboard focus by default — turn that off with pauseOnHover="false" if you want it to keep cycling.

A
B
C
D
<tc-carousel autoplay="2500"> <div>A</div><div>B</div><div>C</div><div>D</div> </tc-carousel>

Fade transition

transition="fade" cross-fades slides stacked on top of each other. Set height so the viewport keeps a fixed size while content swaps.

"Tiny declarative library for building Web Components. No JSX, no compiler."
— release notes
"Refs, reactive props, and a focus-preserving render loop in 60 lines."
— v1.1.0
"Drop-in primitives. No global cascade, no framework runtime."
— kit v1.5.0
<tc-carousel transition="fade" autoplay="3000" height="180px"> <blockquote>"Quote one."</blockquote> <blockquote>"Quote two."</blockquote> <blockquote>"Quote three."</blockquote> </tc-carousel>

Vertical

orientation="vertical" rotates the track and indicators. A height is required so the viewport has a defined extent to scroll within.

One
Two
Three
<tc-carousel orientation="vertical" height="220px"> <div>One</div> <div>Two</div> <div>Three</div> </tc-carousel>

Indicators only, no controls

Hide the prev / next buttons for a more editorial feel. Indicators stay clickable.

Ship work, not config.
Drop into any page.
Native standards.
<tc-carousel controls="false" autoplay="2800"> <h2>Ship work, not config.</h2> <h2>Drop into any page.</h2> <h2>Native standards.</h2> </tc-carousel>

Image gallery

Carousels are most often used for image galleries. Set height so all slides share the same viewport regardless of intrinsic image size.

tan-01.jpg
tan-02.jpg
tan-03.jpg
tan-04.jpg
<tc-carousel autoplay="4000" height="260px"> <img src="/img/1.jpg" alt="…"> <img src="/img/2.jpg" alt="…"> <img src="/img/3.jpg" alt="…"> <img src="/img/4.jpg" alt="…"> </tc-carousel>

Listening for slide changes

<tc-carousel id="hero" autoplay="3000"> <div>One</div><div>Two</div><div>Three</div> </tc-carousel> <script> document.getElementById("hero").addEventListener("tc-change", (e) => { console.log("now on slide", e.detail.index, "from", e.detail.previous); }); </script>

Programmatic control

Set value to jump to a specific slide. The carousel reflects the prop to the value attribute, so two-way binding works with framework integrations.

const car = document.querySelector("tc-carousel"); car.value = 2; // jump to the third slide car.value = car.value + 1; // next

Accessibility

  • The root has role="region" and aria-roledescription="carousel". Set ariaLabel to something meaningful for screen readers.
  • Each slide gets role="group", aria-roledescription="slide", and aria-label="N of M" applied automatically.
  • A polite live region announces the new position on each change.
  • Keyboard support: / (or / vertical) navigate, Home and End jump to the ends. Indicators are real <button> elements, focusable in source order.
  • prefers-reduced-motion: reduce collapses transitions to instant.

Theming

<tc-carousel style=" --tc-carousel-radius: 20px; --tc-carousel-bg: #0b0c10; --tc-carousel-control-bg: rgba(255,255,255,0.12); --tc-carousel-control-bg-hover: rgba(255,255,255,0.2); --tc-carousel-control-fg: #fff; --tc-carousel-duration: 500ms; " autoplay="3000" height="240px" > <!-- slides --> </tc-carousel>