w3schools.com
THE WORLD'S LARGEST WEB DEVELOPER SITE
HTML
CSS
JAVASCRIPT
SQL
PHP
BOOTSTRAP
HOW TO
JQUERY
W3.CSS
ANGULARJS
XML
MORE
FORUM
EXAMPLES
REFERENCES
×
HTML and CSS
Learn HTML Learn CSS Learn W3.CSS Learn Colors Learn Bootstrap 3 Learn Bootstrap 4 Learn Graphics Learn Icons Learn How ToServer Side
Learn SQL Learn PHP Learn Python Learn ASP Learn Node.js Learn Raspberry PiWeb Building
Web Templates Web Statistics Web Certificates Web Editor
×
HTML
HTML Tag Reference HTML Event Reference HTML Color Reference HTML Attribute Reference HTML Canvas Reference HTML SVG Reference Google Maps ReferenceCharsets
HTML Character Sets HTML ASCII HTML ANSI HTML Windows-1252 HTML ISO-8859-1 HTML Symbols HTML UTF-8
×
HTML/CSS
HTML Examples CSS Examples W3.CSS Examples W3.CSS Templates Bootstrap Examples How To Examples SVG ExamplesJavaScript
JavaScript Examples HTML DOM Examples jQuery Examples AngularJS Examples AJAX Examples W3.JS Examples
×
Google
Google Maps Google Maps BW Google Translate Google Charts Google Fonts
HOW TO
HowTo HomeMenus
Icon Bar Menu Icon Accordion Tabs Vertical Tabs Tab Headers Full Page Tabs Top Navigation Responsive Topnav Search Menu Search Bar Fixed Sidebar Side Navigation Fullscreen Navigation Off-Canvas Menu Hover Sidenav Buttons Horizontal Scroll Menu Vertical Menu Bottom Navigation Responsive Bottom Nav Bottom Border Nav Links Right Aligned Menu Links Centered Menu Links Fixed Menu Slide Down Bar on Scroll Hide Navbar on Scroll Sticky Navbar Hover Dropdowns Click Dropdowns Dropdown in Topnav Dropdown in Sidenav Resp Navbar Dropdown Dropup Mega Menu Mobile Menu Pagination Breadcrumbs Button Group Vertical Button Group Sticky Social Bar Responsive HeaderImages
Slideshow Slideshow Gallery Modal Images Lightbox Responsive Image Grid Image Grid Tab Gallery Image Overlay Fade Image Overlay Slide Image Overlay Zoom Image Overlay Title Image Overlay Icon Image Effects Black and White Image Image Text Image Text Blocks Transparent Image Text Full Page Image Form on Image Hero Image Side-by-Side Images Rounded Images Avatar Images Responsive Images Center Images Thumbnails Meet the Team Sticky Image Flip an Image Shake an Image Portfolio Gallery Portfolio with Filtering Image Zoom Image Magnifier Glass Image Comparison SliderButtons
Alert Buttons Outline Buttons Split Buttons Animated Buttons Fading Buttons Button on Image Social Media Buttons Read More Read Less Loading Buttons Download Buttons Icon Buttons Next/prev Buttons More Button in Nav Block Buttons Text Buttons Round Buttons Scroll To Top ButtonForms
Login Form Signup Form Checkout Form Contact Form Social Login Form Register Form Form with Icons Newsletter Responsive Form Clear Input Field Copy Text to Clipboard Animated Search Search Button Fullscreen Search Custom Checkbox/Radio Custom Select Toggle Switch Check Checkbox Password Validation Toggle Password Visibility Multiple Step Form AutocompleteFilters
Filter List Filter Table Filter Elements Filter Dropdown Sort List Sort TableTables
Zebra Striped Table Responsive Tables Comparison TableMore
Fullscreen Video Modal Boxes Timeline Scroll Indicator Progress Bars Skill Bar Range Sliders Tooltips Popups Collapsible Calendar HTML Includes To Do List Loaders Star Rating User Rating Overlay Effect Contact Chips Cards Profile Card Alerts Notes Labels Circles Coupon Responsive Text Fixed Footer Sticky Element Equal Height Clearfix Snackbar Fullscreen Window Scroll Drawing Sticky Header Pricing Table Parallax Aspect Ratio Toggle Like/Dislike Toggle Hide/Show Toggle Text Toggle Class Add Class Remove Class Active Class Remove Property Find Hidden Element Redirect Webpage Zoom Hover Center Vertically Transition on Hover Arrows Shapes Download Link Full Height Element Browser Window Custom Scrollbar Device Look Placeholder Color Vertical Line Animate Icons Countdown Timer Typewriter Coming Soon Page Chat Messages Split Screen Testimonials Section Counter Quotes Slideshow Closable List Items Typical Device Breakpoints Draggable HTML Element Trigger Button on Enter JS Media Queries Syntax Highlighter JS Animations Get Iframe ElementsWebsite
Make a Website Make a Website (W3.CSS) Make a Website (BS3) Make a Website (BS4) Center Website Contact SectionGrid
2 Column Layout 3 Column Layout 4 Column Layout Expanding Grid List Grid View Mixed Column Layout Blog LayoutConverters
Convert Weight Convert Temperature Convert Length Convert SpeedHow TO - Fixed Sidebar
Learn how to create a fixed side navigation menu with CSS.
Full height:
Try it Yourself »Auto height:
Try it Yourself »Create a Fixed Sidebar
Step 1) Add HTML:
Example
<!-- Side navigation -->
<div class="sidenav">
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Clients</a>
<a href="#">Contact</a>
</div>
<!-- Page content -->
<div class="main">
...
</div>
Step 2) Add CSS:
Example
/* The sidebar menu */
.sidenav {
height: 100%; /*
Full-height: remove this if you want "auto" height */
width: 160px;
/* Set the width of the sidebar */
position: fixed; /*
Fixed Sidebar (stay in place on scroll)
*/
z-index: 1; /* Stay on top */
top: 0; /* Stay at the top */
left: 0;
background-color: #111; /* Black */
overflow-x: hidden; /* Disable horizontal scroll */
padding-top: 20px;
}
/* The navigation menu links */
.sidenav a {
padding:
6px 8px 6px 16px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
}
/* When you mouse over the navigation links,
change their color */
.sidenav a:hover {
color: #f1f1f1;
}
/* Style page content */
.main {
margin-left:
160px; /* Same as the width of the sidebar */
padding:
0px 10px;
}
/* On smaller screens, where height is less than
450px, change the style of the sidebar (less padding and a smaller font
size) */
@media screen and (max-height: 450px) {
.sidenav
{padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
Try it Yourself (Full Height) »
Try it Yourself (Auto Height) »
Tip: Go to our CSS Navbar tutorial to learn more about navigation bars.
Tip: Go to our How To - Side Navigation tutorial to learn how to create an animated, closable side navigation.
×
Your Suggestion:
×
Thank You For Helping Us!
Your message has been sent to W3Schools.
W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve reading and basic understanding.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content.
While using this site, you agree to have read and accepted our terms of use,
cookie and privacy policy.
Copyright 1999-2018 by Refsnes Data. All Rights Reserved.
Clone by Md Maruf Adnan Sami.
Clone by Md Maruf Adnan Sami.