Welcome to another phase of your dive into Bootstrap! Today, we will be looking at some of the most fun and commonly used Bootstrap components including Buttons, Alerts, Badges and Cards. These components are some of the elements that make websites interactive, aesthetically pleasing, and easy for users to interact with.
Think about any contemporary website you visit, and you’re going to see colorful buttons that click, notification badges for unread messages, alert boxes for updates, collections of cards that display content in a cohesive way. You will learn how to build all these components using only a few lines of code!
Why is it important for students and beginners?
Let’s go! Time to turn some plain old HTML into stunning interactive components!
To begin, we can create the proper HTML Structure and include Bootstrap:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bootstrap Components Demo</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<!-- Our components will go here -->
</body>
</html>
What are we doing here?
Pro Tip: If you want anything with interactivity (dropdowns, modals, dismissible alerts, etc.), you need to include the Bootstrap JavaScript file.
Now, let’s add some variations on buttons:
<h1 class="text-center">Buttons</h1>
<button class="btn btn-primary">Primary</button>
<button class="btn btn-secondary">Secondary</button>
<button class="btn btn-success">Success</button>
<button class="btn btn-danger">Danger</button>
Understanding Button Classes:
Why not just a button? Plain HTML buttons tend to look bland and inconsistent across different browsers. Bootstrap buttons:
Let’s add more color options, in addition to contextual buttons::
<button class="btn btn-warning">Warning</button>
<button class="btn btn-info">Info</button>
<button class="btn btn-light">Light</button>
<button class="btn btn-dark">Dark</button>
<button class="btn btn-link">Link</button>
Each button color has a purpose:
Each button color has a purpose:
Note: The entities give non-breaking spaces between buttons so they are scoped from one another. In production, you’d typically use CSS margin classes instead.
Bootstrap provides a simple way to have buttons with several sizes:
<button class="btn btn-primary btn-lg">Large Button</button>
<button class="btn btn-secondary btn-sm">Small Button</button>
Size classes:
When to use sizes:
<button class="btn btn-primary w-100">Full Width</button><br><br>
<button class="btn btn-danger" disabled>Disabled</button>
What these do:
Pro Tip: Full width buttons are great when designing for mobile-first and you want users to easily tap!
Alerts are a way to display important information to the user:
<h1 style="text-align: center">Bootstrap Alerts</h1>
<div class="alert alert-success">This is a success alert!</div>
<div class="alert alert-primary">Primary</div>
<div class="alert alert-secondary">Secondary</div>
<div class="alert alert-danger">Danger</div>
<div class="alert alert-warning">Warning</div>
<div class="alert alert-info">Info</div>
Understanding Alerts:
What you need to understand about Alerts:
Why use alerts? Alerts provide visual feedback to the user about their actions. Without alerts, the user would not know whether their submission was successful or not!
Let’s create an alert that the user can dismiss:
<div class="alert alert-secondary alert-dismissible fade show" role="alert">
<strong>Warning!</strong> This is a dismissible alert
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
Breaking down this code:
When to use dismissible alerts?
Common Mistake: Forgetting to include the required bootstrap JavaScript file to enable dismissible alerts!
Badges are a small label that draws attention to a new or important object:
<h1 style="text-align: center">Bootstrap Badges</h1>
<h6>1. Badge inside Heading</h6>
<h4>Notification <span class="badge bg-danger">5</span></h4>
<h6>2. Badge on Button</h6>
<button class="btn btn-primary">Message<span class="badge bg-light text-dark">3</span></button>
<h6>3. Badge Variants</h6>
<span class="badge bg-success">Success</span>
<span class="badge bg-info text-dark">Info</span>
Understanding Badges:
Understanding Badges:
Real-world examples:
Pro Tip: The text-dark class is important to badge light in color!
Cards are versatile containers for showcasing information:
<h1 style="text-align: center">Bootstrap Cards</h1>
<div class="card" style="width: 18rem">
<div class="card-body">
<h5 class="card-title">Card Title</h5>
<p class="card-text">Some quick example text.</p>
<a href="day2.html" class="btn btn-primary">Go somewhere</a>
</div>
</div>
Card format:
Why use cards? Cards are the Swiss Army knife of web design. They can display:
Why cards? Cards are the Swiss Army knife of web design. Cards can display:
<div class="card" style="width: 18rem">
<img src="images/pic_trulli.jpg" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card with Image</h5>
<p class="card-text">Some quick text about the image.</p>
</div>
</div>
What is new here:
Note – Don’t forget to always add an alt attribute for images for accessibility for seo!
<div class="card" style="width: 18rem">
<div class="card-header">Featured</div>
<div class="card-body">
<h5 class="card-title">Card Title</h5>
<p class="card-text">With a header and footer.</p>
</div>
<div class="card-footer text-muted">Footer text</div>
</div>
New components
Use cases:
This is a card with text above the image:
<div class="card text-white">
<img src="images/paris.jpg" class="card-img" alt="...">
<div class="card-img-overlay">
<h5 class="card-title">Overlay Title</h5>
<p class="card-text">This is an overlay on the image.</p>
</div>
</div>
How it works:
How it works:
Best Use Cases:
Design Tip: Ensure that your image(s) are dark enough that the white text remains legible! Use a semi-transparent overlay on a light image.
Card groups are used for grouping multiple cards together:
<h1 style="text-align: center">Card Groups & Decks</h1>
<div class="card-group">
<div class="card">
<img src="images/nature.jpg" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card 1</h5>
<p class="card-text">Some text.</p>
</div>
</div>
<div class="card">
<img src="images/pic_trulli.jpg" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Card 2</h5>
<p class="card-text">Some text.</p>
</div>
</div>
</div>
What card-group does:
Best for: Pricing tables, comparison charts, or feature lists where you want all the cards to be the same height.
<div class="row row-cols-1 row-cols-md-3 g-4">
<div class="col">
<div class="card">
<img src="images/nature.jpg" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Card content...</p>
</div>
</div>
</div>
</div>
Understanding the grid classes:
Why this matters:
This creates a responsive layout – one column on phones, three columns on larger screens. Your layout automatically adapts to screen size!
Pro Tip: Bootstrap’s grid system is incredibly powerful. Master it, and you can create any layout!
Button System
The button system in Bootstrap uses a two-part class structure:
1. Base class (btn): Provides fundamental button styling, including padding, border, font, and interactive states
2. Variant class (btn-primary, btn-danger, etc.): Applies specific colors and semantic meaning
This modular approach allows you to easily change button appearance by simply swapping the variant class. The system also includes:
Alert System
Bootstrap alerts provide contextual feedback messages. The structure follows this pattern:
The dismissible functionality requires:
Badge System
Badges are inline elements that use the <span> tag. They’re designed to be:
Flexible: Can be placed inside buttons, headings, or standalone
Semantic: Background colors convey meaning (danger, success, etc.)
Adaptable: Text color can be adjusted with utility classes like text-dark
Card System
Cards are Bootstrap’s most versatile component. The hierarchy is:
.card (container)
├── .card-header (optional)
├── .card-img-top (optional)
├── .card-body (main content)
│ ├── .card-title
│ └── .card-text
└── .card-footer (optional)
For overlay cards, the structure changes to:
.card
├── .card-img (full-size background image)
└── .card-img-overlay (content layer on top)
Layout styles:
1.Components / Keywords Used
Name | Description |
btn | Base class for all Bootstrap buttons, provides fundamental styling |
alert | Container for displaying contextual feedback messages to users |
badge | Small inline label used for counts, status indicators, or tags |
card | Flexible content container with border, padding, and optional components |
card-body | Main content area inside a card with proper padding |
card-header | Top section of a card, typically used for titles or categories |
card-footer | Bottom section of a card, often for metadata or secondary actions |
card-img-top | Image positioned at the top of a card with rounded corners |
card-img-overlay | Content layer positioned on top of a card image |
card-group | Container that connects multiple cards as a single attached unit |
btn-close | Bootstrap’s styled close button for dismissible components |
alert-dismissible | Makes an alert closeable with a dismiss button |
2. Key Properties / Parameters / Features
Name | Description |
btn-primary | Primary action button, typically blue, for main actions |
btn-secondary | Secondary button for less important actions |
btn-success | Green button indicating positive/success actions |
btn-danger | Red button for destructive or dangerous actions |
btn-warning | Orange/yellow button for cautionary actions |
btn-info | Light blue button for informational actions |
btn-lg | Large button size modifier |
btn-sm | Small button size modifier |
w-100 | Utility class making element full width (100%) |
disabled | HTML attribute preventing interaction with button |
alert-{variant} | Color variants for alerts (success, danger, warning, info, etc.) |
fade show | Animation classes for smooth transitions when dismissing |
bg-{color} | Background color utilities (bg-danger, bg-success, etc.) |
text-dark | Makes text dark colored for better contrast on light backgrounds |
text-white | Makes text white for dark backgrounds or image overlays |
text-muted | Lightens text color to indicate less important content |
card-title | Styled heading within a card body |
card-text | Regular paragraph text with appropriate card styling |
row | Bootstrap grid row container |
row-cols-{n} | Defines number of columns per row at different breakpoints |
g-{n} | Gutter spacing between grid columns (g-4 = 1.5rem spacing) |
data-bs-dismiss | Bootstrap attribute that triggers dismissal of components |
role=”alert” | ARIA attribute improving accessibility for screen readers |
Try these experiments:
Next Steps – Keep Practicing!
Try these experiments:
Challenge yourself :
Finally, the best way to learn is to build real projects. Begin small, experiment often, and don’t be afraid to break things – this is truly how you learn!
Here are a few good resources to help you dive deeper into Bootstrap:
Official Documentation
Learning Platforms
Practice & Inspiration
Tools
Great work! You’ve just learned some of the most important components that Bootstrap has to offer. Let’s reflect on what you’ve just learned:
The most important takeaways
Skills You Have Acquired:
The beginner's easiest learning path to the Bootstrap is to construct small daily UI parts. At first, work with buttons, alerts, badges, and cards, and afterward, combine them in small projects like product grids, notification panels, or simple dashboards. Theoretical knowledge gets absorbed during the process of working on live projects.
Coloring buttons semantically will make your UX less puzzling and more comfortable for the user.
Alerts are the most accessible way to tell users the consequences of their actions—an excellent mix of submission, an error warning, or even a new update. If alerts are not used, then the users are supposed to guess what happened when they pressed a button. They are of paramount importance in furnishing clear and accessible feedback.
Bootstrap cards are among the most versatile components. You can use it from product listings to blog previews, pricing grids, user profiles, portfolios, or featured content. Their tidy structure allows easy layout building and makes them responsive by default.
Badges turn out to be the users' attention grabbers - they can show counts, statuses, or labels. Notifications, messages, items in a cart, or "new" tags are some of the areas where badges are most applicable. A tiny badge can still give a huge boost to your interface's interactivity and informality.
Copyright © 2025 Niotechone Software Solution Pvt. Ltd. All Rights Reserved.