Aral Code

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?

OptionProsCons
CDN link (above)Easiest; may already be cached in the browserNeeds internet
Download from getbootstrap.comWorks offline (great for school labs)You manage the files
npm (npm install bootstrap)Customize with Sass; used in bigger projectsNeeds 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

Example A complete Bootstrap page
<!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:

Example Dark color mode
<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. 🙂

1. Why is the viewport meta tag important?
2. When do you need Bootstrap's JavaScript bundle?
3. Where should your own stylesheet be linked?
4. Which class is from an older Bootstrap version, not v5?

By Sir Reyel · Last updated 2026-12-04