Navbar basics
The navbar is the responsive header bar that holds a brand, links and other navigation.
In this page:
Syntax
<nav class="navbar navbar-expand-lg bg-body-tertiary">
<div class="container-fluid">
<a class="navbar-brand" href="#">Brand</a>
<div class="navbar-nav">
<a class="nav-link" href="#">Link</a>
</div>
</div>
</nav>
Navbar basics
Create a nav with .navbar and .navbar-expand-lg to expand at lg, add a colour scheme with data-bs-theme="dark" and a background class. Inside, put .navbar-brand, a .navbar-toggler button and a .collapse.navbar-collapse containing .navbar-nav links.
The toggler needs the Bootstrap JavaScript.
Note:
navbar-expand-{breakpoint} controls where the links stop collapsing.
Example: Navbar basics
<!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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body class="p-3">
<nav class="navbar navbar-expand-lg bg-dark" data-bs-theme="dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">Site</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#nav" aria-controls="nav" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>
<div class="collapse navbar-collapse" id="nav">
<ul class="navbar-nav me-auto"><li class="nav-item"><a class="nav-link active" href="#">Home</a></li><li class="nav-item"><a class="nav-link" href="#">Pricing</a></li></ul>
</div>
</div>
</nav>
</body>
</html>
Live Example
Related Topics
Common Mistakes
- Forgetting the JS bundle for the toggler
- Missing data-bs-target ids
- Not choosing an expand breakpoint
Chapter Summary
- .navbar with navbar-expand-*
- Brand, toggler and collapse
- navbar-nav holds links
- Needs the JS bundle for toggling
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: