๐ฏ Learning Objectives
- Understand what Bootstrap is and its benefits
- Learn how to add Bootstrap via CDN
- Link Bootstrap to HTML projects
- Test Bootstrap components
- Understand Bootstrap documentation
๐ What is Bootstrap?
Bootstrap is the world's most popular front-end framework for building responsive, mobile-first websites.
Why Use Bootstrap?
- โก Faster Development: Pre-built components save time
- ๐ฑ Responsive by Default: Mobile-first approach built-in
- ๐จ Professional Design: Clean, modern aesthetics
- ๐ง Customizable: Easy to modify and extend
- ๐ Cross-Browser Compatible: Works on all modern browsers
- ๐ Great Documentation: Extensive resources and examples
- ๐ฅ Large Community: Millions of developers worldwide
What Does Bootstrap Include?
- Grid System: Flexible layout structure (12-column grid)
- Components: Buttons, cards, navbars, forms, modals, etc.
- Utilities: Spacing, colors, typography, display classes
- JavaScript Plugins: Dropdowns, carousels, tooltips, etc.
๐ฆ Installing Bootstrap
Method 1: CDN (Content Delivery Network) - Recommended for Beginners
CDN is the fastest way to get started. Files are hosted online, no download needed!
Bootstrap CSS Link (Add to <head>):
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM"
crossorigin="anonymous">
Bootstrap JavaScript Bundle (Add before closing </body>):
<!-- Bootstrap JavaScript Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"
integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz"
crossorigin="anonymous"></script>
Method 2: Download Bootstrap Files
- Visit getbootstrap.com
- Click "Download" button
- Extract files to your project folder
- Link CSS and JS files locally
Complete HTML Template with Bootstrap
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My First Bootstrap Page</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"
rel="stylesheet">
</head>
<body>
<div class="container">
<h1 class="text-center mt-5">Hello, Bootstrap!</h1>
<p class="lead text-center">My first Bootstrap webpage</p>
<button class="btn btn-primary">Click Me</button>
</div>
<!-- Bootstrap JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
๐งช Testing Bootstrap Installation
Test 1: Bootstrap Button
<button class="btn btn-primary">Primary Button</button>
<button class="btn btn-success">Success Button</button>
<button class="btn btn-danger">Danger Button</button>
Expected Result: You should see three styled buttons with different colors (blue, green, red).
Test 2: Bootstrap Alert
<div class="alert alert-success" role="alert">
Bootstrap is working! โ
</div>
Test 3: Bootstrap Container
<div class="container">
<h1>Container Example</h1>
<p>This content is centered with padding on the sides.</p>
</div>
๐ Understanding Bootstrap Classes
Common Bootstrap Class Patterns
| Class | Purpose | Example |
|---|---|---|
container |
Fixed-width responsive container | <div class="container"> |
container-fluid |
Full-width container | <div class="container-fluid"> |
btn |
Button styling | <button class="btn btn-primary"> |
text-center |
Center text | <p class="text-center"> |
mt-3 |
Margin top (spacing) | <div class="mt-3"> |
p-4 |
Padding (all sides) | <div class="p-4"> |
Bootstrap Color Classes
btn-primary- Blue (main action)btn-secondary- Gray (secondary action)btn-success- Green (success)btn-danger- Red (danger/delete)btn-warning- Yellow (warning)btn-info- Cyan (information)btn-light- Light graybtn-dark- Dark gray
Live Button Examples:
Outline Button Examples:
๐ป Practice Activity: Create Your First Bootstrap Page
Task: Build a Simple Bootstrap Welcome Page
Create bootstrap-test.html with the following elements:
Complete Example Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bootstrap Test Page</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"
rel="stylesheet">
</head>
<body>
<!-- Navigation Bar -->
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container-fluid">
<a class="navbar-brand" href="#">My First Bootstrap Site</a>
</div>
</nav>
<!-- Main Content -->
<div class="container mt-5">
<h1 class="text-center text-primary">Welcome to Bootstrap! ๐</h1>
<p class="lead text-center">
Building responsive websites just got easier!
</p>
<!-- Alert Message -->
<div class="alert alert-success text-center" role="alert">
โ
Bootstrap is successfully installed and working!
</div>
<!-- Buttons -->
<div class="text-center mt-4">
<h3>Button Examples</h3>
<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>
<button class="btn btn-warning">Warning</button>
<button class="btn btn-info">Info</button>
</div>
<!-- Card Example -->
<div class="row mt-5">
<div class="col-md-6 mx-auto">
<div class="card">
<div class="card-body">
<h5 class="card-title">What is Bootstrap?</h5>
<p class="card-text">
Bootstrap is a powerful front-end framework that helps
you build responsive websites quickly and easily.
</p>
<a href="https://getbootstrap.com"
class="btn btn-primary"
target="_blank">
Learn More
</a>
</div>
</div>
</div>
</div>
</div>
<!-- Footer -->
<footer class="bg-dark text-white text-center p-4 mt-5">
<p>ยฉ 2025 My Bootstrap Journey</p>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Steps to Complete
- Create a new file:
bootstrap-test.html - Copy the code above
- Open in browser (Chrome, Firefox, Edge)
- Verify all components display correctly
- Try resizing the browser window to test responsiveness
๐ Bootstrap Documentation
Essential Resources
- Official Site: getbootstrap.com
- Components: Bootstrap Components
- Utilities: Bootstrap Utilities
- Examples: Bootstrap Examples
How to Use Bootstrap Documentation
- Visit the official Bootstrap website
- Navigate to "Docs" section
- Browse components or search for what you need
- Copy example code snippets
- Paste into your HTML and customize
โ๏ธ Practice Exercises
Exercise 1: Button Collection
Create a page with all button variants:
- All 8 color variations
- Different sizes (btn-sm, btn-lg)
- Outline buttons (btn-outline-primary)
Exercise 2: Alert Messages
Create different alert types:
- Success alert
- Warning alert
- Danger alert
- Info alert
Exercise 3: Text Utilities
Practice text alignment and colors:
- Center, left, and right aligned text
- Different text colors (text-primary, text-danger)
- Text sizes (display-1, lead)
โ Today's Deliverable
- Bootstrap linked to HTML file via CDN
- Working bootstrap-test.html with navbar
- At least 6 different colored buttons
- One alert message displayed
- One card component working
- Page tested in browser
- Screenshot of working Bootstrap page
๐ Troubleshooting Common Issues
Issue 1: Bootstrap Not Working
- โ Check internet connection (CDN requires internet)
- โ
Verify CSS link is in
<head> - โ
Verify JS script is before closing
</body> - โ Check for typos in class names
Issue 2: Buttons Look Plain
- โ
Make sure you have both
btnandbtn-primaryclasses - โ
Example:
<button class="btn btn-primary">
Issue 3: Layout Not Responsive
- โ
Check viewport meta tag in
<head> - โ
Must have:
<meta name="viewport" content="width=device-width, initial-scale=1.0">