To build a responsive Bootstrap 5 carousel, load Bootstrap’s CSS and JavaScript bundle, give the carousel a unique ID, mark one slide .active, and make every control or indicator target that ID. Bootstrap’s .d-block.w-100 image pattern fills the available width; you still need to decide how slide heights and image cropping should behave on different screens.
Load Bootstrap 5.3
The carousel needs Bootstrap CSS and JavaScript. Bootstrap’s setup page currently shows version 5.3.8 CDN assets. Before publishing, check that page for the current version and matching integrity values rather than copying stale hashes.
Use the mobile viewport declaration so the page lays out at the device width:
<meta name="viewport" content="width=device-width, initial-scale=1">
Place the CSS link in the document head and the JavaScript bundle before the closing body tag. The bundle includes the dependencies needed by Bootstrap components.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →#1 Best Overall
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
Bootstrap 5.3 setup documentation
Build a basic responsive carousel
This example provides two slides and previous/next buttons. Replace the image paths and alternative text with content appropriate to your page.
<div id="heroCarousel" class="carousel slide">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="slide-1.jpg" class="d-block w-100" alt="Describe the first image">
</div>
<div class="carousel-item">
<img src="slide-2.jpg" class="d-block w-100" alt="Describe the second image">
</div>
</div>
<button class="carousel-control-prev" type="button"
data-bs-target="#heroCarousel" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button"
data-bs-target="#heroCarousel" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
The required structure is a .carousel wrapper, a .carousel-inner, and a .carousel-item for each slide. At least one item must have active; otherwise, no slide appears. The image classes d-block w-100 make each image a block-level element at the container’s full width.
The controls are buttons, and their data-bs-target value must match the carousel’s ID, including the leading #. If a page has multiple carousels, assign each a different ID and update all related targets.
Bootstrap 5.3 Carousel documentation
Choose how images fit the frame
Bootstrap does not normalize slide dimensions. Images with different aspect ratios can make the carousel height change as visitors move between slides. Test the actual images at narrow and wide viewport sizes, and choose a framing strategy deliberately.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
- Natural image dimensions: Preserve the whole image without cropping, but expect slide height to vary when the source images have different proportions.
- Consistent aspect ratio: A fixed or fluid ratio can create a steadier frame. Applying
object-fit: coveris one CSS approach, but it crops part of an image; check that important subjects remain visible on mobile and desktop.
For example, a project might add a class to each image and define a shared frame in its stylesheet:
.carousel-frame {
width: 100%;
aspect-ratio: 16 / 9;
object-fit: cover;
}
Then include class="d-block w-100 carousel-frame" on each image. The 16:9 ratio is a design choice, not a Bootstrap requirement; use a ratio that suits the content and verify the resulting crop.
Add indicators or captions
Indicators
Indicators give visitors a visible sense of slide count and let them jump directly to a slide. Put the indicator buttons inside the carousel. Their slide indices start at zero, and each target must match the carousel ID.
<div class="carousel-indicators">
<button type="button" data-bs-target="#heroCarousel" data-bs-slide-to="0"
class="active" aria-current="true" aria-label="Slide 1"></button>
<button type="button" data-bs-target="#heroCarousel" data-bs-slide-to="1"
aria-label="Slide 2"></button>
</div>
Keep the active indicator synchronized with the initially active slide. Add or remove indicator buttons if the number of slides changes.
Rank #3
Captions
Place a .carousel-caption within the relevant .carousel-item. Bootstrap’s display utilities can hide caption text on small screens and show it from the medium breakpoint:
<div class="carousel-item active">
<img src="slide-1.jpg" class="d-block w-100" alt="A cyclist on a forest trail">
<div class="carousel-caption d-none d-md-block">
<h2>Explore the forest trail</h2>
<p>A caption shown from the medium breakpoint upward.</p>
</div>
</div>
Do not hide information or a necessary call to action on small screens just because the caption is hidden there. If visitors need the content, make it available elsewhere or choose a layout that keeps it visible.
Choose manual navigation or autoplay
Manual navigation lets visitors control how long they spend on each slide. Autoplay can expose changing content without an interaction, but it may interrupt reading or move before someone has finished. Choose based on the purpose of the slides, not simply because cycling is available.
Enable autoplay
Add data-bs-ride="carousel" to the wrapper to start cycling when the page loads. Bootstrap documents a default interval of 5,000 milliseconds. Set a per-slide data-bs-interval in milliseconds when different slides need different display times.
Free tools Windows power users keep installed
One-click scans. No signup required.
Rank #4
- Brand: Wiley
- Set of 2 Volumes
- A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
<div id="heroCarousel" class="carousel slide" data-bs-ride="carousel">
The documentation says carousels pause on hover by default and stop when the page is not visible in supporting browsers. Do not assume those behaviors eliminate the need to make autoplay easy to control or to avoid it when motion interferes with the content.
Use JavaScript options
For options that are not expressed in markup, initialize the component through JavaScript. For example, turn off cycling with interval: false:
const carouselElement = document.querySelector('#heroCarousel');
const carousel = new bootstrap.Carousel(carouselElement, {
interval: false,
touch: true
});
Bootstrap 5.3 says to initialize manually when you need event listeners, except that a carousel using data-bs-ride="carousel" initializes automatically. Do not initialize that autoplaying data-attribute carousel a second time.
Touch and transition options
Touch swiping is enabled by default. Set the JavaScript option touch: false if swiping should be disabled. To use a fade instead of the standard slide transition, add carousel-fade alongside carousel slide. A fade changes the transition style, not the need for controls, clear content, or deliberate motion choices.
Best Value
Make the carousel usable and accessible
Bootstrap cautions that carousels can create usability and accessibility challenges. Bootstrap supplies useful markup patterns, but accessibility depends substantially on the author’s HTML, styling, and scripting.
- Write meaningful alternative text for informative images. Use empty alternative text only when an image is decorative and its content is not otherwise needed.
- Keep controls as buttons and retain the visually hidden “Previous” and “Next” labels so their purpose is available to assistive technology.
- Check that controls and indicators work with keyboard and touch input, and that controls have sufficient contrast over every slide.
- Use autoplay only when it serves the page, and make sure moving content does not prevent visitors from reading or controlling the experience.
- Test the design with reduced motion enabled. Bootstrap’s motion effects respond to the
prefers-reduced-motionsetting.
Bootstrap’s accessibility guidance: Accessibility.
Common problems and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| No slide is visible | No .carousel-item has the active class. |
Add active to the slide that should appear first. |
| Next and previous buttons do nothing | Bootstrap’s JavaScript bundle is missing, the target ID is wrong, or the controls are outside the matching carousel. | Load the bundle, check that the wrapper ID is unique, and make the controls’ data-bs-target match it exactly. |
| An indicator opens the wrong slide or does nothing | The target does not match, the zero-based index is wrong, or the indicator set does not match the slides. | Use the carousel’s exact ID and number indicators from zero in slide order. |
| The carousel height jumps between slides | The slides contain images with differing intrinsic dimensions, and Bootstrap does not normalize their height. | Use consistently proportioned images or apply a considered aspect-ratio frame; inspect any cropping at mobile and desktop widths. |
| The caption is missing on a phone | The example uses d-none d-md-block, which hides the caption below the medium breakpoint. |
Remove or change those display utilities, or provide the important information outside the caption. |
| Autoplay does not start or runs unexpectedly | The ride attribute or JavaScript options may be missing, or a carousel may have been initialized twice. | Choose either the documented data-bs-ride initialization or the manual JavaScript setup and avoid duplicating initialization. |
Or skip the browser setup
If what you need is a screenshot of the finished page rather than a carousel implementation, ScreenshotNeo is a website screenshot API and MCP server for developers. It can capture a page as PNG, JPEG, WebP, or PDF. A basic request takes a URL:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for request options. ScreenshotNeo accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, with response headers indicating the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchSign up for ScreenshotNeo’s free plan.
Frequently Asked Questions
Can I put more than one Bootstrap carousel on a page?
Yes. Give each carousel a unique ID and make that carousel’s controls and indicators target only its own ID.
Does Bootstrap automatically make every slide the same height?
No. Bootstrap does not normalize slide dimensions; choose natural image sizing or a consistent frame and test the result at relevant viewport widths.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




