Navs and tabs
Base nav
Navigation available in Bootstrap share general markup and styles, from the base .nav class to the active and disabled states. Swap modifier classes to switch between each style.
The base .nav component is built with flexbox and provide a strong foundation for building all types of navigation components. It includes some style overrides (for working with lists), some link padding for larger hit areas, and basic disabled styling.
<ul class="nav"> <li class="nav-item"> <a class="nav-link active" href="#">Active</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Link</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Link</a> </li> <li class="nav-item"> <a class="nav-link disabled" href="#">Disabled</a> </li> </ul>
Classes are used throughout, so your markup can be super flexible. Use <ul>s like above, <ol> if the order of your items is important, or roll your own with a <nav> element. Because the .nav uses display: flex, the nav links behave the same as nav items would, but without the extra markup.
<nav class="nav"> <a class="nav-link active"href="#">Active</a> <a class="nav-link" href="#">Link</a> <a class="nav-link" href="#">Link</a> <a class="nav-link disabled" href="#">Disabled</a> </nav>
Horizontal alignment
Change the horizontal alignment of your nav with flexbox utilities. By default, navs are left-aligned, but you can easily change them to center or right aligned.
Centered with .justify-content-center:
<ul class="nav justify-content-center">
...
</ul>
Right aligned with .justify-content-end:
<ul class="nav justify-content-end">
...
</ul>
Vertical
Stack your navigation by changing the flex item direction with the .flex-column utility. Need to stack them on some viewports but not others? Use the responsive versions (e.g., .flex-sm-column).
This works with both <ul> and <a>.
<ul class="nav flex-column">
...
</ul>
Tabs
Takes the basic nav from above and adds the .nav-tabs class to generate a tabbed interface.
<ul class="nav nav-tabs">
...
</ul>
Pills
Take that same HTML, but use .nav-pills instead.
<ul class="nav nav-pills">
...
</ul>
Fill and justify
Force your .nav’s contents to extend the full available width one of two modifier classes. To proportionately fill all available space with your .nav-items, use .nav-fill. Notice that all horizontal space is occupied, but not every nav item has the same width.
<ul class="nav nav-pills nav-fill">
...
</ul>
For equal-width elements, use .nav-justified. All horizontal space will be occupied by nav links, but unlike the .nav-fill above, every nav item will be the same width.
<ul class="nav nav-pills nav-justified">
...
</ul>
Working with flex utilities
If you need responsive nav variations, consider using a series of flexbox utilities. While more verbose, these utilities offer greater customization across responsive breakpoints. In the example below, our nav will be stacked on the lowest breakpoint, then adapt to a horizontal layout that fills the available width starting from the small breakpoint.
<ul class="nav nav-pills">
...
</ul>
Tabs and pills with dropdowns
<ul class="nav nav-tabs"> <li class="nav-item"> <a class="nav-link active" href="#">Active</a> </li> <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#">Dropdown</a> <ul class="dropdown-menu"> <li><a class="dropdown-item" href="#">Action</a></li> <li><a class="dropdown-item" href="#">Another action</a></li> <li><a class="dropdown-item" href="#">Something else here</a></li> <li><hr class="dropdown-divider"></li> <li><a class="dropdown-item" href="#">Separated link</a></li> </ul> </li> <li class="nav-item"> <a class="nav-link" href="#">Link</a> </li> <li class="nav-item"> <a class="nav-link disabled" href="#">Disabled</a> </li> </ul>
<ul class="nav nav-pills"> ... </ul>
JavaScript behavior
Below are some examples of how to use the navs with JavaScript to view content.
For more details, please visit the Bootstrap page.
<ul class="nav nav-tabs mb-2" id="myTab"> <li class="nav-item"> <button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#home">Home</button> </li> <li class="nav-item"> <button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#profile">Profile</button> </li> <li class="nav-item"> <button class="nav-link" id="contact-tab" data-bs-toggle="tab" data-bs-target="#contact">Contact</button> </li> </ul> <div class="tab-content" id="myTabContent"> <div class="tab-pane fade show active" id="home">HOME</div> <div class="tab-pane fade" id="profile">PROFILE</div> <div class="tab-pane fade" id="contact">CONTACT</div> </div>
<ul class="nav nav-pills mb-3" id="pills-tab"> <li class="nav-item"> <button class="nav-link active" id="home-pill" data-bs-toggle="pill" data-bs-target="#home">Home</button> </li> <li class="nav-item"> <button class="nav-link" id="profile-pill" data-bs-toggle="pill" data-bs-target="#profile">Profile</button> </li> <li class="nav-item"> <button class="nav-link" id="contact-pill" data-bs-toggle="pill" data-bs-target="#contact">Contact</button> </li> </ul> <div class="tab-content" id="pills-TabContent"> <div class="tab-pane fade show active" id="home">HOME</div> <div class="tab-pane fade" id="profile">PROFILE</div> <div class="tab-pane fade" id="contact">CONTACT</div> </div>
<div class="d-flex align-items-start"> <div class="nav flex-column nav-pills me-3" id="v-pills-tab"> <button class="nav-link active" id="v-pills-home-tab" data-bs-toggle="pill" data-bs-target="#v-pills-home">Home</button> <button class="nav-link" id="v-pills-profile-tab" data-bs-toggle="pill" data-bs-target="#v-pills-profile">Profile</buttona> <button class="nav-link" id="v-pills-messages-tab" data-bs-toggle="pill" data-bs-target="#v-pills-messages">Messages</button> <button class="nav-link" id="v-pills-settings-tab" data-bs-toggle="pill" data-bs-target="#v-pills-settings">Settings</button> </div> <div class="tab-content" id="v-pills-tabContent"> <div class="tab-pane fade show active" id="v-pills-home">HOME</div> <div class="tab-pane fade" id="v-pills-profile">PROFILE</div> <div class="tab-pane fade" id="v-pills-messages">MESSAGES</div> <div class="tab-pane fade" id="v-pills-settings">SETTINGS</div> </div> </div>