Horizontal CSS List Menu

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

June 9, 2008 at 8:02 am

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

Sam

July 24, 2008 at 11:15 am

good work i was looking for this thanks

Tom

October 25, 2008 at 12:30 pm

Great!

Works wonderfully!

:)

korpirkor

November 13, 2008 at 3:23 pm

Thank You, It’s nice and simple

pavel

December 8, 2008 at 5:30 am

simple as everybody wants!
thanks

Sasha

February 12, 2009 at 1:53 pm

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.

February 12, 2009 at 3:07 pm

Could you upload your site and post the link?

Jamess last blog post..Automatically published articles with WordPress

fazlionline

April 11, 2009 at 5:06 am

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

devianti

April 21, 2009 at 6:36 am

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!

April 29, 2009 at 12:12 am

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

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

Samia

June 23, 2009 at 3:48 pm

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.

June 25, 2009 at 5:23 pm

Awesome thank you!
Saved me mucking about!!

July 15, 2009 at 6:07 pm

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?

Ed

August 2, 2009 at 5:57 pm

How do you add submenus?

August 3, 2009 at 4:44 pm

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

February 2, 2010 at 7:21 pm

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

Jmz

February 3, 2010 at 12:27 pm

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.

Dave

February 16, 2010 at 3:07 am

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

February 16, 2010 at 2:15 pm

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

CITS F221 Graphics and Multimedia for the Web » Blog Archive » 07: Navigation, Image Maps, and CSS Sprites

October 27, 2009 at 12:33 pm

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

Leave a Reply

Your email is never published nor shared.

CommentLuv Enabled