Bootstrap Buttons
14 April 2025 | Category: Bootstrap
Bootstrap Tutorial: Create Stylish Buttons
In this Bootstrap tutorial, you’ll learn how to use Bootstrap’s Button classes to create colorful, responsive buttons. We’ll add images to make the examples pop and show how buttons can enhance your webpage.
What You’ll Learn
- Creating basic buttons
- Using different button colors
- Adjusting button sizes
- Combining buttons with images
Prerequisites
- Basic knowledge of HTML
- A text editor (e.g., VS Code, Notepad)
- A web browser (e.g., Chrome, Firefox)
Step 1: Understand Bootstrap Buttons
Bootstrap Buttons use classes like btn
, btn-primary
, and btn-lg
to style <button>
or <a>
tags. They’re versatile for forms, links, or actions, with built-in responsive design.
Assume Bootstrap CSS is included in your project (we’ll skip the <link>
tag as requested).
Step 2: Create Basic Buttons
Start with a few colored buttons. Use this code:
<div class="container">
<button class="btn btn-primary me-2">Primary</button>
<button class="btn btn-success">Success</button>
</div>
Explanation:
container
: Centers and constrains content.btn
: Applies base button styling (padding, rounded corners).btn-primary
: Blue button for main actions.btn-success
: Green button for positive actions.me-2
: Adds margin-right for spacing.
These buttons are bold and clickable.
Step 3: Use Different Button Styles
Bootstrap offers various styles, like outline and contextual colors. Try this:
<div class="container">
<button class="btn btn-outline-warning me-2">Warning</button>
<button class="btn btn-danger me-2">Danger</button>
<a href="#" class="btn btn-info">Info Link</a>
</div>
Explanation:
btn-outline-warning
: Yellow outlined button for subtle cautions.btn-danger
: Red button for critical actions.btn-info
: Blue button on an<a>
tag for links.me-2
: Spaces buttons apart.
These styles add variety to your button designs.
Step 4: Adjust Button Sizes
Control button size with classes like btn-lg
or btn-sm
. Add this:
<div class="container">
<button class="btn btn-primary btn-lg me-2">Large Button</button>
<button class="btn btn-success me-2">Normal Button</button>
<button class="btn btn-secondary btn-sm">Small Button</button>
</div>
Explanation:
btn-lg
: Makes a larger button.btn-sm
: Makes a smaller button.- No size class means default size.
This shows buttons in large, medium, and small formats.
Step 5: Combine Buttons with an Image
Pair a button with a dummy image for a richer layout. Use this:
<div class="container">
<div class="row">
<div class="col-8">
<h3>Call to Action</h3>
<p>Click below to explore our features.</p>
<button class="btn btn-primary btn-lg">Discover Now</button>
</div>
<div class="col-4">
<img src="https://placehold.co/200x150/17a2b8/ffffff" class="img-fluid rounded" alt="Teal placeholder">
</div>
</div>
</div>
Explanation:
row
andcol-8
,col-4
: Splits content into text/buttons (8 units) and image (4 units).btn-lg
: Makes the button prominent.- Uses a 200×150 teal image for visual appeal.
The image enhances the button’s context.
Final Code
Here’s a combined example with varied buttons and an image:
<div class="container">
<div class="row mb-3">
<div class="col-12">
<button class="btn btn-success me-2">Save</button>
<button class="btn btn-outline-danger me-2">Cancel</button>
<a href="#" class="btn btn-info">Learn More</a>
</div>
</div>
<div class="row mb-3">
<div class="col-12">
<button class="btn btn-primary btn-lg me-2">Big Action</button>
<button class="btn btn-secondary btn-sm">Tiny Action</button>
</div>
</div>
<div class="row">
<div class="col-7">
<h3>Ready to Start?</h3>
<p>Join us with a single click.</p>
<button class="btn btn-warning btn-lg">Sign Up</button>
</div>
<div class="col-5">
<img src="https://placehold.co/250x150/ff6b6b/ffffff" class="img-fluid rounded" alt="Red placeholder">
</div>
</div>
</div>
Output
Your webpage should show:
- A row with green, red-outlined, and blue buttons.
- A row with a large blue button and a small gray button.
- A two-column section with a yellow button, text, and a red image (250×150).
- All buttons are responsive, adjusting for mobile, with colorful images for a vibrant look.
Next Steps
- Check the Bootstrap Buttons Docs for more styles.
- Try
btn-block
for full-width buttons. - Add buttons to Bootstrap forms for interactivity.
Conclusion
You’ve mastered Bootstrap Buttons! With classes like btn-primary
, btn-lg
, and btn-outline
, plus striking images, you’ve created dynamic, stylish buttons. Keep experimenting to enhance your webpages.