# Carousel

- **Section:** Components
- **URL:** https://refast.fastapicloud.dev/docs/components/carousel
- **Markdown:** https://refast.fastapicloud.dev/docs/components/carousel.md
- **Source:** https://github.com/idling-mind/refast-docs/blob/main/docs/pages/components/utility/carousel.py
- **Live examples:** the widgets on this page need a browser; open the URL above to try them.
- **Applies to:** refast 0.12.2

A touch-friendly, swipeable carousel powered by [Embla Carousel](https://www.embla-carousel.com/).
Supports horizontal and vertical orientations, looping, and custom slide content.

```python
from refast.components import (
    Carousel, CarouselContent, CarouselItem,
    CarouselPrevious, CarouselNext,
)
```

🌊

Slide 1

🔮

Slide 2

🌿

Slide 3

🔥

Slide 4

🌸

Slide 5

```python
Carousel(
    orientation="horizontal",
    loop=False,
    children=[
        CarouselContent(
            children=[
                CarouselItem(children=[Card(title="Slide 1", ...)]),
                CarouselItem(children=[Card(title="Slide 2", ...)]),
                CarouselItem(children=[Card(title="Slide 3", ...)]),
            ]
        ),
        CarouselPrevious(),
        CarouselNext(),
    ]
)
```

## Props

### `Carousel`

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | Scroll axis |
| `loop` | `bool` | `False` | Whether to wrap around continuously |
| `opts` | `dict \| None` | `None` | Embla Carousel options (advanced) |
| `children` | `ChildrenType` | `None` | `CarouselContent` + navigation buttons |

### `CarouselItem`

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `children` | `ChildrenType` | `None` | Slide content |
| `class_name` | `str` | `""` | Extra Tailwind classes (e.g. `"basis-1/2"` for multi-visible) |

### `CarouselPrevious` / `CarouselNext`

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `on_click` | `Callback \| None` | `None` | Optional server callback when navigating |

## Component Hierarchy

```
Carousel
├── CarouselContent
│   ├── CarouselItem  ← slide 1
│   ├── CarouselItem  ← slide 2
│   └── CarouselItem  ← slide N
├── CarouselPrevious  ← prev button (outside CarouselContent)
└── CarouselNext      ← next button (outside CarouselContent)
```

## Multi-slide Visible

Use `class_name="basis-1/3"` on `CarouselItem` to show multiple slides
at once:

```python
Carousel(
    children=[
        CarouselContent(
            children=[
                CarouselItem(
                    class_name="basis-1/3",
                    children=[Card(title=f"Item {i}")]
                )
                for i in range(9)
            ]
        ),
        CarouselPrevious(),
        CarouselNext(),
    ]
)
```

## Vertical Carousel

```python
Carousel(
    orientation="vertical",
    class_name="h-64",
    children=[
        CarouselContent(class_name="h-full"),
        CarouselPrevious(),
        CarouselNext(),
    ]
)
```

## Advanced Options (Embla)

Pass any Embla Carousel option via `opts`:

```python
Carousel(
    opts={"align": "start", "skipSnaps": False},
    loop=True,
    children=[...]
)
```

---

Part of the Refast documentation: [all pages](https://refast.fastapicloud.dev/llms.txt), [everything on one page](https://refast.fastapicloud.dev/llms-full.txt), [search](https://refast.fastapicloud.dev/api/search?q=save_prop).
