Getting Started Lesson 2 of 12
Getting Started with Bootstrap 5
Add Bootstrap 5 to a page with the CDN or downloaded files, use the starter template with the viewport meta tag, and load the JavaScript bundle for interactive components.
Adding Bootstrap to a page takes two lines. This lesson shows the recommended starter template and explains each part.
The starter template
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My Bootstrap Page</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<h1>Hello, Bootstrap!</h1>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
- The viewport meta tag is essential: without it, phones show a zoomed-out desktop version and the responsive grid doesn't work.
- The CSS link goes in the
<head>. - The JavaScript bundle goes just before
</body>. It's only needed for interactive components like dropdowns, modals, the mobile navbar toggle and carousels. The "bundle" version includes Popper, which positions dropdowns and tooltips.
CDN or download?
| Option | Pros | Cons |
|---|---|---|
| CDN link (above) | Easiest; may already be cached in the browser | Needs internet |
| Download from getbootstrap.com | Works offline (great for school labs) | You manage the files |
npm (npm install bootstrap) | Customize with Sass; used in bigger projects | Needs build tools |
For offline use, download the compiled files and link them with relative paths:
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="js/bootstrap.bundle.min.js"></script>
Try it
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/vendor/bootstrap.min.css">
</head>
<body>
<div class="container py-4">
<h1 class="text-primary">Hello, Bootstrap!</h1>
<p class="text-muted">This page uses Bootstrap 5.</p>
<div class="alert alert-info">Bootstrap is working if this box is light blue. ✅</div>
<button class="btn btn-primary">A Bootstrap button</button>
</div>
<script src="/vendor/bootstrap.bundle.min.js"></script>
</body>
</html>
Adding your own CSS
Put your own stylesheet after Bootstrap's, so your rules can override it:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="css/style.css">
Dark mode
Bootstrap 5.3 supports dark mode with one attribute:
<html data-bs-theme="dark">
<link rel="stylesheet" href="/vendor/bootstrap.min.css">
<body class="p-4">
<h2>Dark mode</h2>
<p>Add <code>data-bs-theme="dark"</code> to the html tag.</p>
<button class="btn btn-primary">Button</button>
</body>
</html>
Quick Quiz
Check what you learned. Walang grade ito, practice lang. 🙂
By Sir Reyel · Last updated 2026-12-04