Horizontal CSS List Menu

This tutorial will show you how to make a horizontal CSS list menu. No images, no javascript. Just a simple, cross browser compatible CSS list menu! If you want to see the finished product or you just want the code, look here.

First of all we’ll need the HTML for our list menu, this is just a normal unordered list.

<div class="menu">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
</ul>
<br style="clear:left"/>
</div>

It’s just a simple html page with an unordered list menu on. You might notice I’ve added a div called menu around the list, I like to do this as it helps me remember what part of the code does what if I ever have to go back to it.

Next we’re going to add the CSS code for the div called menu that surrounds the list.

.menu{
	width: 100%;
	background-color: #333; }

Again this is nice and simple. The menu div will be the full width of the div it’s inside and will have a dark grey background.

Next we add the syling for the list and the list items.

.menu ul{
	margin: 0; padding: 0;
	float: left;}

.menu ul li{
	display: inline;}

.menu ul li a{
	float: left; text-decoration: none;
	color: white;
	padding: 10.5px 11px;
	background-color: #333; }

.menu ul li a:visited{
	color: white;}

.menu ul li a:hover, .menu ul li .current{
	color: #fff;
	background-color:#0b75b2;}

Again it’s all pretty simple, you should be able to understand the code with a little bit of CSS knowledge. Have a tinker with the code if you’re unsure about something.

You might also want to sign up for the RSS Feed or view some of my other CSS Tutorials

This entry was posted in CSS Tutorials and tagged , , , , . Bookmark the permalink. Both comments and trackbacks are currently closed.

34 Comments

  1. Posted June 9, 2008 at 8:02 am | Permalink

    Yet again, this works like a charm. Good job.

  2. Sam
    Posted July 24, 2008 at 11:15 am | Permalink

    good work i was looking for this thanks

  3. Posted October 25, 2008 at 12:30 pm | Permalink

    Great!

    Works wonderfully!

    :)

  4. korpirkor
    Posted November 13, 2008 at 3:23 pm | Permalink

    Thank You, It’s nice and simple

  5. pavel
    Posted December 8, 2008 at 5:30 am | Permalink

    simple as everybody wants!
    thanks

  6. Sasha
    Posted February 12, 2009 at 1:53 pm | Permalink

    I can’t get it to work! I copy and paste exactly the way it is. The html code makes a list but when i enter the css code it does nothing.

  7. Posted February 12, 2009 at 3:07 pm | Permalink

    Could you upload your site and post the link?

    Jamess last blog post..Automatically published articles with WordPress

  8. fazlionline
    Posted April 11, 2009 at 5:06 am | Permalink

    this is the best
    but how can i add a submenu to it?

  9. devianti
    Posted April 21, 2009 at 6:36 am | Permalink

    It works! It didn’t work at first but I figured it out by replacing the class function to div in css…!

    Thanks a lot for the simplicity!

  10. Posted April 29, 2009 at 12:12 am | Permalink

    Do you have anything on 2 level, horizontal CSS nav bars?

    SaminOzs last blog post..Element (Tag) attributes in XHTML

  11. Samia
    Posted June 23, 2009 at 3:48 pm | Permalink

    Hey,it’s quite simple and easy,but i can’t center it. Can you tell me how i can do it? it’s a bit urgent.

  12. Posted June 25, 2009 at 5:23 pm | Permalink

    Awesome thank you!
    Saved me mucking about!!

  13. Posted July 15, 2009 at 6:07 pm | Permalink

    This CSS tutorial has solved my problem. Thank you!

    By the way, would you happen to have one with a 2nd-level hierarchy for each menu link?

  14. Ed
    Posted August 2, 2009 at 5:57 pm | Permalink

    How do you add submenus?

  15. Posted August 3, 2009 at 4:44 pm | Permalink

    Thank you! This is probably the most intuitive, easy to follow tut for horizontal list menus. Much appreciated, and thanks for sharing.

  16. Posted February 2, 2010 at 7:21 pm | Permalink

    Is it possible to create the menu then place it all into a single ccs sheet so that it works on every page autimatically.

  17. Posted February 3, 2010 at 12:27 pm | Permalink

    Yes you would just put your code in a separate CSS file and then include the CSS file between the head tags of each html document you want it in.

    To include the CSS file, use the code (code moved to pastebin: http://pastebin.com/mf1ccb51 ) when the name of your CSS file is style.css.

  18. Dave
    Posted February 16, 2010 at 3:07 am | Permalink

    Thanks, works great. However, how do you center it?

  19. Posted February 16, 2010 at 2:15 pm | Permalink

    Good One
    but how can i add a sub menu to it ?

  20. stimpson
    Posted April 7, 2010 at 11:52 am | Permalink

    ow man this is exactly what i like about these tuts, simpl & basic! With this you can experiment to get your own result fast, which is way more easy then recoding too-complicated examples with the basics somewhere in it. Thanks again!

  21. Posted April 7, 2010 at 2:34 pm | Permalink

    These really helped me to build my homepage, I can really appreciated if people take some time and write a usefull tutorial.

  22. Trinda
    Posted April 19, 2010 at 6:30 pm | Permalink

    thank you thank you.

    I am just learning to find my way through css and this is exactly what I needed!!!!

  23. Posted April 30, 2010 at 1:19 pm | Permalink

    This is a neat clean horizontal menu. I will be implementing it in the church website today.

  24. Posted May 29, 2010 at 3:28 am | Permalink

    Hey thanks bro! worked great! and simple to follow

  25. thed
    Posted July 23, 2010 at 7:06 am | Permalink

    works just perfectly.. thanks a lot for the tip..

  26. Posted September 29, 2010 at 11:41 am | Permalink

    Brilliant – cleared some things up for me. Very straightforward and well layed out. Thanks very much…

  27. Johan
    Posted October 5, 2010 at 7:35 pm | Permalink

    VERY NICE! THANKS!

  28. Posted December 5, 2010 at 4:38 pm | Permalink

    Simple, clean code – good job

  29. naseema
    Posted December 7, 2010 at 8:51 am | Permalink

    hai.. i have one doubt. css list-menu differ in different browser like firefox and ie. pls solve my problem……

  30. Posted February 18, 2011 at 6:51 pm | Permalink

    How to make horizontal list catogery likes MP3 category A – Z?
    Wirobrojo´s last [type] ..Memperkuat Keyword Dengan Tag Alt

  31. Chris
    Posted March 11, 2011 at 10:55 am | Permalink

    Nice one for a simple straight forward tutorial.

  32. Nidhi
    Posted April 2, 2011 at 11:12 am | Permalink

    Hey its really owesome…..thanx

  33. Posted April 7, 2011 at 10:53 am | Permalink

    simple and straight forward menu.

  34. Binu V Pillai
    Posted April 11, 2011 at 1:46 pm | Permalink

    Sorry mate.

    It wont work properly in firefox. it will alway position on the top of div. We can’t move the list content on the center of “menu” div. margin or padding will not help in this case. we need to do some other css hack.

    my testing environment are:
    Firefox 3.6.16
    Ubuntu 10.04

One Trackback

  1. [...] For those of you that want to try something more advanced, check out the code for this horizontal list menu. [...]