Carousel
A slideshow of cards with previous and next buttons, built on Bootstrap Carousel, without autoplay.
Installation
bash
npx bootcn add carouselbash
pnpm dlx bootcn add carouselbash
yarn dlx bootcn add carouselbash
bunx --bun bootcn add carouselThe CLI also installs the design tokens and these components: none. It prints the <link> and <script> tags to add to your layout.
Usage
Put any content in each .carousel-item. The carousel does not move on its own (no data-bs-ride): moving content is hard to read and to use. If you add autoplay, add a visible pause button too (WCAG 2.2.2). Buttons sit outside the slides; keep a margin around the carousel for them.
Accessibility
- A labelled
<section>witharia-roledescription="carousel"; each slide is a group named "n of 5", so screen readers say where they are. - The slides region is a polite live region: the new slide is announced after Previous or Next.
- Buttons have names ("Previous slide", "Next slide").
Dependencies
- Bootstrap 5.3+ CSS and the JS bundle.
themes/tokens/tokens.css.
Source
The exact files the CLI installs (carousel@1.0.0). View on GitHub · Report an issue
html
<section
id="bootcn-carousel"
class="carousel slide bootcn-carousel"
aria-roledescription="carousel"
aria-label="Featured numbers"
>
<div class="carousel-inner" aria-live="polite">
<div class="carousel-item active" role="group" aria-roledescription="slide" aria-label="1 of 5">
<div class="bootcn-carousel__slide">1</div>
</div>
<div class="carousel-item" role="group" aria-roledescription="slide" aria-label="2 of 5">
<div class="bootcn-carousel__slide">2</div>
</div>
<div class="carousel-item" role="group" aria-roledescription="slide" aria-label="3 of 5">
<div class="bootcn-carousel__slide">3</div>
</div>
<div class="carousel-item" role="group" aria-roledescription="slide" aria-label="4 of 5">
<div class="bootcn-carousel__slide">4</div>
</div>
<div class="carousel-item" role="group" aria-roledescription="slide" aria-label="5 of 5">
<div class="bootcn-carousel__slide">5</div>
</div>
</div>
<button
class="bootcn-carousel__control bootcn-carousel__control--prev"
type="button"
data-bs-target="#bootcn-carousel"
data-bs-slide="prev"
>
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<path d="m15 18-6-6 6-6" />
</svg>
<span class="visually-hidden">Previous slide</span>
</button>
<button
class="bootcn-carousel__control bootcn-carousel__control--next"
type="button"
data-bs-target="#bootcn-carousel"
data-bs-slide="next"
>
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<path d="m9 18 6-6-6-6" />
</svg>
<span class="visually-hidden">Next slide</span>
</button>
</section>css
.bootcn-carousel {
max-width: 20rem;
margin: 0 3rem;
}
.bootcn-carousel__slide {
display: flex;
align-items: center;
justify-content: center;
aspect-ratio: 1 / 1;
padding: 1.5rem;
border: var(--bootcn-border-width) solid var(--bootcn-border-color);
border-radius: var(--bootcn-radius-xl);
background-color: var(--bootcn-background);
box-shadow: var(--bootcn-shadow-sm);
font-size: 2.25rem;
font-weight: 600;
}
.bootcn-carousel__control {
position: absolute;
top: 50%;
display: inline-flex;
align-items: center;
justify-content: center;
width: 2rem;
height: 2rem;
border: var(--bootcn-border-width) solid var(--bootcn-input);
border-radius: 9999px;
background-color: var(--bootcn-background);
color: var(--bootcn-foreground);
box-shadow: var(--bootcn-shadow-sm);
transform: translateY(-50%);
}
.bootcn-carousel__control:hover {
background-color: var(--bootcn-accent);
}
.bootcn-carousel__control:focus-visible {
outline: 0;
box-shadow: var(--bootcn-focus-ring);
}
.bootcn-carousel__control--prev {
left: -3rem;
}
.bootcn-carousel__control--next {
right: -3rem;
}
@media (prefers-reduced-motion: reduce) {
.bootcn-carousel .carousel-item {
transition: none;
}
}
