<div id="carouselExample" class="carousel slide" data-bs-ride="carousel"> <div class="carousel-inner"> <div class="carousel-item"> <img src="slide1.jpg" class="d-block w-100" alt="Slide 1"> </div> <div class="carousel-item active"> <img src="slide2.jpg" class="d-block w-100" alt="Slide 2"> </div> <div class="carousel-item"> <img src="slide3.jpg" class="d-block w-100" alt="Slide 3"> </div> </div> </div>
In Bootstrap carousels, the slide with the active class is the one shown first. Here, Slide 2 has the active class, so it will be visible initially.
Bootstrap 5 uses data-bs-target and data-bs-slide attributes on button elements for carousel controls. The values must be exactly 'prev' and 'next'. Also, aria-hidden and visually-hidden classes are used for accessibility.
Bootstrap adds the active class to the currently visible slide. The correct selector is .carousel-item.active which selects elements with both classes.
object-fit: cover; makes images fill their container by cropping excess parts, preserving aspect ratio. Combined with width: 100%; height: 100%;, it ensures full coverage without distortion.
Using aria-label on the button and a span with visually-hidden class inside provides clear, accessible text for screen readers without showing it visually.