Skip to content
  • Quizes
  • QStack
  • Blog
  • pinterest
  • instagram
  • twitter
  • linkedin
  • facebook
W3 Coding Schools
  • Home
  • HTML
    • HTML Introduction
    • HTML Editors
    • Fundamentals of HTML
    • Elements of HTML
    • HTML Attributes
    • HTML Headings
    • HTML Paragraphs
    • HTML Style Attribute
    • HTML Text Formatting
    • HTML Phrase Tags
    • HTML Comments
    • HTML with CSS
    • HTML Links
    • HTML Images
    • HTML Tables
    • HTML Lists
    • HTML Blocks
    • HTML Class Attribute
    • HTML Id Attribute
    • HTML Iframes
    • HTML JavaScript
    • HTML File Paths
    • HTML Head
    • Computer Code Elements
    • HTML Entities
    • HTML Charset
    • HTML URL Encode
    • HTML and XHTML
    • HTML Layouts
    • HTML Forms
    • HTML Form Elements
    • HTML Form Input Types
    • HTML Input Attributes
    • HTML5 Introduction
    • HTML5 New Elements
    • Semantic Elements
    • HTML5 Migration
    • Style Guide
    • HTML Canvas
  • CSS
    • CSS Introduction
    • CSS Syntax and CSS Comments
    • CSS Selectors
    • How to add CSS to a Webpage
    • CSS Color Basics
    • CSS Background Properties
    • CSS Border Properties
    • CSS Margin and Padding Properties
    • CSS Height and Width properties
    • CSS Box Model
    • CSS Outline Properties
    • CSS Fonts
    • CSS Text
    • How To Add Icons
    • CSS Links
    • CSS List-Style
    • CSS Tables
    • CSS Display Property
    • CSS Position Property
    • CSS Overflow Property
    • CSS max-width Property
    • CSS Float and Clear Properties
    • CSS Alignment
    • CSS inline-block
    • CSS Combinators
    • CSS Pseudo Classes
    • CSS Pseudo Elements
    • CSS Opacity
    • CSS Navigation Bar
    • CSS Dropdowns
    • CSS Image Gallery
    • CSS Image Sprites
    • CSS Attribute Selector
    • CSS Styling Forms
    • CSS Counters
    • CSS Units
    • CSS Specificity
    • CSS Website Layout
    • CSS Rounded Corners
    • CSS Border Image Property
    • CSS Multiple Backgrounds
    • CSS Gradient
    • CSS Shadow Effects
    • CSS Text Effects
    • CSS Web Fonts
    • CSS 2D Transforms
  • Bootstrap 4
    • Bootstrap 4 – Introduction
    • Bootstrap versions
    • Bootstrap 4 Layout
    • Bootstrap 3 Vs Bootstrap 4
    • Bootstrap 4 Grid System
    • Bootstrap 4 Typography
    • Bootstrap 4 Colors
    • Bootstrap 4 Images
    • Bootstrap 4 Tables
    • Bootstrap 4 Jumbotron
    • Bootstrap 4 Figures
    • Bootstrap 4 Alerts
    • Bootstrap 4 Buttons
    • Bootstrap 4 Button Group
    • Bootstrap 4 Badges
    • Bootstrap 4 Spinners
    • Bootstrap 4 Progress Bars
    • Bootstrap 4 Pagination
    • Bootstrap 4 Breadcrumbs
    • Bootstrap 4 List Groups
    • Bootstrap 4 Cards
  • jQuery
    • jQuery Introduction
    • jQuery Download
    • jQuery Selectors
    • jQuery Event Methods
    • jQuery Hide/Show Effects
    • jQuery Fading Effects
    • jQuery Sliding Effects
    • jQuery Animation
    • jQuery Stop and Callback
    • jQuery Get and Set Methods
    • jQuery Chaining
    • jQuery Add
    • jQuery Remove
    • jQuery CSS Classes
    • jQuery Style Properties
    • jQuery Dimensions
    • jQuery Traversing
    • jQuery Ancestors
    • jQuery Descendants
    • jQuery Siblings
  • Javascript
    • JS Introduction
    • JS Where to Put
    • JavaScript Syntax
    • JavaScript Comments
    • JavaScript Variables
    • JavaScript Data Types
    • JavaScript Operators
    • JavaScript Events
    • JavaScript Strings
    • JavaScript Numbers
  • php
    • PHP Introduction
    • Install PHP
    • PHP Syntax and Comments
    • PHP Variables
    • PHP Constants
    • PHP Echo and Print
    • PHP Data Types
    • PHP Strings
    • PHP Operators
    • PHP $ and $$ Variables
  • WordPress
    • WordPress Introduction
    • WordPress History
    • WordPress.com vs WordPress.org
    • How to Install WordPress
    • WordPress Dashboard
    • How to Create a WordPress Website
    • WordPress Posts
    • WordPress Pages
    • WordPress Posts vs Pages
    • WordPress Categories
  • SEO
    • SEO Introduction
    • SEO Tactics and Methods
    • SEO Relevant Filenames
    • SEO Domain Name
    • Website Design and SEO
    • SEO Keywords
    • Meta Tags Optimization
    • Title Tag Optimization
    • Anchor Text Optimization
    • Content Optimization
  • Android
    • Android Introduction
    • Android History and Versions
    • Android Architecture
    • Android Environment Setup
    • Android Application Components
    • Hello World Application
    • Android Activities
  • iOS
    • iOS Introduction
    • iOS Environment Setup
    • iOS Architecture

You Are Here

  • Home
  • Learn CSS
  • CSS Navigation Bar

Topics

  • CSS Introduction
  • CSS Syntax and CSS Comments
  • CSS Selectors
  • How to add CSS to a Webpage
  • CSS Color Basics
  • CSS Background Properties
  • CSS Border Properties
  • CSS Margin and Padding Properties
  • CSS Height and Width properties
  • CSS Box Model
  • CSS Outline Properties
  • CSS Fonts
  • CSS Text
  • How To Add Icons
  • CSS Links
  • CSS List-Style
  • CSS Tables
  • CSS Display Property
  • CSS Position Property
  • CSS Overflow Property
  • CSS max-width Property
  • CSS Float and Clear Properties
  • CSS Alignment
  • CSS inline-block
  • CSS Combinators
  • CSS Pseudo Classes
  • CSS Pseudo Elements
  • CSS Opacity
  • CSS Navigation Bar
  • CSS Dropdowns
  • CSS Image Gallery
  • CSS Image Sprites
  • CSS Attribute Selector
  • CSS Styling Forms
  • CSS Counters
  • CSS Units
  • CSS Specificity
  • CSS Website Layout
  • CSS Rounded Corners
  • CSS Border Image Property
  • CSS Multiple Backgrounds
  • CSS Gradient
  • CSS Shadow Effects
  • CSS Text Effects
  • CSS Web Fonts
  • CSS 2D Transforms

Oct Champs & Prizes

  • 1. Pooja Ladda
  • 2. Manjali Kuldharan
  • 3. Pranali Surawar
  • 4. Anjali Kulkarni
  • 5. Vishal Deshmukh

Recent Posts

  • HTML Media
  • jQuery Siblings
  • Bootstrap 4 Cards
  • jQuery Descendants
  • jQuery Ancestors

CSS Navigation Bar

A navigation bar is a link to appropriate sections or pages on a website that helps readers in traversing the online document. The navigation bar can be implemented in a number of ways, namely, horizontally or vertically, or fixed or dynamic.
Below we see how to convert boring HTML menus into attractive navigation bars.

Vertical Navigation Bar

Step1: Mostly, the navigation bar is created by using list of links. So using <ul> and <li> elements makes perfect sense.

Example:

<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Our Clients</a></li>
<li><a href="#">Our Services</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
Try it
Step2: Use the list-style-type: none; to remove the bullets of the list. And set the margin and padding is zero to remove the browser default settings.
After for vertical navigation set display: block property to <li>.

Example:

ul {

list-style-type: none;

margin: 0px;

padding: 0px;

}

li a {

display: block;

}
Try it
Step3: Now, set the width to <ul> items otherwise it takes full width and adds background-color. For removing the underline of list item set text-decoration: none; also set the color property to <li> item.

Example:

ul {

list-style-type: none;

margin: 0px;

padding: 0px;

width: 150px;

background-color: #ff5722;

}

li a {

display: block;

color: #ffffff;

text-decoration: none;

padding: 10px 20px;

}
Try it
Step4: By using :hover pseudo-class change the background color of the list item where user mouse over and also set the “active” class to current link to know the which page is on.

Example:

ul {

list-style-type: none;

margin: 0px;

padding: 0px;

width: 150px;

background-color: #ff5722;

}

li a {

display: block;

color: #ffffff;

text-decoration: none;

padding: 10px 20px;

}

li a:hover {

background-color:#f94455;

color: #ffffff;

}

li a.active {

background-color: #f90055;

color: #ffffff;

}
Try it

Horizontal Navigation Bar

Step1: Mostly, the navbar is created by using list of links. So using <ul> and <li> elements makes perfect sense.

Example:

<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Our Clients</a></li>
<li><a href="#">Our Services</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
Try it
Step2: Use the list-style-type: none; to remove the bullets of the list. And set the margin and padding is zero to remove the browser default settings.
For horizontal navbar use float: left property to <li> item. And set display: block property to a of <li> item.

Example:

ul {

list-style-type: none;

margin: 0px;

padding: 0px;

}

li {

float: left;

}

li a {

display: block;

padding: 10px;

}
Try it
Step3: Set the background-color to <ul> for full-width background-color. For hover effect set background-color on :hover pseudo-class. and also set the active class to know the active menu to the user.

Example:

ul {

list-style-type: none;

margin: 0px;

padding: 0px;

background-color: #ff5722;

overflow: hidden;

}

li {

float: left;

}

li a {

display: block;

padding: 15px 18px;

color: #ffffff;

text-decoration: none;

}

li a:hover {

background-color: #f94455;

}

li a.active {

background-color: #f90055;

}
Try it
Step4: To give the divider in between the links use the border-right property to <li> item.

Example:

ul {

list-style-type: none;

margin: 0px;

padding: 0px;

background-color: #ff5722;

overflow: hidden;

}

li {

float: left;

border-right:1px solid #fff;

}

li:last-child {

border-right: none;

}

li a {

display: block;

padding: 15px 18px;

color: #ffffff;

text-decoration: none;

}

li a:hover {

background-color: #f94455;

}

li a.active {

background-color: #f90055;

}
Try it

Fixed Navigation Bar

For a fixed navigation-bar, set the position is fixed. If you want to the fixed navbar at the top then set top: 0; and for bottom fixed then bottom:0.

Example:

Fixed navbar at top.
ul {

position: fixed;

top: 0;

}
Try it

Example:

Fixed navbar at bottom.
ul {

position: fixed;

bottom: 0;

}
Try it

Sticky Navigation Bar

For a sticky navbar, set the position is sticky.

Example:

ul {

position: sticky;

top: 0;

}
Try it

Responsive Top Navigation Bar

By using media-query, you can design a responsive navigation bar as well as a website also.
This example shows how to use media-query and makes responsive a top nav bar.

Example:

@media screen and (max-width: 768px) {

ul.topnav li {

float: none;

}

}
Try it

Responsive Side Navigation Bar

Example:

@media screen and (max-width: 992px) {

ul.navbar {

width: 100%;

height: auto;

position: relative;

}

ul.navbar li a {

padding: 20px;

float: left;

}

}

@media screen and (max-width: 576px) {

ul.navbar li a {

text-align: center;

float: none;

}

}

Try it

Post navigation

CSS Opacity
CSS Dropdowns

Ask a Question Cancel reply

Your email address will not be published. Required fields are marked *

W3 CODING SCHOOLS © Copyright 2019-20
Privacy policy   Terms of use

We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok