Buttons in Bootstrap are created using the .btn
class. Bootstrap offers different styles, sizes, and states for buttons.
Bootstrap provides different types of buttons based on their purpose.
π Example: Basic Buttons
<button class="btn btn-primary">Primary Button</button>
<button class="btn btn-secondary">Secondary Button</button>
<button class="btn btn-success">Success Button</button>
<button class="btn btn-danger">Danger Button</button>
<button class="btn btn-warning">Warning Button</button>
<button class="btn btn-info">Info Button</button>
<button class="btn btn-light">Light Button</button>
<button class="btn btn-dark">Dark Button</button>
β Explanation:
.btn
is the base class for buttons.
.btn-primary
, .btn-danger
, etc., apply different colors based on Bootstrap’s theme.
Bootstrap allows different button sizes using .btn-lg
, .btn-sm
, and default size.
π Example: Button Sizes
<button class="btn btn-primary btn-lg">Large Button</button>
<button class="btn btn-primary">Default Button</button>
<button class="btn btn-primary btn-sm">Small Button</button>
β Explanation:
.btn-lg
makes the button larger.
.btn-sm
creates a smaller button.
Outline buttons have a transparent background and a colored border.
π Example: Outline Buttons
<button class="btn btn-outline-primary">Outline Primary</button>
<button class="btn btn-outline-success">Outline Success</button>
<button class="btn btn-outline-danger">Outline Danger</button>
You can disable a button or show an active state.
π Example: Disabled & Active Buttons
<button class="btn btn-primary active">Active Button</button>
<button class="btn btn-secondary" disabled>Disabled Button</button>
Bootstrap provides different types of alert messages using the .alert
class.
π Example: Basic Alerts
<div class="alert alert-primary">This is a primary alert!</div>
<div class="alert alert-success">This is a success alert!</div>
<div class="alert alert-danger">This is a danger alert!</div>
<div class="alert alert-warning">This is a warning alert!</div>
<div class="alert alert-info">This is an info alert!</div>
<div class="alert alert-light">This is a light alert!</div>
<div class="alert alert-dark">This is a dark alert!</div>
β Explanation:
.alert
is the base class for alerts.
.alert-success
, .alert-danger
, etc., change the alert’s color.
You can add a close button inside alerts using .alert-dismissible
.
π Example: Dismissible Alert
<div class="alert alert-warning alert-dismissible fade show" role="alert">
This is a warning alert with a close button!
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
β Explanation:
.alert-dismissible
allows the alert to be closed.
.btn-close
is the close button.
data-bs-dismiss="alert"
enables the close functionality.
You can add headings and additional content inside alerts.
π Example: Alert with Heading
<div class="alert alert-info">
<h4 class="alert-heading">Important Info</h4>
<p>This is an important message that needs attention.</p>
</div>
Bootstrap Buttons & Alerts make it easy to add interactive elements and notifications to your web pages. With a variety of styles, sizes, and features like dismissible alerts, you can enhance the user experience efficiently. π
Let me know if you need further customization! π