Bootstrap Alerts & Badges

Feedback messages and labels.

✍️ 3 exercises + code challenge in this lesson

Alerts

.alert .alert-success shows a contextual message. Add .alert-dismissible and a close button with data-bs-dismiss="alert" to let users close it.

Badges

.badge .text-bg-primary creates a small label; .rounded-pill makes it pill-shaped.

Key Takeaways: Bootstrap Alerts & Badges

Mastering Bootstrap Alerts & Badges helps you write clean and reliable Bootstrap code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

Bootstrap Alerts & Badges Code Example

Bootstrap
<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>
<div class="container py-3">
  <div class="alert alert-success">Your profile was saved.</div>
  <div class="alert alert-danger alert-dismissible fade show">
    <strong>Error!</strong> Payment failed.
    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
  </div>
  <h4>Notifications <span class="badge text-bg-danger">4</span></h4>
  <span class="badge rounded-pill text-bg-primary">New</span>
  <span class="badge rounded-pill text-bg-success">Paid</span>
</div>
Free sign-in required · Google login available

Bootstrap Alerts & Badges Practice Exercises

Check what you learned in “Bootstrap Alerts & Badges”.

/ 3 solved
Fill in the blank

Create a success alert.

<div class="alert ">Saved!</div>
✓ Correct! Not quite. Try again.
Multiple choice

Which class makes a badge pill-shaped?

✓ Correct! Not quite. Try again.
Code challenge

Add an "alert alert-info" div with the text "New update available".

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services