--- title: Navs and tabs description: Documentation and examples for how to use Bootstrap’s included navigation components. aliases: "/docs/[[config:docs_version]]/components/navs/" toc: true --- ## 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. The base `.nav` component does not include any `.active` state. The following examples include the class, mainly to demonstrate that this particular class does not trigger any special styling. To convey the active state to assistive technologies, use the `aria-current` attribute — using the `page` value for current page, or `true` for the current item in a set. `} /> Classes are used throughout, so your markup can be super flexible. Use ``} /> Right-aligned with `.justify-content-end`: `} /> ### 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`). `} /> As always, vertical navigation is possible without `
    `s, too. Active Link Link Disabled `} /> ### Tabs Takes the basic nav from above and adds the `.nav-tabs` class to generate a tabbed interface. Use them to create tabbable regions with our [tab JavaScript plugin](#javascript-behavior).
`} /> ### Pills Take that same HTML, but use `.nav-pills` instead: `} /> ### Underline Take that same HTML, but use `.nav-underline` instead: `} /> ### Fill and justify Force your `.nav`’s contents to extend the full available width with one of two modifier classes. To proportionately fill all available space with your `.nav-item`s, use `.nav-fill`. Notice that all horizontal space is occupied, but not every nav item has the same width. `} /> When using a ``} /> 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. `} /> Similar to the `.nav-fill` example using a ``} /> ## Working with flex utilities If you need responsive nav variations, consider using a series of [flexbox utilities]([[docsref:/utilities/flex]]). 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. Active Longer nav link Link Disabled `} /> ## Regarding accessibility If you’re using navs to provide a navigation bar, be sure to add a `role="navigation"` to the most logical parent container of the `
    `, or wrap a `
`} /> ## CSS ### Variables As part of Bootstrap’s evolving CSS variables approach, navs now use local CSS variables on `.nav`, `.nav-tabs`, and `.nav-pills` for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too. On the `.nav` base class: On the `.nav-tabs` modifier class: On the `.nav-pills` modifier class: On the `.nav-underline` modifier class: ### Sass variables ## JavaScript behavior Use the tab JavaScript plugin—include it individually or through the compiled `bootstrap.js` file—to extend our navigational tabs and pills to create tabbable panes of local content.

This is some placeholder content the Home tab’s associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other .nav-powered navigation.

This is some placeholder content the Profile tab’s associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other .nav-powered navigation.

This is some placeholder content the Contact tab’s associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other .nav-powered navigation.

This is some placeholder content the Disabled tab’s associated content.

```html
...
...
...
...
``` To help fit your needs, this works with `
    `-based markup, as shown above, or with any arbitrary “roll your own” markup. Note that if you’re using `
...
...
...
...
``` ### Via JavaScript Enable tabbable tabs via JavaScript (each tab needs to be activated individually): ```js const triggerTabList = document.querySelectorAll('#myTab button') triggerTabList.forEach(triggerEl => { const tabTrigger = new bootstrap.Tab(triggerEl) triggerEl.addEventListener('click', event => { event.preventDefault() tabTrigger.show() }) }) ``` You can activate individual tabs in several ways: ```js const triggerEl = document.querySelector('#myTab button[data-bs-target="#profile"]') bootstrap.Tab.getInstance(triggerEl).show() // Select tab by name const triggerFirstTabEl = document.querySelector('#myTab li:first-child button') bootstrap.Tab.getInstance(triggerFirstTabEl).show() // Select first tab ``` ### Fade effect To make tabs fade in, add `.fade` to each `.tab-pane`. The first tab pane must also have `.show` to make the initial content visible. ```html
...
...
...
...
``` ### Methods Activates your content as a tab element. You can create a tab instance with the constructor, for example: ```js const bsTab = new bootstrap.Tab('#myTab') ``` | Method | Description | | --- | --- | | `dispose` | Destroys an element’s tab. | | `getInstance` | Static method which allows you to get the tab instance associated with a DOM element, you can use it like this: `bootstrap.Tab.getInstance(element)`. | | `getOrCreateInstance` | Static method which returns a tab instance associated to a DOM element or create a new one in case it wasn’t initialized. You can use it like this: `bootstrap.Tab.getOrCreateInstance(element)`. | | `show` | Selects the given tab and shows its associated pane. Any other tab that was previously selected becomes unselected and its associated pane is hidden. **Returns to the caller before the tab pane has actually been shown** (i.e. before the `shown.bs.tab` event occurs). | ### Events When showing a new tab, the events fire in the following order: 1. `hide.bs.tab` (on the current active tab) 2. `show.bs.tab` (on the to-be-shown tab) 3. `hidden.bs.tab` (on the previous active tab, the same one as for the `hide.bs.tab` event) 4. `shown.bs.tab` (on the newly-active just-shown tab, the same one as for the `show.bs.tab` event) If no tab was already active, then the `hide.bs.tab` and `hidden.bs.tab` events will not be fired. | Event type | Description | | --- | --- | | `hide.bs.tab` | This event fires when a new tab is to be shown (and thus the previous active tab is to be hidden). Use `event.target` and `event.relatedTarget` to target the current active tab and the new soon-to-be-active tab, respectively. | | `hidden.bs.tab` | This event fires after a new tab is shown (and thus the previous active tab is hidden). Use `event.target` and `event.relatedTarget` to target the previous active tab and the new active tab, respectively. | | `show.bs.tab` | This event fires on tab show, but before the new tab has been shown. Use `event.target` and `event.relatedTarget` to target the active tab and the previous active tab (if available) respectively. | | `shown.bs.tab` | This event fires on tab show after a tab has been shown. Use `event.target` and `event.relatedTarget` to target the active tab and the previous active tab (if available) respectively. | ```js const tabEl = document.querySelector('button[data-bs-toggle="tab"]') tabEl.addEventListener('shown.bs.tab', event => { event.target // newly activated tab event.relatedTarget // previous active tab }) ```