Welcome to Day 5 of your Bootstrap journey!
Today, we will explore some of the most interactive and visually interesting components Bootstrap 5 has to offer. If you’ve been building static layouts up until this point, you’re in for a treat! Today we will bring your web pages to life with modals (which are popup dialogs), tooltips (helpful messages that display when a user hovers over an element), popovers (information about an element that are shown after a click), carousels (image sliders), and progress bars (a visual indication of completion and progress).
These components are the building blocks of modern, user-friendly websites. Whether you’re developing a contact form popup, a portfolio gallery, or some other type of loading state, utilizing these components will really demonstrate your web development skills. We will break everything down step-by-step so that you not only understand what the component does, but also why you would want to use it and when to use each component.
These components greatly improve user experience (UX) and can often be found in professional websites, so let’s dive in!
Requirements
Before we start, ensure you have:
Let’s get going with the basic structure and connection to Bootstrap 5.
<title>Bootstrap 5 Interactive Components</title>
<!-- Bootstrap 5 CSS CDN -->
<!-- Our components will go here -->
<!-- Bootstrap 5 JS Bundle (includes Popper.js) -->
What’s Happening Here?
Pro Tip: Always place the JavaScript <script> tag just before the closing </body> tag. This ensures the HTML loads first, improving page performance.
A modal is a dialog box that pops up above your current page. It is great for forms, confirmations, and alerts.
Code:
<!-- Button to trigger modal -->
<h2>Modal with Form</h2>
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#formModal">
Open Form Modal
</button>
<!-- Modal Structure -->
<div class="modal fade" id="formModal">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h5 class="modal-title">Contact Form</h5>
<button class="btn-close" data-bs-dismiss="modal"></button>
</div>
<!-- Modal Body -->
<div class="modal-body">
<div class="mb-3">
<label for="email" class="form-label">Email</label>
</div>
<div class="mb-3">
<label for="message" class="form-label">Message</label>
<textarea class="form-control" id="message" rows="3"></textarea>
</div>
</div>
<!-- Modal Footer -->
<div class="modal-footer">
<button class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button class="btn btn-success">Send</button>
</div>
</div>
</div>
</div>
Explanation:
The Trigger Button:
The Modal Structure:
Modal Sections:
Form Elements:
A common mistake is to not include the Bootstrap JS bundle, which will make your modal not work. Always remember to include the <script> tag.
Tooltips are concise pop-up messages that display when the user hovers over an element. They serve a nice purpose of presenting hints while keeping your UI neat.
Code:
<h2>Tooltip</h2>
<button class="btn btn-info me-2" data-bs-toggle="tooltip" data-bs-placement="top" title="Tooltip on top">
Hover me
</button>
<button class="btn btn-info" data-bs-toggle="tooltip" data-bs-placement="right" title="Tooltip on right">
Hover me too
</button>
<!-- Tooltip Initialization Script -->
document.querySelectorAll('[data-bs-toggle="tooltip"]').forEach(el => new bootstrap.Tooltip(el));
Explanation:
HTML Attributes:
Javascript Initialization: Tooltips need to be manually initialized with JS. Here’s how it works:
Just note that without this JS initialization, the tooltips will not work! This is because Bootstrap will need to create them and position them dynamically.
Popovers display similarly to tooltips, but they can contain more content including titles and body text. Instead of displaying on hover, they display on click.
Code:
<h2>Popover</h2>
<button class="btn btn-warning" data-bs-toggle="popover" title="Popover Title" data-bs-content="This is extra info in a popover.">
Click for Popover
</button>
<!-- Popover Initialization Script -->
document.queryS
Explanation:
HTML Attributes:
Key Differences compared to tooltips:
Pro Tip: Use tooltips for short text for hints and popovers for longer text, or cases where you need a title + description.
A carousel (or slider) allows you to display multiple images or content in a rotating slideshow format. Great for portfolios, testimonials, or product display.
Code:
<h2>Image Carousel</h2>
<div id="myCarousel" class="carousel slide w-50 mx-auto" data-bs-ride="carousel">
<!-- Carousel Indicators -->
<div class="carousel-indicators">
<button type="button" data-bs-target="#myCarousel" data-bs-slide-to="0" class="active"></button>
<button type="button" data-bs-target="#myCarousel" data-bs-slide-to="1"></button>
<button type="button" data-bs-target="#myCarousel" data-bs-slide-to="2"></button>
</div>
<!-- Carousel Items -->
<div class="carousel-inner">
<div class="carousel-item active">
<img src="images/mountainskies.jpg" class="d-block w-100" alt="Slide 1">
<div class="carousel-caption d-none d-md-block">
<h5 style="color: yellow">Mountain Skies</h5>
<p>Beautiful mountain landscape.</p>
</div>
</div>
<div class="carousel-item">
<img src="images/paris.jpg" class="d-block w-100" alt="Slide 2">
<div class="carousel-caption d-none d-md-block">
<h5 style="color: yellow">Paris</h5>
<p>The city of lights.</p>
</div>
</div>
<div class="carousel-item">
<img src="images/ocean.jpg" class="d-block w-100" alt="Slide 3">
<div class="carousel-caption d-none d-md-block">
<h5 style="color: yellow">Ocean</h5>
<p>Peaceful ocean waves.</p>
</div>
</div>
</div>
<!-- Carousel Controls -->
<button class="carousel-control-prev" type="button" data-bs-target="#myCarousel" data-bs-slide="prev">
<span class="carousel-control-prev-icon"></span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#myCarousel" data-bs-slide="next">
<span class="carousel-control-next-icon"></span>
</button>
</div>
Carousel Structure:
Indicators (Dots):
Carousel Items:
Carousel Captions:
Navigation Controls:
Pro Tip: You should always set the first carousel item to be active, or nothing will show on the initial display!
Progress bars are an effective means of visually communicating completion, loading states or any other forms of progress that can be measured.
Code:
<h2>Progress Bar</h2>
<!-- Basic Progress Bar -->
<div class="progress mb-3">
<div class="progress-bar bg-success" style="width: 70%">70%</div>
</div>
<!-- Animated Striped Progress Bar -->
<div class="progress mb-3">
<div class="progress-bar progress-bar-striped progress-bar-animated bg-info" style="width: 50%">
Loading...
</div>
</div>
<!-- Multiple Progress Bars (Stacked) -->
<div class="progress mb-3">
<div class="progress-bar bg-info" style="width: 40%"></div>
<div class="progress-bar bg-warning" style="width: 30%"></div>
</div>
Explanation:
Basic Structure:
Color options include:
Striped & Animated:
You can stack multiple elements to create a progress-bar, which allows you to segment the progress (for example, showing you have completed different parts of a task-labeled labels on the bar is needed).
Common Uses
Name | Description |
modal | A dialog box/popup that overlays the page content |
modal-dialog | Container for the modal content, controls sizing |
modal-content | Wrapper for header, body, and footer sections |
modal-header | Top section with title and close button |
modal-body | Main content area of the modal |
modal-footer | Bottom section with action buttons |
tooltip | Small popup message that appears on hover |
popover | Larger popup with title and content, appears on click |
carousel | Image/content slider with navigation controls |
carousel-item | Individual slide within a carousel |
carousel-caption | Text overlay on carousel images |
carousel-indicators | Navigation dots for carousel slides |
progress | Container for progress bar visualization |
progress-bar | Colored bar showing completion percentage |
btn-close | Bootstrap’s styled close button (X icon) |
fade | CSS class that adds fade-in/out animation |
data-bs-toggle | Attribute that activates Bootstrap components |
data-bs-target | Specifies which element to control (by ID) |
data-bs-placement | Controls tooltip/popover position (top, left, etc.) |
Name | Description |
data-bs-toggle | Activates Bootstrap components (modal, tooltip, popover, etc.) |
data-bs-target | ID selector of the element to control or open |
data-bs-placement | Position of tooltip/popover (top, right, bottom, left) |
data-bs-dismiss | Closes/dismisses a component (e.g., modal) |
data-bs-ride | Auto-starts carousel on page load |
data-bs-slide | Controls carousel direction (prev/next) |
data-bs-slide-to | Jumps to specific carousel slide by index |
title | Text content for tooltips or popover headers |
data-bs-content | Body content for popovers |
tabindex=”-1″ | Removes element from normal tab navigation order |
mb-3 | Margin-bottom spacing utility (3 units) |
me-2 | Margin-end (right) spacing utility (2 units) |
w-50 | Width set to 50% |
w-100 | Width set to 100% |
mx-auto | Horizontal centering (auto left/right margins) |
d-block | Display as block element |
d-none | Hide element completely |
d-md-block | Display as block on medium screens and up |
progress-bar-striped | Adds striped pattern to progress bar |
progress-bar-animated | Animates the striped progress bar |
bg-success, bg-info, etc. | Bootstrap background color classes |
btn-primary, btn-secondary, etc. | Bootstrap button styling classes |
Here are some fantastic resources to your knowledge of Bootstrap:
Official Documentation:
Learning Resources:
Practice & Challenges:
Video Tutorials:
Design Inspiration:
Today you learned how to use Bootstrap’s interactive components like modals, tooltips, popovers, carousels, and progress bars to make your UI more engaging and user-friendly. You also understood how Bootstrap uses data attributes and simple JavaScript to activate these features.
You practiced creating sliders, animated progress bars, and popup elements, improving your layout and interaction skills. These components help you build modern, dynamic, and professional web pages quickly and efficiently.
A modal allows the user to view and interact with different types of content such as forms, alerts, or messages without navigating away from the current page.
Tooltips require JavaScript initialization via bootstrap.Tooltip()—if this step is missed, tooltips will not show up at all.
A popover is appropriate when you have larger content requirements such as a title and a detailed text. Tooltips, on the other hand, are intended solely for providing short hints.
Carousels are the ones that facilitate the creation of sliding image or content sliders. They are perfect for galleries, portfolios, and product showcases.
Users can see the progress of loading, completion, or steps visually through the use of progress bars which, in turn, helps them understand the system's status better.
Copyright © 2025 Niotechone Software Solution Pvt. Ltd. All Rights Reserved.