← Learning Hub
Beginner

Buttons, Badges and Alerts

Buttons

Every button needs btn plus a colour class. Use btn-outline-* for an outline style and btn-sm / btn-lg for size.

Consistent buttons make an app easy to use: the main action on each screen (like "Place order") uses the strong primary colour, less important actions use outline or secondary styles, and dangerous actions ("Delete") use red. Bootstrap's colour names make this consistency automatic. Badges are small labels ("New", a cart count) and alerts are boxes for messages like success or error.

Example
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body class="p-3">
    <button class="btn btn-primary">Add to cart</button>
    <button class="btn btn-outline-secondary">Wishlist</button>
    <button class="btn btn-danger btn-sm">Remove</button>
    <button class="btn btn-success btn-lg w-100 mt-2">Buy now</button>
  </body>
</html>
▶ Try it yourself

Badges

Example
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body class="p-3">
    <h4>Smart Watch <span class="badge bg-success">20% off</span></h4>
    <p>Cart <span class="badge rounded-pill bg-danger">3</span></p>
  </body>
</html>
▶ Try it yourself

Alerts

Example
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body class="p-3">
    <div class="alert alert-success">Your order was placed!</div>
    <div class="alert alert-warning">Price may change at checkout.</div>
    <div class="alert alert-danger alert-dismissible fade show">
      Payment failed. Please try again.
      <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
  </body>
</html>
▶ Try it yourself
The close button on the last alert works because the example loads Bootstrap's JavaScript file at the bottom.
Key points
  • Buttons: btn + a colour like btn-primary.
  • Badges label things; alerts show messages.
  • Use colours by meaning: primary, success, danger, warning.

📝 Test yourself

1. Which two classes make a blue button?
2. Which class makes a button fill the full width?
3. Fill in the class for a small label like "New":
<span class=" bg-info">New</span>