Every website contains navigation bar. Navigation bar is an important part of website.
This post will show you about how to create navigation bar?, Types of navigation bar.
Before creating navigation bar understand about what is it and what is purpose of navigation bar?
What is navigation bar?
Navigation bar is collection of multiple links. Links in navigation bar helps user to jump from one page to another page.
navigation bar using HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 | <html> <head> <title>html navigation</title> </head> <body> <ul> <li><a href="navinhtml. html">Home</a></li> <li><a href="navinhtml.html">About</a></li> <li><a href="navinhtml.html">Services</a></li> </ul> </body> </html> |
This example describes that how to create navigation bar using only HTML. Output show how it looks.
Horizontal navigation bar
To create navigation menu, you have to remove bullets and underlines from the links.
To remove bullets set list-style-type property to none. list-style-type property display bullets in different shapes, like square, circle, disc, etc..) The default value is disc.
After removing the bullets, next step is to remove underline from link text. For that set text-decoration property to none. text-decoration property defined in anchor(<a>) selector.
How to make horizontal navigation bar?
To make horizontal navigation bar set display property to inline.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | <!Doctype html> <html> <head> <title>Horizontal Navigation</title> <style> .main{ position:relative; top:100px; left:100px; background-color:#c33; height:500px; width:700px; } ul{ background-color:#fc7; width:660px; top:90px; } li{ list-style-type:none; display:inline-block; padding:15px; } a{ text-decoration:none; font-size:16pt; } </style> </head> <body> <div class="main"> <ul> <li> <a href="horizontalnav.html">Home</a></li> <li> <a href="horizontalnav.html">About</a></li> <li> <a href="horizontalnav.html">Services</a> </li> <li> <a href="horizontalnav.html">Contact Us</a></li> </ul> </div> </body> </html> |
Output:-
![]() |
Horizontal navigation bar |
In example, <li> and <ul> elements are define under <div> element. Padding set to 15px to make area bigger. Set background color in <ul> element to get fully colored.
![]() |
Horizontal navigation bar (splitted) |
navigation bar - changing alignment of link
You can also change alignment of links. For example, if you want to change service link to right position. Then set float property to right to <li> element.
Adding borders to navigation links
Hovering on navigation links
![]() |
Hover effect on navigation links |
Fixed horizontal navigation bar
To fix navigation bar set position property to fixed in ul selector.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | <!Doctype html> <html> <head> <title>Horizontal Navigation</title> <style> .main{ position:relative; top:100px; left:100px; background-color:#c33; height:500px; width:700px; } ul{ background-color:#fc7; position:fixed; width:660px; top:90px; z-index:1; } li{ list-style-type:none; display:inline-block; padding:15px; border-right:2px solid grey;} a{ text-decoration:none; font-size:16pt; } .contnt{ position:absolute; top:60px; height:400px; overflow:auto; } </style> </head> <body> <div class="main"> <ul> <li> <a href="horizontalnav.html">Home</a></li> <li> <a href="horizontalnav.html">About</a></li> <li> <a href="horizontalnav.html">Services</a></li> <li> <a href="horizontalnav.html">Contact Us</a></li> <div class="contnt"> <h1>Horizontal navigation bar</h1> <p> some text</p><p> some text</p><p> some text</p><p> some text</p><p> some text</p><p> some text</p><p> some text</p><p> some text</p><p> some text</p><p> some text</p>some text</p><p>some text</p><p> some text</p><p> some text</p><p> some text</p><p> some text</p><p> some text</p><p> some text</p><p> some text</p><p> some text</p><p>end text</p><p>end text</p> </div> </div> </body> </html> |
Output:-
![]() |
Fixed horizontal navigation bar |
Active/current link in navigation bar
![]() |
Active link in navigation bar |
Navigation bar with Drop down menu
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | <html> <head> <title>Dropdoown Navigation</title> <style> ul{ position:relative; background-color:#fcc;} li{ display:inline-block; list-style-type:none; padding:15px;} li:hover{ background-color:#fac;} a{ text-decoration:none; font-size:20pt; text-align:center;} .submenu{ position:absolute; top;50px; display:block; height:auto; width:auto; background-color:#9cc; } .submenu li{ display:none;} li:hover .submenu li{ display: inline-block;} </style> </head> <body> <ul> <li><a href="#">Home</a> </li> <li><a href="#">About</a> </li> <li><a href="#">Menu</a> <ul class="submenu"> <li><a href="#">link1</a></li> <li><a href="#">link2</a></li> <li><a href="#">link3</a></li> </ul> </li> </ul> </body> </html> |
Output:-
![]() |
Drop-down menu in horizontal navigation bar |
Drop-down menu with transition and transform effect
.submenu li{ transition:transform 2s linear; border-radius:50%; } .submenu li:hover{ transform:translate(15px); }
Output:-
Vertical navigation bar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | <!Doctype html> <html> <head> <title>vertical navigation bar</title> <style> .vertical{ position:fixed; background-color:#fca; height:500px; width:200px; } ul{ position:absolute; list-style-type:none; } li a{ display:block; text-decoration:none; padding:15px; display:block; width:100px; } </style> </head> <body> <div class="main"> <div class="vertical"> <ul> <li class="active"><a href="verticalnavi.html">Home</a></li> <li><a href="verticalnavi.html">About</a></li> <li class="menu"><a href="#">Services</a> </li> <li><a href="verticalnavi.html">Contact us</a></li> </ul> </div> </div> </body> </html> |
Output:-
![]() |
Vertical navigation bar |
Alignment of links in vertical navigation bar.
vertical navigation bar with borders
Fixed Vertical navigation bar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | <!Doctype html> <html> <head> <title>vertical navigation bar</title> <style> ..... ..... .main{ position:relative; height:500px; width:699px; background-color:#c33; overflow:auto;} .contnt{ position:absolute; left:200px; top:50px; padding:5px; overflow:auto; } </style> </head> <body> <div class="main"> <div class="vertical"> <ul> <li class="active"><a href="verticalnavi.html">Home</a></li> <li><a href="verticalnavi.html">About</a></li> <li class="menu"><a href="#">Services</a> </li> <li><a href="verticalnavi.html">Contact us</a></li> </ul> </div> <div class="contnt"> <h1>Fixed Vertical Navigation bar</h1> <p>This is example of fixed vertical navigation bar. This paragraph is scrollable.</p> <p>This is example of fixed vertical navigation bar. This paragraph is scrollable.</p> <p>This is example of fixed vertical navigation bar. This paragraph is scrollable.</p> <p>This is example of fixed vertical navigation bar. This paragraph is scrollable.</p> <p>This is example of fixed vertical navigation bar. This paragraph is scrollable.</p> <p>This is example of fixed vertical navigation bar. This paragraph is scrollable.</p> <p>This is example of fixed vertical navigation bar. This paragraph is scrollable.</p> <p>This is example of fixed vertical navigation bar. This paragraph is scrollable.</p> </div> </div> </body> </html> |
Output:-
![]() |
Fixed vertical navigation bar |
Vertical navigation bar with Drop down menu
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | <!Doctype html> <html> <head> <title>vertical navigation bar</title> <style> ..... ..... .submenu li{ display:none; position:relative; width:auto; text-align:left; } li:hover .submenu li{ display:block; background-color:#fea; } .menu:hover{ display:block; height:170px;} </style> </head> <body> <div class="main"> <div class="vertical"> <ul> <li class="active"><a href="verticalnavi.html">Home</a></li> <li><a href="verticalnavi.html">About</a></li> <li class="menu"><a href="#">Services</a> <ul class="submenu"> <li><a href="#">home delievery</a></li> <li><a href="#">Repair</a></li> </ul> </li> <li><a href="verticalnavi.html">Contact us</a></li> </ul> </div> </div> </body> </html> |
Output:-
![]() |
Vertical navigation bar with Drop down menu |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | <!Doctype html> <html> <head> <title>vertical navigation bar</title> <style> .vertical{ position:fixed; background-color:#fca; height:500px; width:200px; } ul{ position:absolute; list-style-type:none; } li a{ display:block; text-decoration:none; padding:15px; display:block; width:100px; border:1px solid grey; } li{ text-align:center; } li:hover{ background-color:#ccc;} .active{background-color:#0c0;} .main{ position:relative; height:500px; width:699px; background-color:#c33; overflow:auto;} .contnt{ position:absolute; left:200px; top:50px; padding:5px; overflow:auto; } .submenu li{ display:none; position:relative; width:auto; text-align:left; } li:hover .submenu li{ display:block; background-color:#fea; } .menu:hover{ display:block; height:170px;} </style> </head> <body> <div class="main"> <div class="vertical"> <ul> <li class="active"><a href="verticalnavi.html">Home</a></li> <li><a href="verticalnavi.html">About</a></li> <li class="menu"><a href="#">Services</a> <ul class="submenu"> <li><a href="#">home delievery</a></li> <li><a href="#">Repair</a></li> </ul> </li> <li><a href="verticalnavi.html">Contact us</a></li> </ul> </div> <div class="contnt"> <h1>Fixed Vertical Navigation bar</h1> <p>This is example of fixed vertical navigation bar. This paragraph is scrollable.</p> <p>This is example of fixed vertical navigation bar. This paragraph is scrollable.</p> <p>This is example of fixed vertical navigation bar. This paragraph is scrollable.</p> <p>This is example of fixed vertical navigation bar. This paragraph is scrollable.</p> <p>This is example of fixed vertical navigation bar. This paragraph is scrollable.</p> <p>This is example of fixed vertical navigation bar. This paragraph is scrollable.</p> <p>This is example of fixed vertical navigation bar. This paragraph is scrollable.</p> <p>This is example of fixed vertical navigation bar. This paragraph is scrollable.</p></div> </div> </body> </html> |
0 Comments