Bootstrap Tabs and Pills
Menus
Most web pages have some kind of a menu.
In HTML, a menu is often defined in an unordered list <ul>
(and styled
afterwards), like this:
<ul>
<li><a href="#">Home</a></li>
<li><a
href="#">Menu 1</a></li>
<li><a href="#">Menu 2</a></li>
<li><a href="#">Menu 3</a></li>
</ul>
If you want to create a horizontal menu of the list above, add the
.list-inline
class to <ul>
:
<ul class="list-inline">
Try it Yourself »
Or you can display the menu above with Bootstraps' Tabs and Pills (see below).
Note: See the last example on this page to find out how to make tabs and pills toggleable/dynamic.
Tabs
Tabs are created with <ul class="nav nav-tabs">
:
Tip: Also mark the current page with <li class="active">
.
The following example creates navigation tabs:
Example
<ul class="nav nav-tabs">
<li
class="active"><a href="#">Home</a></li>
<li><a href="#">Menu 1</a></li>
<li><a href="#">Menu 2</a></li>
<li><a href="#">Menu 3</a></li>
</ul>
Try it Yourself »
Tabs With Dropdown Menu
Tabs can also hold dropdown menus.
The following example adds a dropdown menu to "Menu 1":
Example
<ul class="nav nav-tabs">
<li class="active"><a href="#">Home</a></li>
<li
class="dropdown">
<a
class="dropdown-toggle" data-toggle="dropdown" href="#">Menu 1
<span class="caret"></span></a>
<ul
class="dropdown-menu">
<li><a href="#">Submenu 1-1</a></li>
<li><a href="#">Submenu 1-2</a></li>
<li><a href="#">Submenu 1-3</a></li>
</ul>
</li>
<li><a href="#">Menu 2</a></li>
<li><a href="#">Menu 3</a></li>
</ul>
Try it Yourself »
Pills
Pills are created with <ul class="nav nav-pills">
. Also mark the current page with
<li class="active">
:
Example
<ul class="nav nav-pills">
<li
class="active"><a href="#">Home</a></li>
<li><a href="#">Menu 1</a></li>
<li><a href="#">Menu 2</a></li>
<li><a href="#">Menu 3</a></li>
</ul>
Try it Yourself »
Vertical Pills
Pills can also be displayed vertically. Just add the .nav-stacked
class:
Example
<ul class="nav nav-pills nav-stacked">
<li
class="active"><a href="#">Home</a></li>
<li><a href="#">Menu 1</a></li>
<li><a href="#">Menu 2</a></li>
<li><a href="#">Menu 3</a></li>
</ul>
Try it Yourself »
Vertical Pills in a Row
Text...
Text...
Text...
The following example places the vertical pill menu inside the last column. So, on a large screen the menu will be displayed to the right. But on a small screen, the content will automatically adjust itself into a single-column layout:
Example
<div class="col-md-3">
<ul class="nav nav-pills nav-stacked">
<li
class="active"><a href="#">Home</a></li>
<li><a href="#">Menu 1</a></li>
<li><a href="#">Menu 2</a></li>
<li><a href="#">Menu 3</a></li>
</ul>
</div>
Try it Yourself »
Pills With Dropdown Menu
Pills can also hold dropdown menus.
The following example adds a dropdown menu to "Menu 1":
Example
<ul class="nav nav-pills nav-stacked">
<li class="active"><a href="#">Home</a></li>
<li
class="dropdown">
<a
class="dropdown-toggle" data-toggle="dropdown" href="#">Menu 1
<span class="caret"></span></a>
<ul
class="dropdown-menu">
<li><a href="#">Submenu 1-1</a></li>
<li><a href="#">Submenu 1-2</a></li>
<li><a href="#">Submenu 1-3</a></li>
</ul>
</li>
<li><a href="#">Menu 2</a></li>
<li><a href="#">Menu 3</a></li>
</ul>
Try it Yourself »
Centered Tabs and Pills
To center/justify the tabs and pills, use the .nav-justified
class.
Note that on screens that are smaller than 768px, the list items are stacked (content will remain centered):
Example
<!-- Centered Tabs -->
<ul class="nav nav-tabs nav-justified">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Menu
1</a></li>
<li><a href="#">Menu 2</a></li>
<li><a href="#">Menu
3</a></li>
</ul>
<!-- Centered Pills -->
<ul class="nav nav-pills
nav-justified">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Menu 1</a></li>
<li><a href="#">Menu 2</a></li>
<li><a href="#">Menu 3</a></li>
</ul>
Try it Yourself »
Toggleable / Dynamic Tabs
HOME
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
To make the tabs toggleable, add the data-toggle="tab"
attribute to each link.
Then add a .tab-pane
class with a unique ID for every tab and wrap them inside a
<div>
element with class .tab-content
.
If you want the tabs to fade in and out when clicking on them, add the
.fade
class to .tab-pane
:
Example
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab"
href="#home">Home</a></li>
<li><a data-toggle="tab" href="#menu1">Menu
1</a></li>
<li><a data-toggle="tab" href="#menu2">Menu 2</a></li>
</ul>
<div class="tab-content">
<div id="home" class="tab-pane fade in active">
<h3>HOME</h3>
<p>Some content.</p>
</div>
<div id="menu1" class="tab-pane fade">
<h3>Menu 1</h3>
<p>Some content in menu 1.</p>
</div>
<div id="menu2"
class="tab-pane fade">
<h3>Menu 2</h3>
<p>Some content in menu 2.</p>
</div>
</div>
Try it Yourself »
Toggleable / Dynamic Pills
The same code applies to pills; only change the data-toggle
attribute to data-toggle="pill"
:
Example
<ul class="nav nav-pills">
<li class="active"><a data-toggle="pill" href="#home">Home</a></li>
<li><a data-toggle="pill" href="#menu1">Menu
1</a></li>
<li><a data-toggle="pill" href="#menu2">Menu 2</a></li>
</ul>
<div class="tab-content">
<div id="home" class="tab-pane fade in active">
<h3>HOME</h3>
<p>Some content.</p>
</div>
<div id="menu1" class="tab-pane fade">
<h3>Menu 1</h3>
<p>Some content in menu 1.</p>
</div>
<div id="menu2"
class="tab-pane fade">
<h3>Menu 2</h3>
<p>Some content in menu 2.</p>
</div>
</div>
Try it Yourself »
Test Yourself with Exercises!
Exercise 1 » Exercise 2 » Exercise 3 » Exercise 4 » Exercise 5 » Exercise 6 »
Complete Bootstrap Navigation Reference
For a complete reference of all navigation classes, go to our complete Bootstrap Navigation Reference.
For a complete reference of all tab options, methods and events, go to our Bootstrap JS Tab Reference.