Demo: Navigation Bars
In this article, we will discuss how to create horizontal menu bar using HTML/CSS step by step and in the next article, how to create vertical menu bar using HTML/CSS. This is the simplest way to create css dropdown menu bar but best for new web developer. To get more interactive menu bar, you could use JQuery, HTML 5 and CSS3. To write the. Apr 18, 2019 Take a look at these free usable HTML CSS3 Dropdown menus with jquery code for modification of your old dropdown list with these unique set of dropdown menus. All country flag selector with flags and country code. Simple HTML CSS drop down Download. A responsive horizontal drop-down menu inspired by the Microsoft.com menu. PickArt – Modern DropDown Menu v1.1. PickArt Modern DropDown Menu flat UI menus navigation bar with different colors. In this project, you will get different colors menus, clean code, Full HTML & CSS3 and Fully Responsive. I have seen this project, it is professional and attractive menus and navigation bar.
Horizontal
Navigation Bars
Having easy-to-use navigation is important for any web site.
With CSS you can transform boring HTML menus into good-looking navigation bars.
Navigation Bar = List of Links
A navigation bar needs standard HTML as a base.
In our examples we will build the navigation bar from a standard HTML list.
A navigation bar is basically a list of links, so using the <ul> and <li> elements makes perfect sense:
Example
<ul>
<li><a href='default.asp'>Home</a></li>
<li><a href='news.asp'>News</a></li>
<li><a href='contact.asp'>Contact</a></li>
<li><a href='about.asp'>About</a></li>
</ul>
Try it Yourself »<li><a href='default.asp'>Home</a></li>
<li><a href='news.asp'>News</a></li>
<li><a href='contact.asp'>Contact</a></li>
<li><a href='about.asp'>About</a></li>
</ul>
Now let's remove the bullets and the margins and padding from the list:
Example
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
Try it Yourself »list-style-type: none;
margin: 0;
padding: 0;
}
Example explained:
list-style-type: none;
- Removes the bullets. A navigation bar does not need list markers- Set
margin: 0;
andpadding: 0;
to remove browser default settings
The code in the example above is the standard code used in both vertical, and horizontal navigation bars.
Html Code For Download
Vertical Navigation Bar
To build a vertical navigation bar, you can style the <a> elements inside the list, in addition to the code above:
Example
Try it Yourself »Example explained:
display: block;
- Displaying the links as block elements makes the whole link area clickable (not just the text), and it allows us to specify the width (and padding, margin, height, etc. if you want)width: 60px;
- Block elements take up the full width available by default. We want to specify a 60 pixels width
You can also set the width of <ul>, and remove the width of <a>, as they will take up the full width available when displayed as block elements. This will produce the same result as our previous example:
Example
ul {
list-style-type: none;
margin: 0;
padding: 0;
width: 60px;
}
li a {
display: block;
}
Try it Yourself »list-style-type: none;
margin: 0;
padding: 0;
width: 60px;
}
li a {
display: block;
}
Vertical Navigation Bar Examples
Create a basic vertical navigation bar with a gray background color and change the background color of the links when the user moves the mouse over them:
Example
ul {
list-style-type: none;
margin: 0;
padding: 0;
width: 200px;
background-color: #f1f1f1;
}
li a {
display: block;
color: #000;
padding: 8px 16px;
text-decoration: none;
}
/* Change the link color on hover */
li a:hover {
background-color: #555;
color: white;
}
Try it Yourself »list-style-type: none;
margin: 0;
padding: 0;
width: 200px;
background-color: #f1f1f1;
}
li a {
display: block;
color: #000;
padding: 8px 16px;
text-decoration: none;
}
/* Change the link color on hover */
li a:hover {
background-color: #555;
color: white;
}
Active/Current Navigation Link
Add an 'active' class to the current link to let the user know which page he/she is on:
Example
.active {
background-color: #4CAF50;
color: white;
}
background-color: #4CAF50;
color: white;
}
Horizontal Menu Bar Html Code
Try it Yourself »Center Links & Add Borders
Add
text-align:center
to <li> or <a> to center the links.Add the
border
property to <ul> add a border around the navbar. If you also want borders inside the navbar, add a border-bottom
to all <li> elements, except for the last one:Example
ul {
border: 1px solid #555;
}
li {
text-align: center;
border-bottom: 1px solid #555;
}
li:last-child {
border-bottom: none;
}
Try it Yourself »border: 1px solid #555;
}
li {
text-align: center;
border-bottom: 1px solid #555;
}
li:last-child {
border-bottom: none;
}
Full-height Fixed Vertical Navbar
Create a full-height, 'sticky' side navigation:
Example
ul {
list-style-type: none;
margin: 0;
padding: 0;
width: 25%;
background-color: #f1f1f1;
height: 100%; /* Full height */
position: fixed; /* Make it stick, even on scroll */
overflow: auto; /* Enable scrolling if the sidenav has too much content */
}
Try it Yourself »list-style-type: none;
margin: 0;
padding: 0;
width: 25%;
background-color: #f1f1f1;
height: 100%; /* Full height */
position: fixed; /* Make it stick, even on scroll */
overflow: auto; /* Enable scrolling if the sidenav has too much content */
}
Note: This example might not work properly on mobile devices.
Horizontal Navigation Bar
There are two ways to create a horizontal navigation bar. Using inline or floating list items.
Inline List Items
One way to build a horizontal navigation bar is to specify the <li> elements as inline, in addition to the 'standard' code above:
Example
Try it Yourself »Example explained:
display: inline;
- By default, <li> elements are block elements. Here, we remove the line breaks before and after each list item, to display them on one line
Floating List Items
Another way of creating a horizontal navigation bar is to float the <li> elements, and specify a layout for the navigation links:
Example
li {
float: left;
}
a {
display: block;
padding: 8px;
background-color: #dddddd;
}
Try it Yourself »float: left;
}
a {
display: block;
padding: 8px;
background-color: #dddddd;
}
Example explained:
float: left;
- use float to get block elements to slide next to each otherdisplay: block;
- Displaying the links as block elements makes the whole link area clickable (not just the text), and it allows us to specify padding (and height, width, margins, etc. if you want)padding: 8px;
- Since block elements take up the full width available, they cannot float next to each other. Therefore, specify some padding to make them look goodbackground-color: #dddddd;
- Add a gray background-color to each a element
Tip: Add the background-color to <ul> instead of each <a> element if you want a full-width background color:
Example
Try it Yourself »Horizontal Navigation Bar Examples
Create a basic horizontal navigation bar with a dark background color and change the background color of the links when the user moves the mouse over them:
Example
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
/* Change the link color to #111 (black) on hover */
li a:hover {
background-color: #111;
}
Try it Yourself »list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
/* Change the link color to #111 (black) on hover */
li a:hover {
background-color: #111;
}
Active/Current Navigation Link
Add an 'active' class to the current link to let the user know which page he/she is on:
Example
Try it Yourself »Right-Align Links
Right-align links by floating the list items to the right (
float:right;
):Example
<ul>
<li><a href='#home'>Home</a></li>
<li><a href='#news'>News</a></li>
<li><a href='#contact'>Contact</a></li>
<li><a href='#about'>About</a></li>
</ul>
Try it Yourself »<li><a href='#home'>Home</a></li>
<li><a href='#news'>News</a></li>
<li><a href='#contact'>Contact</a></li>
<li><a href='#about'>About</a></li>
</ul>
Border Dividers
Add the
border-right
property to <li> to create link dividers:Example
/* Add a gray right border to all list items, except the last item (last-child) */
li {
border-right: 1px solid #bbb;
}
li:last-child {
border-right: none;
}
Try it Yourself »li {
border-right: 1px solid #bbb;
}
li:last-child {
border-right: none;
}
Fixed Navigation Bar
Make the navigation bar stay at the top or the bottom of the page, even when the user scrolls the page:
Fixed Top
Try it Yourself »Fixed Bottom
Try it Yourself »Note: Fixed position might not work properly on mobile devices.
Gray Horizontal Navbar
An example of a gray horizontal navigation bar with a thin gray border:
Example
ul {
border: 1px solid #e7e7e7;
background-color: #f3f3f3;
}
li a {
color: #666;
}
Try it Yourself »border: 1px solid #e7e7e7;
background-color: #f3f3f3;
}
li a {
color: #666;
}
Sticky Navbar
Add
position: sticky;
to <ul> to create a sticky navbar.A sticky element toggles between relative and fixed, depending on the scroll position. It is positioned relative until a given offset position is met in the viewport - then it 'sticks' in place (like position:fixed).
Example
ul {
position: -webkit-sticky; /* Safari */
position: sticky;
top: 0;
}
Try it Yourself »position: -webkit-sticky; /* Safari */
position: sticky;
top: 0;
}
Note: Internet Explorer, Edge 15 and earlier versions do not support sticky positioning. Safari requires a -webkit- prefix (see example above). You must also specify at least one of
top
, right
, bottom
or left
for sticky positioning to work.More Examples
Responsive Topnav
How to use CSS media queries to create a responsive top navigation.
Try it Yourself »Responsive Sidenav
How to use CSS media queries to create a responsive side navigation.
Try it Yourself »Dropdown Navbar
How to add a dropdown menu inside a navigation bar.
Try it Yourself »Learn how to create a dropdown navigation bar.
Dropdown Menu in Navbar
Create A Dropdown Navbar
Create a dropdown menu that appears when the user moves the mouse over an element inside a navigation bar.
Step 1) Add HTML:
Example
<div>
<a href='#home'>Home</a>
<a href='#news'>News</a>
<div>
<button>Dropdown
<i></i>
</button>
<div>
<a href='#'>Link 1</a>
<a href='#'>Link 2</a>
<a href='#'>Link 3</a>
</div>
</div>
</div>
<a href='#home'>Home</a>
<a href='#news'>News</a>
<div>
<button>Dropdown
<i></i>
</button>
<div>
<a href='#'>Link 1</a>
<a href='#'>Link 2</a>
<a href='#'>Link 3</a>
</div>
</div>
</div>
Example Explained
Menu Bar In Html Code Free Download For Mac
Use any element to open the dropdown menu, e.g. a <button>, <a> or <p> element.
Use a container element (like <div>) to create the dropdown menu and add the dropdown links inside it.
Wrap a <div> element around the button and the <div> to position the dropdown menu correctly with CSS.
Step 2) Add CSS:
Example
/* Navbar container */
.navbar {
overflow: hidden;
background-color: #333;
font-family: Arial;
}
/* Links inside the navbar */
.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
/* The dropdown container */
.dropdown {
float: left;
overflow: hidden;
}
/* Dropdown button */
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit; /* Important for vertical align on mobile phones */
margin: 0; /* Important for vertical align on mobile phones */
}
/* Add a red background color to navbar links on hover */
.navbar a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
/* Dropdown content (hidden by default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
/* Links inside the dropdown */
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/* Add a grey background color to dropdown links on hover */
.dropdown-content a:hover {
background-color: #ddd;
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
Try it Yourself ».navbar {
overflow: hidden;
background-color: #333;
font-family: Arial;
}
/* Links inside the navbar */
.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
/* The dropdown container */
.dropdown {
float: left;
overflow: hidden;
}
/* Dropdown button */
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit; /* Important for vertical align on mobile phones */
margin: 0; /* Important for vertical align on mobile phones */
}
/* Add a red background color to navbar links on hover */
.navbar a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
/* Dropdown content (hidden by default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
/* Links inside the dropdown */
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/* Add a grey background color to dropdown links on hover */
.dropdown-content a:hover {
background-color: #ddd;
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
Example Explained
We have styled the navigation bar and the navbar links with a background-color, padding, etc.
We have styled the dropdown button with a background-color, padding, etc.
The
.dropdown
class is the container for .dropdown-content
. Since this is a <div> element, and not an <a> element, we have to float it to make sure that it stays next to the links.The
.dropdown-content
class holds the actual dropdown menu. It is hidden by default, and will be displayed on hover (see below). Note the min-width
is set to 160px. Feel free to change this.Instead of using a border, we have used the
box-shadow
property to make the dropdown menu look like a 'card'. We also use z-index to place the dropdown in front of other elements.The
:hover
selector is used to show the dropdown menu when the user moves the mouse over the dropdown button.Clickable Dropdown in Navbar
Example
Try it Yourself »Tip: Go to our CSS Dropdowns Tutorial to learn more about dropdowns.
Tip: Go to our Clickable Dropdowns to learn more about clickable dropdowns
Tip: Go to our CSS Navbar Tutorial to learn more about navbars.
Any pdf to dwg converter registration code free download. Tip: Go to our Responsive Top Navigation to learn about how to create a responsive navbar.