Bootstrap 5 navs & tabs provide the simple and easy way to create horizontal and vertical nav & tab components.
Steps to Create Horizontal nav Component
.nav
class to the (<ul>
) or (<ol>
) nav container.
.nav-item
to the base class of the (<li>
) element.
.nav-link
to the base class of the (<a>
) element.
General Syntax
<ul class="nav">
<li class="nav-item">
<a class="nav-link" href="#">Nav Link</a>
</li>
</ul>
Source Code
<div class="container mt-5">
<h2 class="text-center">Bootstrap Navs</h2>
<ul class="nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Web Design</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Web Development</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Graphics Design</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">SEO</a>
</li>
</ul>
</div>
<!--/container-->
Navigation can also be created using <nav>
element.
Following are the steps to create Nav.
.nav
to the nav container, i.e. (<nav>
) element base class.
.nav-link
to the (<a>
) element base class.
Source Code
<div class="container mt-5">
<h2 class="text-center">Bootstrap Navs</h2>
<nav class="nav">
<a class="nav-link active" aria-current="page" href="#">Active</a>
<a class="nav-link" href="#">Link1</a>
<a class="nav-link" href="#">Link2</a>
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled Link3</a>
</nav>
</div>
<!--/container-->
Add .active
to the <a>
element's base class to make a nav item active, and to make a disabled navigation link, add .disabled
to the <a>
element's base class.
General Syntax
<ul class="nav">
<li class="nav-item">
<a class="nav-link active" href="#">Active Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled Link</a>
</li>
</ul>
Source Code
<div class="container mt-5">
<h2 class="text-center">Active/Disabled Nav Link</h2>
<ul class="nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Active Link1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link2</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link3</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled Link4</a>
</li>
</ul>
</div>
<!--/container-->
To make a disabled nav item, use .disabled
to the <a>
element's base class.
General Syntax
<ul class="nav">
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled Link </a>
</li>
</ul>
Source Code
<div class="container mt-5">
<h2 class="text-center">Disabled Nav Link</h2>
<ul class="nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Active Link1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link 2</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link 3</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled Link 4</a>
</li>
</ul>
</div>
<!--/container-->
By default navs is left-aligned, but it can be changed to the center or right using flexbox utility classes.
Add .justify-content-center
to the nav container's base class to align the nav item to the horizontal center.
Source Code
<div class="container mt-5">
<h2 class="text-center">Horizontal Alignment Of Navs</h2>
<ul class="nav justify-content-center">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Services</a>
</li>
</ul>
</div>
<!--/container-->
To align the nav item in the right direction of the web page, add .justify-content-end
to the nav container base class.
Source Code
<div class="container mt-5">
<h2 class="text-center">Nav:Right Alignment</h2>
<ul class="nav justify-content-end">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">App design</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Web design</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Graphics Design</a>
</li>
</ul>
</div>
<!--/container-->
Steps to create vertical nav system.
.nav
, and .flex-column
to the base class of the <ul>
element.
.nav-item
to the <li>
element's base class. .nav-link
to the <a>
element's base class.General Syntax
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Link 1</a>
</li>
</ul>
Source Code
<div class="container mt-5">
<h2 class="text-center">Vertical Nav</h2>
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Link1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link2</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link3</a>
</li>
</ul>
</div>
<!--/container-->
<nav>
ElementSource Code
<div class="container mt-5">
<h2 class="text-center">Vertical Nav</h2>
<nav class="nav flex-column">
<a class="nav-link active" aria-current="page" href="#">Link1</a>
<a class="nav-link" href="#">Link2</a>
<a class="nav-link" href="#">Link3</a>
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Link4</a>
</nav>
</div>
<!--/container-->
Steps to create tab menus:
.nav
and .nav-tabs
to the <ul>
element base class.
.nav-item
to the <li>
element base class.
.nav-link
to the <a>
element base class.
General Syntax
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
</ul>
Source Code
<div class="container mt-5">
<h2 class="text-center">Bootstrap Tabs</h2>
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Web Design</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">App Design </a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Graphics Design</a>
</li>
</ul>
</div>
<!--/container-->
Steps to create pills:
.nav
, and .nav-pills
to the base class of the <ul>
element.
.nav-item
to the base class of the <li>
element.
.nav-link
class to the base class of <a>
element.
General Syntax
<ul class="nav nav-pills">
<li class="nav-item"><a class="nav-link active" href="#">Nav Link</a> </li>
</ul>
Source Code
<div class="container mt-5">
<h2 class="text-center">Bootstrap Pills</h2>
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Web Design</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Graphics Design</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">App Design</a>
</li>
</ul>
</div>
<!--/container-->
.nav
,.nav-pills
& .flex-column
to the <ul>
element base class.
.nav-item
to the <li>
element base class.
.nav-link
to the <a>
element base class.
General Syntax
<ul class="nav nav-pills flex-column">
<li class="nav-item">
<a class="nav-link active" href="#">Link</a>
</li>
</ul>
Source Code
<div class="container">
<h2 class="text-center">Bootstrap Vertical Pills</h2>
<ul class="nav nav-pills flex-column">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Web Design</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Graphics Design</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">App Design</a>
</li>
</ul>
</div>
<!--/container-->
To extend the navigation nav into the whole available width, use .nav-fill
class to <ul>
having class either
.nav .nav-pills
or .nav .nav-tabs
. Please keep in mind that every nav item will not be the same width.
General Syntax
<ul class="nav nav-pills nav-fill">
<li class="nav-item">
<a class="nav-link active" href="#">Nav Link</a>
</li>
</ul>
Source Code
<div class="container mt-5">
<h2 class="text-center">Assigning Equal Width To Nav Menu</h2>
<ul class="nav nav-pills nav-fill">
<li class="nav-item">
<a class="nav-link active" href="#">App Design</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Graphics Design</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">SEO</a>
</li>
</ul>
</div>
<!--/container-->
General Syntax
<ul class="nav nav-tabs nav-fill">
<li class="nav-item">
<a class="nav-link active" href="#">Link</a>
</li>
</ul>
Source Code
<div class="container">
<h2 class="text-center">Full Width Tab Alignment</h2>
<ul class="nav nav-tabs nav-fill">
<li class="nav-item">
<a class="nav-link active" href="#">Web Design</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Graphics Design</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">App Design</a>
</li>
</ul>
</div>
<!--/container-->
To align equal width of nav/pill menu item, use .nav-justified
to <ul>
element having either
.nav .nav-pills
or .nav .nav-tabs
class.
Source Code
<div class="container mt-5">
<h2 class="text-center">Assigning Equal Width To Nav/Pill Menu</h2>
<ul class="nav nav-pills nav-justified">
<li class="nav-item">
<a class="nav-link active" href="#">Web Design</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Graphics Design</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">App Design</a>
</li>
</ul>
</div>
<!--/container-->
.nav
& .nav-tabs
to <nav>
element base class.
.nav-item
& .nav-link
to <a>
element base class.
General Syntax
<nav class="nav nav-tabs">
<a href="#" class="nav-item nav-link ">Link</a>
</nav>
Source Code
<div class="container mt-5">
<h2 class="text-center">Creating Nav Based Navigation</h2>
<nav class="nav nav-tabs">
<a href="#" class="nav-item nav-link active">Home</a>
<a href="#" class="nav-item nav-link">About</a>
<a href="#" class="nav-item nav-link">Services</a>
<a href="#" class="nav-item nav-link disabled" tabindex="-1">Contact</a>
</nav>
</div>
<!--/container-->
.nav
& .nav-pills
to the <nav>
element base class.
.nav-item
& .nav-link
to the <a>
element base class.
General Syntax
<nav class="nav nav-pills">
<a href="#" class="nav-item nav-link">Link</a>
</nav>
Source Code
<div class="container">
<h2 class="text-center">Creating Pill Based Navigation</h2>
<nav class="nav nav-pills">
<a href="#" class="nav-item nav-link active">Home</a>
<a href="#" class="nav-item nav-link">About</a>
<a href="#" class="nav-item nav-link">Contact</a>
</nav>
</div>
<!--/container-->
Bootstrap tabs/pills menus and dropdown concept are used to make dropdown tabs/pills menu.
General Syntax
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Services</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Service 1</a></li>
</ul>
</li>
</ul>
Source Code
<div class="container mt-5">
<h2 class="text-center">Bootstrap Tabs With Dropdown</h2>
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Services</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Services1</a></li>
<li><a class="dropdown-item" href="#">Services2</a></li>
<li><a class="dropdown-item" href="#">Services3</a></li>
</ul>
</li>
</ul>
</div>
<!--/container-->
General Syntax
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Services</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Services1</a></li>
</ul>
</li>
</ul>
Source Code
<div class="container">
<h2 class="text-center">Bootstrap Pills With Dropdown</h2>
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Services</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Services1</a></li>
<li><a class="dropdown-item" href="#">Services2</a></li>
<li><a class="dropdown-item" href="#">Services3</a></li>
</ul>
</li>
</ul>
</div>
<!--/container-->