Menu
Bootstrap 5 Navbars
Navigation Bars
A navigation bar is a navigation header that is placed at the top of the page:
Basic Navbar
With Bootstrap, a navigation bar can extend or collapse, depending on the screen size.
A standard navigation bar is created with the .navbar class, followed by a responsive collapsing class: .navbar-expand-xxl|xl|lg|md|sm (stacks the navbar vertically on xxlarge, extra large, large, medium or small screens).
To add links inside the navbar, use either an <ul> element (or a <div>) with class="navbar-nav". Then add <li> elements with a .nav-item class followed by an <a> element with a .nav-link class:
Example
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body>
<nav>
<div>
<ul>
<li>
<a href=”#”>Link 1</a>
</li>
<li>
<a href=”#”>Link 2</a>
</li>
<li>
<a href=”#”>Link 3</a>
</li>
</ul>
</div>
</nav>
<div>
<h3>Basic Navbar Example</h3>
<p>A navigation bar is a navigation header that is placed at the top of the page.</p>
<p>The navbar-expand-xxl|xl|lg|md|sm class determines when the navbar should stack vertically (on xxlarge, extra large, large, medium or small screens).</p>
</div>
</body>
</html>
Vertical Navbar
Remove the .navbar-expand-* class to create a navigation bar that will always be vertical:
Example
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body>
<nav>
<div>
<ul>
<li>
<a href=”#”>Link 1</a>
</li>
<li>
<a href=”#”>Link 2</a>
</li>
<li>
<a href=”#”>Link 3</a>
</li>
</ul>
</div>
</nav>
<div>
<h3>Vertical Navbar Example</h3>
<p>A navigation bar is a navigation header that is placed at the top of the page.</p>
</div>
</body>
</html>
Centered Navbar
Add the .justify-content-center class to center the navigation bar:
Example
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body>
<nav>
<ul>
<li>
<a href=”#”>Link 1</a>
</li>
<li>
<a href=”#”>Link 2</a>
</li>
<li>
<a href=”#”>Link 3</a>
</li>
</ul>
</nav>
<div>
<h3>Centered Navbar</h3>
<p>Use the .justify-content-center class to center the navigation bar.</p>
<p>In this example, the navbar will be centered on medium, large and extra large screens. On small screens it will be displayed vertically and left-aligned (because of the .navbar-expand-sm class).</p>
</div>
</body>
</html>
Colored Navbar
Tip: Add a white text color to all links in the navbar with the .navbar-dark class, or use the .navbar-light class to add a black text color.
Example
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body>
<div>
<h3>Colored Navbar</h3>
<p>Use any of the .bg-color classes to add a background color to the navbar.</p>
<p>Tip: Add a white text color to all links in the navbar with the .navbar-dark class, or use the .navbar-light class to add a black text color.</p>
</div>
<nav>
<div>
<ul>
<li>
<a href=”#”>Active</a>
</li>
<li>
<a href=”#”>Link</a>
</li>
<li>
<a href=”#”>Link</a>
</li>
<li>
<a href=”#”>Disabled</a>
</li>
</ul>
</div>
</nav>
<nav>
<div>
<ul>
<li>
<a href=”#”>Active</a>
</li>
<li>
<a href=”#”>Link</a>
</li>
<li>
<a href=”#”>Link</a>
</li>
<li>
<a href=”#”>Disabled</a>
</li>
</ul>
</div>
</nav>
<nav>
<div>
<ul>
<li>
<a href=”#”>Active</a>
</li>
<li>
<a href=”#”>Link</a>
</li>
<li>
<a href=”#”>Link</a>
</li>
<li>
<a href=”#”>Disabled</a>
</li>
</ul>
</div>
</nav>
<nav>
<div>
<ul>
<li>
<a href=”#”>Active</a>
</li>
<li>
<a href=”#”>Link</a>
</li>
<li>
<a href=”#”>Link</a>
</li>
<li>
<a href=”#”>Disabled</a>
</li>
</ul>
</div>
</nav>
<nav>
<div>
<ul>
<li>
<a href=”#”>Active</a>
</li>
<li>
<a href=”#”>Link</a>
</li>
<li>
<a href=”#”>Link</a>
</li>
<li>
<a href=”#”>Disabled</a>
</li>
</ul>
</div>
</nav>
<nav>
<div>
<ul>
<li>
<a href=”#”>Active</a>
</li>
<li>
<a href=”#”>Link</a>
</li>
<li>
<a href=”#”>Link</a>
</li>
<li>
<a href=”#”>Disabled</a>
</li>
</ul>
</div>
</nav>
<nav>
<div>
<ul>
<li>
<a href=”#”>Active</a>
</li>
<li>
<a href=”#”>Link</a>
</li>
<li>
<a href=”#”>Link</a>
</li>
<li>
<a href=”#”>Disabled</a>
</li>
</ul>
</div>
</nav>
<nav>
<div>
<ul>
<li>
<a href=”#”>Active</a>
</li>
<li>
<a href=”#”>Link</a>
</li>
<li>
<a href=”#”>Link</a>
</li>
<li>
<a href=”#”>Disabled</a>
</li>
</ul>
</div>
</nav>
</body>
</html>
.
Brand / Logo
The .navbar-brand class is used to highlight the brand/logo/project name of your page:
Example
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body>
<nav>
<div>
<a href=”#”>Logo</a>
</div>
</nav>
<div>
<h3>Brand / Logo</h3>
<p>The .navbar-brand class is used to highlight the brand/logo/project name of your page.</p>
</div>
</body>
</html>
When using the .navbar-brand class with images, Bootstrap 5 will automatically style the image to fit the navbar vertically.
Example
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body>
<nav>
<div>
<a href=”#”>
<img src=”img_avatar1.png” alt=”Logo” style=”width:40px;”>
</a>
</div>
</nav>
<div>
<h3>Brand / Logo</h3>
<p>When using the .navbar-brand class with images, Bootstrap 5 will automatically style the image to fit the navbar.</p>
</div>
</body>
</html>
Navbar Text
Use the .navbar-text class to vertical align any elements inside the navbar that are not links (ensures proper padding and text color).
Example
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body>
<nav>
<div>
<span>Navbar text</span>
</div>
</nav>
<div>
<h3>Navbar Text</h3>
<p>Use the .navbar-text class to vertical align any elements inside the navbar that are not links (ensures proper padding).</p>
</div>
</body>
</html>
Very often, especially on small screens, you want to hide the navigation links and replace them with a button that should reveal them when clicked on.
To create a collapsible navigation bar, use a button with class="navbar-toggler", data-bs-toggle="collapse" and data-bs-target="#thetarget". Then wrap the navbar content (links, etc) inside a <div> element with class="collapse navbar-collapse", followed by an id that matches the data-bs-target of the button: “thetarget“.
Example
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body>
<nav>
<div>
<a href=”#”>Logo</a>
<button type=”button” data-bs-toggle=”collapse” data-bs-target=”#collapsibleNavbar”>
<span></span>
</button>
<div id=”collapsibleNavbar”>
<ul>
<li>
<a href=”#”>Link</a>
</li>
<li>
<a href=”#”>Link</a>
</li>
<li>
<a href=”#”>Link</a>
</li>
</ul>
</div>
</div>
</nav>
<div>
<h3>Collapsible Navbar</h3>
<p>In this example, the navigation bar is hidden on small screens and replaced by a button in the top right corner (try to re-size this window).</p>
<p>Only when the button is clicked, the navigation bar will be displayed.</p>
<p>Tip: You can also remove the .navbar-expand-md class to ALWAYS hide navbar links and display the toggler button.</p>
</div>
</body>
</html>
Navbar With Dropdown
Example
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body>
<nav>
<div>
<a href=”#”>Logo</a>
<button type=”button” data-bs-toggle=”collapse” data-bs-target=”#collapsibleNavbar”>
<span></span>
</button>
<div id=”collapsibleNavbar”>
<ul>
<li>
<a href=”#”>Link</a>
</li>
<li>
<a href=”#”>Link</a>
</li>
<li>
<a href=”#”>Link</a>
</li>
<li>
<a href=”#” role=”button” data-bs-toggle=”dropdown”>Dropdown</a>
<ul>
<li><a href=”#”>Link</a></li>
<li><a href=”#”>Another link</a></li>
<li><a href=”#”>A third link</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<div>
<h3>Navbar With Dropdown</h3>
<p>This example adds a dropdown menu in the navbar.</p>
</div>
</body>
</html>
Navbar Forms and Buttons
Example
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body>
<nav>
<div>
<a href=”javascript:void(0)”>Logo</a>
<button type=”button” data-bs-toggle=”collapse” data-bs-target=”#mynavbar”>
<span></span>
</button>
<div id=”mynavbar”>
<ul>
<li>
<a href=”javascript:void(0)”>Link</a>
</li>
<li>
<a href=”javascript:void(0)”>Link</a>
</li>
<li>
<a href=”javascript:void(0)”>Link</a>
</li>
</ul>
<form>
<input type=”text” placeholder=”Search”>
<button type=”button”>Search</button>
</form>
</div>
</div>
</nav>
<div>
<h3>Navbar Forms</h3>
<p>You can also include forms inside the navigation bar.</p>
</div>
</body>
</html>
Fixed Navigation Bar
The navigation bar can also be fixed at the top or at the bottom of the page.
A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll.
The .fixed-top class makes the navigation bar fixed at the top:
Example
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body style=”height:1500px”>
<nav>
<div>
<a href=”#”>Fixed top</a>
</div>
</nav>
<div style=”margin-top:80px”>
<h3>Top Fixed Navbar</h3>
<p>A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll.</p>
<h1>Scroll this page to see the effect</h1>
</div>
</body>
</html>
Use the .fixed-bottom class to make the navbar stay at the bottom of the page:
Example
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body style=”height:1500px”>
<nav>
<div>
<a href=”#”>Fixed bottom</a>
</div>
</nav>
<div><br>
<h3>Bottom Fixed Navbar</h3>
<p>A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll.</p>
<h1>Scroll this page to see the effect</h1>
</div>
</body>
</html>
Use the .sticky-top class to make the navbar fixed/stay at the top of the page when you scroll past it. Note: This class does not work in IE11 and earlier (will treat it as position:relative).
Example
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body style=”height:1500px”>
<div>
<br>
<h3>Sticky Navbar</h3>
<p>A sticky navigation bar stays fixed at the top of the page when you scroll past it.</p>
<p>Scroll this page to see the effect. <strong>Note:</strong> sticky-top does not work in IE11 and earlier.</p>
</div>
<nav>
<div>
<a href=”#”>Sticky top</a>
</div>
</nav>
<div><br>
<p>Some example text. Some example text. Some example text. Some example text. Some example text.</p>
<p>Some example text. Some example text. Some example text. Some example text. Some example text.</p>
<p>Some example text. Some example text. Some example text. Some example text. Some example text.</p>
<p>Some example text. Some example text. Some example text. Some example text. Some example text.</p>
</div>
</body>
</html>