🗂️ Bootstrap 5 – Navs & Tabs: Organize Content with Tabbed Navigation
🧲 Introduction – What Are Navs and Tabs in Bootstrap 5?
Navs and Tabs in Bootstrap 5 help you create tabbed interfaces, navigation menus, and content toggling without extra JavaScript. They are fully responsive, keyboard accessible, and customizable via utility classes.
🎯 In this guide, you’ll learn:
- How to use
.nav
and.nav-tabs
for tabbed interfaces - Create pill-style tabs and vertical menus
- Control tab content visibility with data attributes
- Improve navigation UX with proper ARIA roles
✅ Example 1 – Basic Tabs Navigation
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="home-tab" data-bs-toggle="tab"
data-bs-target="#home" type="button" role="tab" aria-controls="home" aria-selected="true">
Home
</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="profile-tab" data-bs-toggle="tab"
data-bs-target="#profile" type="button" role="tab" aria-controls="profile" aria-selected="false">
Profile
</button>
</li>
</ul>
<div class="tab-content mt-3" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
<p>This is the Home tab content.</p>
</div>
<div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">
<p>This is the Profile tab content.</p>
</div>
</div>
🔍 Explanation:
Element/Class | Purpose |
---|---|
.nav-tabs | Creates tab-style navigation |
.nav-link , .nav-item | Defines each tab button |
data-bs-toggle="tab" | Enables tab toggle behavior |
.tab-content , .tab-pane | Wraps the corresponding tab content |
.fade , .show , .active | Controls visibility and animation effects |
✅ Example 2 – Pills Navigation
<ul class="nav nav-pills mb-3">
<li class="nav-item">
<a class="nav-link active" data-bs-toggle="pill" href="#pills-home">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#pills-settings">Settings</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane fade show active" id="pills-home">Home tab content</div>
<div class="tab-pane fade" id="pills-settings">Settings tab content</div>
</div>
🔍 Difference:
.nav-pills
gives tabs a pill-like appearance.- Good for settings panels, dashboards, or wizard interfaces.
✅ Example 3 – Vertical Tabs
<div class="d-flex align-items-start">
<div class="nav flex-column nav-pills me-3" id="v-pills-tab" role="tablist">
<button class="nav-link active" id="v-home-tab" data-bs-toggle="pill" data-bs-target="#v-home"
type="button" role="tab">Home</button>
<button class="nav-link" id="v-profile-tab" data-bs-toggle="pill" data-bs-target="#v-profile"
type="button" role="tab">Profile</button>
</div>
<div class="tab-content">
<div class="tab-pane fade show active" id="v-home" role="tabpanel">Home content</div>
<div class="tab-pane fade" id="v-profile" role="tabpanel">Profile content</div>
</div>
</div>
🔍 Use Case:
- Ideal for sidebars, admin panels, and split layout interfaces.
🛠️ Best Practices for Navs & Tabs
Practice | Why It Helps |
---|---|
Always pair tab with its content | Prevents broken UI and improves accessibility |
Use unique id and aria labels | Helps screen readers and keyboard navigation |
Prefer .nav-tabs for visual separation | Good for top menu interfaces |
Use .nav-pills for modern look | Smooth rounded edges and less visual noise |
Avoid placing heavy content in tabs | Improves performance and usability |
📌 Summary – Tabs for Smart UI Navigation
Bootstrap 5 navs and tabs provide a semantic, accessible way to organize and toggle between content sections. With minimal effort, you can create visually appealing, responsive tabbed interfaces that elevate your UX.
🔍 Key Takeaways:
- Use
.nav-tabs
or.nav-pills
for horizontal tab navigation - Combine with
.tab-content
and.tab-pane
to display dynamic content - Use
data-bs-toggle="tab"
or"pill"
for automatic behavior - Tabs are great for forms, dashboards, settings, and feature comparisons
⚙️ Perfect for user profiles, tabbed settings panels, or product detail views.
❓ FAQs – Bootstrap 5 Navs & Tabs
❓ What’s the difference between .nav-tabs
and .nav-pills
?
✅ .nav-tabs
have borders and look like folder tabs, while .nav-pills
have smooth pill-style buttons.
❓ Can I switch tabs programmatically?
✅ Yes. Use JavaScript:
var tab = new bootstrap.Tab(document.querySelector('#profile-tab'));
tab.show();
❓ Is it possible to use dropdowns in tabs?
✅ Yes. You can nest a .dropdown
inside a .nav-item
, but ensure the tab content links work with data-bs-toggle="tab"
.
❓ Do tabs work without JavaScript?
❌ No. Tabs require Bootstrap’s JavaScript (Tab plugin) to function.
Share Now :