Tutorials Bootstrap 5 Tutorial
Navbar Collapse Menu
Navbar Collapse Menu: free step-by-step lesson with examples, common mistakes, and interview tips — part of Bootstrap 5 Tutorial on Toolliyo Academy.
On this page
Bootstrap 5 Tutorial · Lesson 32 of 100
Navbar Collapse Menu
Setup & Utilities ✓ → Components & Forms → Theme & Integrate → Ship & Projects
Components & Forms · 2 — UI · ~6 min · Navigation and Forms
What is this?
A responsive navbar collapses into a toggler on small screens using data-bs-toggle="collapse" and a target id.
Why should you care?
Every BootVerse app needs a top nav that works on phones.
See it live — copy this example
Examples include Bootstrap 5.3 CDN links. Paste into an HTML file or use Run Example to preview.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>BootVerse</title>
</head>
<body class="p-3">
<nav class="navbar navbar-expand-lg bg-body-tertiary">
<div class="container-fluid">
<a class="navbar-brand" href="#">BootVerse</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navMain">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navMain">
<ul class="navbar-nav ms-auto">
<li class="nav-item"><a class="nav-link active" href="#">Home</a></li>
<li class="nav-item"><a class="nav-link" href="#">Reports</a></li>
</ul>
</div>
</div>
</nav>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Run Example »
Edit the code below and click Run to see the result in Toolliyo’s live editor.
What happened?
- expand-lg keeps the menu open from large screens up.
- Matching id on collapse target is required.
- Bundle JS powers the toggler.
Practice next
- Resize below lg to see the toggler.
- Fix a mismatched data-bs-target.
- Add a third link.
- Add a dropdown under Reports.
- Stick the nav with sticky-top.
Remember
Toggler + collapse id pair. Brand + links pattern. Test on a narrow viewport.
App chrome
Phone users open BootVerse.
Outcome: Menu opens and closes cleanly.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!