Carousel
Responsive slideshow component for cycling through images or content.
Basic Usage
from faststrap import Carousel, CarouselItem
Carousel(
CarouselItem(Img(src="/img/slide1.jpg"), caption="First slide"),
CarouselItem(Img(src="/img/slide2.jpg"), caption="Second slide"),
CarouselItem(Img(src="/img/slide3.jpg"), caption="Third slide"),
carousel_id="myCarousel",
)
API Reference
Carousel
| Parameter | Type | Default | Description |
|---|---|---|---|
*items |
CarouselItem |
- | Carousel items |
carousel_id |
str \| None |
None |
Unique carousel ID. Auto-generated when omitted. |
controls |
bool \| None |
UNSET |
Show previous/next controls. |
indicators |
bool \| None |
UNSET |
Show slide indicators. |
interval |
int \| None |
UNSET |
Auto-play interval in milliseconds. |
keyboard |
bool \| None |
UNSET |
Enable keyboard navigation. |
pause |
bool \| str \| None |
UNSET |
Pause behavior, such as "hover" or False. |
ride |
bool \| str \| None |
UNSET |
Auto-start behavior, such as "carousel" or False. |
wrap |
bool \| None |
UNSET |
Loop from last slide to first. |
fade |
bool \| None |
UNSET |
Use fade transition. |
dark |
bool \| None |
UNSET |
Use dark carousel controls/indicators. |
**kwargs |
Any |
- | Additional HTML attributes |
CarouselItem
| Parameter | Type | Default | Description |
|---|---|---|---|
*content |
Any |
- | Slide content |
caption |
str \| None |
None |
Slide caption. |
caption_title |
str \| None |
None |
Caption title. |
active |
bool |
False |
Set as active slide. |
interval |
int \| None |
None |
Per-slide interval override. |
**kwargs |
Any |
- | Additional HTML attributes |
Examples
Auto-playing Carousel
Carousel(
CarouselItem(Img(src="/img/1.jpg"), active=True),
CarouselItem(Img(src="/img/2.jpg")),
CarouselItem(Img(src="/img/3.jpg")),
carousel_id="autoCarousel",
interval=3000 # 3 seconds
)
Fade Transition
Carousel(
CarouselItem(Img(src="/img/1.jpg"), active=True),
CarouselItem(Img(src="/img/2.jpg")),
carousel_id="fadeCarousel",
fade=True
)
With Captions
Carousel(
CarouselItem(
Img(src="/products/laptop.jpg"),
caption="Premium Laptop - $999",
active=True
),
CarouselItem(
Img(src="/products/phone.jpg"),
caption="Smartphone - $699"
),
carousel_id="productCarousel",
)
Notes
- The first item should usually pass
active=True. - This component requires Bootstrap JavaScript.
- If you render multiple carousels with the same content and no explicit
carousel_id, Faststrap adds a suffix to avoid duplicate IDs in the same Python process.
Accessibility
- Uses proper ARIA attributes
- Keyboard navigation supported
- Screen reader announcements for slide changes
See Also
API Reference
faststrap.components.display.carousel.Carousel(*items, carousel_id=None, controls=UNSET, indicators=UNSET, interval=UNSET, keyboard=UNSET, pause=UNSET, ride=UNSET, wrap=UNSET, fade=UNSET, dark=UNSET, **kwargs)
Bootstrap Carousel for image/content sliders.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*items
|
Any
|
CarouselItem components |
()
|
carousel_id
|
str | None
|
Unique ID for carousel (auto-generated if not provided) |
None
|
controls
|
bool | None
|
Show previous/next controls |
UNSET
|
indicators
|
bool | None
|
Show slide indicators |
UNSET
|
interval
|
int | None
|
Auto-play interval in milliseconds (5000 = 5s, False = no auto-play) |
UNSET
|
keyboard
|
bool | None
|
Enable keyboard navigation |
UNSET
|
pause
|
bool | str | None
|
Pause on hover ("hover" or False) |
UNSET
|
ride
|
bool | str | None
|
Auto-start carousel ("carousel" or False) |
UNSET
|
wrap
|
bool | None
|
Enable continuous loop |
UNSET
|
fade
|
bool | None
|
Use fade transition instead of slide |
UNSET
|
dark
|
bool | None
|
Use dark variant for controls/indicators |
UNSET
|
**kwargs
|
Any
|
Additional HTML attributes |
{}
|
Returns:
| Type | Description |
|---|---|
Div
|
FastHTML Div element with carousel structure |
Examples:
Basic carousel:
>>> Carousel(
... CarouselItem(Img(src="1.jpg"), caption="First slide"),
... CarouselItem(Img(src="2.jpg"), caption="Second slide"),
... controls=True,
... indicators=True
... )
Auto-playing carousel:
>>> Carousel(
... CarouselItem(Img(src="1.jpg")),
... CarouselItem(Img(src="2.jpg")),
... interval=3000, # 3 seconds
... ride="carousel"
... )
See Also
Bootstrap docs: https://getbootstrap.com/docs/5.3/components/carousel/
Source code in src/faststrap/components/display/carousel.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
faststrap.components.display.carousel.CarouselItem(*content, caption=None, caption_title=None, active=False, interval=None, **kwargs)
Individual carousel slide item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*content
|
Any
|
Slide content (typically an Img element) |
()
|
caption
|
str | None
|
Caption text below image |
None
|
caption_title
|
str | None
|
Caption title (shown above caption text) |
None
|
active
|
bool
|
Mark as active slide (first slide should be active) |
False
|
interval
|
int | None
|
Override carousel interval for this slide |
None
|
**kwargs
|
Any
|
Additional HTML attributes |
{}
|
Returns:
| Type | Description |
|---|---|
Div
|
FastHTML Div element with carousel-item structure |
Examples:
Image with caption:
>>> CarouselItem(
... Img(src="slide1.jpg", cls="d-block w-100"),
... caption_title="First Slide",
... caption="This is the first slide",
... active=True
... )
Custom interval:
>>> CarouselItem(
... Img(src="slide2.jpg", cls="d-block w-100"),
... interval=10000 # Show for 10 seconds
... )
See Also
Bootstrap docs: https://getbootstrap.com/docs/5.3/components/carousel/