Vertical Navigation Bar
With side navigation, you have several options:
- Always display the navigation pane to the left of the page content.
- Use a collapsible, "fully automatic" responsive side navigation.
- Open the navigation pane, hiding the left part of the page content.
- Open the navigation pane, hiding all of the page content.
- Shift the page content to the right, when opening the navigation pane.
Example: Always Display the Side Navigation
<nav class="w3-sidenav w3-white" style="width:25%">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a
href="#">Link 3</a>
<a href="#">Link 4</a>
</nav>
<div style="margin-left:25%">
... page content ...
</div>
Try It Yourself »
Collapsible Responsive Sidenav
<nav class="w3-sidenav w3-collapse w3-white" style="width:200px">
<a href="#" onclick="w3_close()" class="w3-closenav w3-hide-large">Close
×</a>
<a href="#">Link 1</a>
<a href="#">Link
2</a>
<a href="#">Link 3</a>
</nav>
<div class="w3-main" style="margin-left:200px">
<span class="w3-opennav w3-hide-large" onclick="w3_open()">☰</span>
... page content ...
</div>
<script>
function w3_open()
{
document.getElementsByClassName("w3-sidenav")[0].style.display
= "block";
}
function w3_close() {
document.getElementsByClassName("w3-sidenav")[0].style.display = "none";
}
</script>
Try It Yourself »
Open the Navigation Pane Hiding a Part of the Content
function w3_open() {
document.getElementsByClassName("w3-sidenav")[0].style.display = "block";
}
function w3_close() {
document.getElementsByClassName("w3-sidenav")[0].style.display = "none";
}
Try It Yourself »
Open the Navigation Pane Hiding All of the Content
function w3_open() {
document.getElementsByClassName("w3-sidenav")[0].style.width
= "100%";
document.getElementsByClassName("w3-sidenav")[0].style.display
= "block";
}
function w3_close() {
document.getElementsByClassName("w3-sidenav")[0].style.display = "none";
}
Try It Yourself »
Shift the Content to the Right
function w3_open() {
document.getElementById("main").style.marginLeft
= "25%";
document.getElementsByClassName("w3-sidenav")[0].style.width
= "25%";
document.getElementsByClassName("w3-sidenav")[0].style.display
= "block";
document.getElementsByClassName("w3-opennav")[0].style.display
= 'none';
}
function w3_close() {
document.getElementById("main").style.marginLeft
= "0%";
document.getElementsByClassName("w3-sidenav")[0].style.display
= "none";
document.getElementsByClassName("w3-opennav")[0].style.display
= "inline-block";
}
Try It Yourself »
Styling the Side Navigation
Add the w3-color class to the w3-sidenav to change the background color. If you want an active/current link, to let the user know which page he/she is on, add the w3-color class to one of the links as well:
Example
<nav class="w3-sidenav w3-light-grey">
<a class="w3-green" href="#">Link 1</a>
<a href="#">Link 2</a>
<a
href="#">Link 3</a>
</nav>
Try It Yourself »
Bordered Side Navigation
Use the w3-border class to add a border around the sidenav:
Example
<nav class="w3-sidenav w3-border">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a
href="#">Link 3</a>
</nav>
Try It Yourself »
Add the w3-border-bottom class to the links to create link dividers:
Example
<nav class="w3-sidenav w3-border">
<a class="w3-border-bottom" href="#">Link 1</a>
<a
class="w3-border-bottom" href="#">Link 2</a>
<a
href="#">Link 3</a>
</nav>
Try It Yourself »
Use the w3-card class to display the sidenav as a card:
Example
<nav class="w3-sidenav w3-card-8">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a
href="#">Link 3</a>
</nav>
Try It Yourself »
Hoverable Links
When you mouse over the links inside the sidenav, the background color will change to grey.
If you want a different background color on hover, use any of the w3-hover-color classes:
Example
<nav class="w3-sidenav">
<a class="w3-hover-black" href="#">Link 1</a>
<a
class="w3-hover-green" href="#">Link 2</a>
<a
class="w3-hover-blue" href="#">Link 3</a>
<a class="w3-hover-red" href="#">Link
4</a>
</nav>
Try It Yourself »
You can turn off the default hover effect with the w3-hover-none class. This is often used when you only want to highlight text color (and not background color) on hover:
Example
<nav class="w3-sidenav">
<a class="w3-hover-none w3-hover-text-grey" href="#">Link 1</a>
<a
class="w3-hover-none w3-hover-text-green" href="#">Link 2</a>
<a
class="w3-hover-none w3-hover-text-teal" href="#">Link 3</a>
<a class="w3-hover-none w3-hover-text-orange" href="#">Link
4</a>
</nav>
Try It Yourself »
Side Navigation Sizes
Increased font-size (w3-large etc):
Increased padding (w3-padding etc):
Example
<nav class="w3-sidenav w3-large">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</nav>
Try It Yourself »
Side Navigation with Icons
Example
<nav class="w3-sidenav w3-black" style="width:70px">
<a href="#"><i
class="fa fa-home w3-xxlarge"></i></a>
<a href="#"><i class="fa
fa-search w3-xxlarge"></i></a>
<a href="#"><i class="fa fa-envelope
w3-xxlarge"></i></a>
<a href="#"><i class="fa fa-globe
w3-xxlarge"></i></a>
</nav>
Try It Yourself »
Side Navigation with Dropdown
Example
<nav class="w3-sidenav w3-light-grey">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<div
class="w3-dropdown-hover">
<a href="#">Dropdown
<i class="fa fa-caret-down"></i></a>
<div
class="w3-dropdown-content w3-white w3-card-4">
<a href="#">Link 1</a>
<a href="#">Link
2</a>
<a href="#">Link 3</a>
</div>
</div>
<a href="#">Link
3</a>
</nav>
Try It Yourself »
Tip: When the dropdown menu is "open", the dropdown link gets a grey background color to indicate that it is active. To override this, add a w3-hover-color class to both the "dropdown" <li> and <a>.
Side Navigation with Accordion
Example
<nav class="w3-sidenav w3-light-grey w3-card-2" style="width:200px;">
<a href="#">Link</a>
<div class="w3-accordion">
<a onclick="myAccFunc()" href="#">Accordion</a>
<div
id="demoAcc" class="w3-accordion-content w3-white w3-card-4">
<a href="#">Link 1</a>
<a href="#">Link
2</a>
<a href="#">Link 3</a>
</div>
</div>
<div class="w3-dropdown-click">
<a onclick="myDropFunc()" href="#">Dropdown</a>
<div
id="demoDrop" class="w3-dropdown-content w3-white w3-card-4">
<a href="#">Link 1</a>
<a href="#">Link
2</a>
<a href="#">Link 3</a>
</div>
</div>
<a href="#">Link</a>
<a href="#">Link</a>
</nav>
Animated Sidenav
Use any of the w3-animate-classes to fade, zoom or slide in side navigation:
Sidenav Overlay
The w3-overlay class can be used to create an overlay effect when opening the sidenav. The w3-overlay class adds a black background with a 50% opacity to the "page content" - this effect will "highlight" the side navigation.
Example
<!-- Sidenav -->
<nav class="w3-sidenav w3-white w3-animate-left"
style="display:none;z-index:4">
<a href="javascript:void(0)"
onclick="w3_close()" class="w3-closenav">Close</a>
<a href="#">Link
1</a>
<a href="#">Link 2</a>
</nav>
<!-- Overlay -->
<div class="w3-overlay" onclick="w3_close()" style="cursor:pointer"></div>
<!-- Page content -->
<div class="w3-container">
<span
class="w3-opennav" onclick="w3_open()">☰</span>
</div>
<!-- JS to
open and close sidenav with overlay effect -->
<script>
function
w3_open() {
document.getElementsByClassName("w3-sidenav")[0].style.display
= "block";
document.getElementsByClassName("w3-overlay")[0].style.display
= "block";
}
function w3_close() {
document.getElementsByClassName("w3-sidenav")[0].style.display = "none";
document.getElementsByClassName("w3-overlay")[0].style.display = "none";
}
</script>
Try It Yourself »
Sidenav Content
Add whatever you like inside the side navigation:
Example
<nav class="w3-sidenav w3-light-grey" style="width:50%">
<div
class="w3-container w3-dark-grey">
<h4>Menu</h4>
</div>
<img src="img_fjords.jpg">
<a class="w3-red" href="#">Home</a>
<a href="#">Projects
<span
class="w3-tag w3-red w3-round w3-right">8</span>
</a>
<a href="#">About</a>
<a href="#">Contact</a>
<div class="w3-container">
<div class="w3-border w3-round w3-padding w3-blue-grey">
<span class="w3-closebtn">x</span>
<p>Lorem
ipsum box...</p>
</div>
</div>
</nav>
Try It Yourself »