Sexy CSS3 menu

One of the most common elements when talking about a website or an application design is definitely the menu navigation. No matter if vertical or horizontal, simple or complex, a menu is essential and it has to look that way.

In today’s article, you’ll learn how to create a good looking menu using some CSS3 magic.

View demo

The idea

If you are a web developer you may have heard of tools called CSS pre-processors. Less is probably the most well known CSS preprocessor, but that is another story.

While visiting LESS’s site, I noticed their download button, which is an image, and I thought to myself: I can do it using CSS only.


LESS download button – at this time

The HTML

<nav>
	<ul>
		<li><a href="#"><span>Home</span></a></li>
		<li><a href="#"><span>Categories</span></a></li>
		<li><a href="#"><span>About</span></a></li>
		<li><a href="#"><span>Portfolio</span></a></li>
		<li><a href="#"><span>Contact</span></a></li>
	</ul>
</nav>

Pretty clean, except for the span element. You’ll see further why we need that span.

The CSS

The demo example contains also a header and a logo (so, extra styles), but I’ll list here only the styles used for this menu.

Removing the default list styles

nav ul
{
	padding: 0;
	margin: 0;
	list-style: none;
}

nav li
{
	float: left;
}

Style the anchor

nav a
{
    float: left;
    color: #eee;
    margin: 0 5px;
    padding: 3px;
    text-decoration: none;
    border: 1px solid #831608;
    font: bold 14px Arial, Helvetica;
    background-color: #831608;
    background-image: -moz-linear-gradient(#bb413b, #831608);
    background-image: -webkit-gradient(linear, left top, left bottom, from(#bb413b), to(#831608));
    background-image: -webkit-linear-gradient(#bb413b, #831608);
    background-image: -o-linear-gradient(#bb413b, #831608);
    background-image: -ms-linear-gradient(#bb413b, #831608);
    background-image: linear-gradient(#bb413b, #831608);
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    border-radius: 5px;
    text-shadow: 0 -1px 0 rgba(0,0,0,.8);
    -moz-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.3), 0 3px 0 rgba(0, 0, 0, 0.7), 0 2px 2px rgba(0, 0, 0, 0.5), 0 1px 0 rgba(255, 255, 255, 0.5) inset;
    -webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.3), 0 3px 0 rgba(0, 0, 0, 0.7), 0 2px 2px rgba(0, 0, 0, 0.5), 0 1px 0 rgba(255, 255, 255, 0.5) inset;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.3), 0 3px 0 rgba(0, 0, 0, 0.7), 0 2px 2px rgba(0, 0, 0, 0.5), 0 1px 0 rgba(255, 255, 255, 0.5) inset;
}

nav a:hover
{
    background-color: #bb413b;
    background-image: -moz-linear-gradient(#831608, #bb413b);
    background-image: -webkit-gradient(linear, left top, left bottom, from(#831608), to(#bb413b));
    background-image: -webkit-linear-gradient(#831608, #bb413b);
    background-image: -o-linear-gradient(#831608, #bb413b);
    background-image: -ms-linear-gradient(#831608, #bb413b);
    background-image: linear-gradient(#831608, #bb413b);
}

nav a:active
{
    background: #bb413b;
    position: relative;
    top: 2px;
    -moz-box-shadow: 0 0 3px rgba(0, 0, 0, 0.7) inset;
    -webkit-box-shadow: 0 0 3px rgba(0, 0, 0, 0.7) inset;
    box-shadow: 0 0 3px rgba(0, 0, 0, 0.7) inset;
}


Multiple CSS3 properties were used to create the above.

Style the span element

nav span
{
    border: 1px dashed #eba1a3;
    display: inline-block;
    padding: 4px 15px;
    cursor: pointer;
    background-color: #bb413b;
    background-image: -moz-linear-gradient(#d4463c, #aa2618);
    background-image: -webkit-gradient(linear, left top, left bottom, from(#d4463c), to(#aa2618));
    background-image: -webkit-linear-gradient(#d4463c, #aa2618);
    background-image: -o-linear-gradient(#d4463c, #aa2618);
    background-image: -ms-linear-gradient(#d4463c, #aa2618);
    background-image: linear-gradient(#d4463c, #aa2618);
}

nav a:hover span
{
    background-color: #bb413b;
    background-image: -moz-linear-gradient(#aa2618, #d4463c);
    background-image: -webkit-gradient(linear, left top, left bottom, from(#aa2618), to(#d4463c));
    background-image: -webkit-linear-gradient(#aa2618, #d4463c);
    background-image: -o-linear-gradient(#aa2618, #d4463c);
    background-image: -ms-linear-gradient(#aa2618, #d4463c);
    background-image: linear-gradient(#aa2618, #d4463c);
}

View demo

Browser support

If above you have seen how the menu looks in modern browsers, here’s how the menu look in older browsers:


Fallback styles for older browsers

Advantages

  • Scalability
    You can simply adjust its size by updating the anchor‘s font-size:
    font: bold 14px Arial, Helvetica;
    
  • No images, so there are less HTTP image requests, also easy to maintain and update.
  • You could easily transform this menu into a nice dropdown menu.

Conclusion

The menu we created using this tutorial isn’t a Sci-Fi one or a super mega complex one. The main purpose is to see how CSS3 can help us achieve interesting effects without needing images anymore.

I hope you enjoyed this tutorial, thanks for reading it!

Related content

Written by Red

Catalin Rosu, a.k.a Red, is a professional web designer and developer who loves to be creative and enjoys CSS techniques. Stay tuned for latest updates, subscribe to RSS and follow him on Twitter.

41 Responses to “Sexy CSS3 menu”

  1. Paul Crowe says:

    Looks great and not too bad even in older browsers..

  2. Less is the second most well known CSS pre-processor, SASS being the first!

    But seriously, well done.

  3. Alex Le says:

    Nice explanations, demos, and code display. Dig the use of text shadows and gradients.

  4. Instead of float left, you can use display inline in the li. That aside, great job with the inset shadows and gradients

    • Red says:

      Henrique, indeed, that’s also an option.

      Thanks for your comment and I’m glad you found this article interesting!

  5. Joe Zhou says:

    First of all, great post!
    Just wondering if it does make a difference, I mean even if we use image, the load time should not be that slow to be noticable in this day and age? Not trying to take away the merit of the article, css3 kicks ass!

    • Red says:

      Joe, thanks for your comment.

      As you already know, absolutely every HTTP request matters when talking about speed as it ads milliseconds to a loading page.

      Skipping the HTTP requests part, to create this menu with images you’d probably need to use Sliding doors technique. Also, for that you’d need extra time to build clever CSS sprites.

      So, I think the CSS3 method is more suitable for this kind of menu.

  6. Prajakta says:

    Really sexy…too good….!!!

  7. Razvan says:

    Nice work… I like the buttons, but can you tell me the code of the background of the demo, please?

  8. Mario says:

    Very nice. To complete the look, just throw in a pure css arrow: http://lucianmarin.com/peculiar/

  9. Ashish says:

    Wow, it’s gr8 to make buttons like this using CSS only.
    Thanks!

  10. xigeek says:

    nice.. i use position absolute to make it fixed.. :) by the way. thanks bro

  11. rick says:

    So sexy!. thx U.. I´ve been learning a lot from you recently. You have great tuts. thx again

  12. Otomobil says:

    Great menu. Great tutorial. Thank you very much. I love this blog.

  13. Red says:

    @rick, @Otomobil: Nice to hear you like it and thank you for reading my articles!

  14. veteran says:

    hey red take a look to the bootstrap from twitter build with less

  15. Teejay says:

    Good ! you really make a difference … keep it up

  16. Teejay says:

    hi, i just try using this but is not working in IE 9, it works on firefox and chrome, pls way forward..

  17. Teejay says:

    Thanks for your quick responds i really appreciate i didnt get that as i follow the demo carefully but still not work

  18. Teejay says:

    sorry for that i got it after adding the Html 5 shim…. many Thanks

  19. codeheaven says:

    very nice article, i really like it the effort that you have put it in styling the css3 menus. Also check my blog
    http://codeheaven.org/simple-css3-checkbox-and-radio-button.html

  20. Odedra Nils says:

    it’s so good !!!!..

  21. Will says:

    Can I get the source code for the header as well please

  22. Deepak says:

    HI,

    I AM WEBDESIGNER FROM VCARE CORPORATION .THIS MENU IS SO NICE IN ATTRACTIVE. I LIKE IT . BUT HE IS NO BROWSER SUPPORT. WHEN ALL BROWSER CSS3 SUPPORTED HE WILL USE ALL WEB DESIGNER & DEVELOPER

  23. Prodyot says:

    Forever sexy nav buttons.
    Very cute.
    Hats off to you for creating it in pure css3.
    And, thanks for sharing.

Leave a Reply