-
Hajipur, Bihar, 844101
Navigation is a core part of any website or web application, helping users move between pages and sections efficiently. Bootstrap 4 provides the Navs component, a flexible and responsive way to create horizontal or vertical navigation menus. Navs can be combined with tabs, pills, and other Bootstrap components to build professional-looking interfaces. This tutorial covers everything you need to know about BS4 Navs, from basic structure to advanced customization.
Navs are a collection of links arranged in a horizontal or vertical layout. They are built using <ul> elements with the .nav class and <li> elements with .nav-item. Links within nav items use the .nav-link class. Navs can be styled as tabs or pills, and can include active states, disabled links, and responsive alignment.
A simple horizontal navigation menu uses the .nav class with list items:
<ul class="nav">
<li class="nav-item">
<a class="nav-link active" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Messages</a>
</li>
</ul>
The .active class highlights the current page or selection, helping users identify their location.
You can create vertical navigation menus by adding the .flex-column class to the .nav element:
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link active" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Messages</a>
</li>
</ul>
Vertical navs are useful for sidebars or menus in dashboards and admin panels.
Bootstrap 4 allows navs to function as tabs using .nav-tabs. Tabs display content in a card-like style and are ideal for sectioned content.
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab">Profile</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane fade show active" id="home" role="tabpanel">Home content here.</div>
<div class="tab-pane fade" id="profile" role="tabpanel">Profile content here.</div>
</div>
Tabs are perfect for forms, FAQs, or multi-step content sections.
Pills provide a rounded, highlighted style for nav links using .nav-pills. Pills can be used horizontally or vertically.
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Messages</a>
</li>
</ul>
Pills are often used for filters, category selection, or feature tabs.
Links can be disabled using the .disabled class. Disabled links are visually dimmed and cannot be clicked.
<ul class="nav">
<li class="nav-item">
<a class="nav-link active" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
Disabled links provide clear feedback to users about unavailable options.
Nav links can be evenly spaced across the width of the container using .nav-justified. This is useful for menus or navigation bars that span the full width.
<ul class="nav nav-pills nav-justified">
<li class="nav-item">
<a class="nav-link active" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Messages</a>
</li>
</ul>
Alternatively, use .nav-fill to make nav links occupy equal width without the justified styling.
<ul class="nav nav-pills nav-fill">
<li class="nav-item">
<a class="nav-link active" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Messages</a>
</li>
</ul>
Fill is useful for responsive layouts and evenly spaced navigation elements.
Keep navigation labels short and descriptive.
Use .active to indicate the current page.
Use vertical navs for sidebars and horizontal navs for headers.
Choose tabs or pills depending on visual style and use case.
Ensure proper contrast and accessibility for all nav links.
Top Navigation Bar: Horizontal menu in the header with links to Home, Profile, Messages.
Sidebar Navigation: Vertical nav in admin dashboards or settings panels.
Tabbed Content: Switch between different sections of a page using tabs.
Filter Options: Use pills to allow users to select categories or filters.
Multi-step Forms: Display form steps as nav items for better UX.
Bootstrap 4 navs provide a flexible way to create horizontal or vertical navigation menus. They can be styled as tabs or pills, aligned using justified or fill classes, and include active or disabled states. Using navs effectively improves website usability, organizes content, and ensures a clean and professional interface.
Create a basic horizontal nav with three links: Home, Profile, Messages.
Create a vertical nav using .flex-column with three links.
Create a nav with tabs using .nav-tabs and display two corresponding content sections.
Create a nav with pills using .nav-pills and set the second pill as active.
Create a nav with one disabled link and two active links.
Create a nav with justified alignment using .nav-justified.
Create a nav with fill alignment using .nav-fill.
Create a tabbed interface with three tabs and show content when each tab is clicked.
Create a vertical pill navigation on the left with content on the right.
Create a nav inside a card header, combining tabs and active states for content switching.