Icon Supported Navigation

Tutorial CSS Icon Navigation Menu

Looking to give your navigation menu a little more impact with some icons/graphics while still retaining accessibility to your users? Then this tutorial is for you!

In every internet application I build – within and out with Zen Elements – I attempt to stay away from creating menus made entirely from images. In my oppinion, text within a menu system should be just that; text. This will result in a more crisp, sharp and legible menu, regardless of the application reading it, the magnification of the page, etc. Maybe it is just me but should we not be able to create good looking AND accessible menus?

Below is the Markup and CSS used to create the following Icon Supported Menu.

CSS Icon Navigation

Click here for a live example (opens in a new window).

The Basic Markup

  1. navigation.html
  2. <ul class="nav">
  3.   <li class="home"><a href="#link">home</a></li>
  4.   <li class="about"><a href="#link">about</a></li>
  5.   <li class="work"><a href="#link">work</a></li>
  6. </ul>

The CSS

  1. style.css
  2. .nav {width:550px; height:50px; padding:0px 25px; margin:0px; background:url(img/bg.gif) repeat-x; border:1px solid #efefef;}
  3. .nav li {float:left; width:125px; height:50px; display:inline; padding:0px; margin:0px 25px 0px 0px;}
  4.   li.home {background:url(img/nav-home.gif) top left no-repeat;}
  5.   li.home:hover {background:url(img/nav-homeHover.gif) top left no-repeat;}
  6.   li.about {background:url(img/nav-about.gif) top left no-repeat;}
  7.   li.about:hover {background:url(img/nav-aboutHover.gif) top left no-repeat;}
  8.   li.work {background:url(img/nav-work.gif) top left no-repeat;}
  9.   li.work:hover {background:url(img/nav-workHover.gif) top left no-repeat;}
  10. .nav li a {display:block; padding:15px 0px 0px 50px; color:#000; font-size:18px; font-family:arial; height:35px; text-decoration:none;}
  11. .nav li a:hover {color:#C00;}

With menus becoming more heavily styled in keeping with more sophisticated website designs, it is fair to say that if you are wanting to use a particular font – and there is NO way a web compliant one will do – then you are going to have to use images, flash or magic of some sort. It is important to at least try to retain some level accessibility though, as much as possible. Pretty will only get you so far ;)

The best way to learn from this tutorial, is to play! Try moving the icons over to the right or creating a vertical icon supported menu system. If you have an example of a particularly pretty icon supported menu on your site, please share a link alongside a comment!

Thank you for reading.
Alex | Zen Elements

Like this article?

Subscribe to our rss, follow our tweets or please help us spread the work & share this with your friends!

Thank you for all your support; have a cookie!

16 Comments on “Icon Supported Navigation”

  1. Crd 25.02.2009 at 10:23 am

    why not using id instead of class? it’s not like you’re gonna be using those elements somewhere else on the page….

  2. Zen Elements 25.02.2009 at 10:34 am

    @Crd | You can – and are as well to – use the ‘id’ attribute in place of ‘class’ for the navigation, as you say, it is unlikely you’ll use the exact same set again.
    I have seen a few sites that have done this, mimicing the main navigation down in the footer but it is few.

  3. Avangelist 25.02.2009 at 2:42 pm

    Quite, as stated
    Class = more than one instance
    ID = unique

    .nav is repeated.

    I always find these things of styling individual links to use images quite cumbersome to manage and is often best left in the structural layer rather than presentation layer of the page.

  4. Crd 26.02.2009 at 12:21 am

    alternatively, class could be used for semantic description, but i’m not fond of it as it comes down to overloading the attribute :-/ other than that, nice tutorial :)

  5. Justin 26.02.2009 at 9:08 pm

    I feel that using the class attribute is much more effective (for the reason that Zen listed). Even if you weren’t planning on using it in multiple instances to start, you might want to add that without having change a bunch of code.

    As well, what if you wanted to name the body with an ID of ‘about’?

    Regardless, I don’t think this tut was meant to show the specifics of naming methods, but the CSS attached.. Great work!

  6. Crd 01.03.2009 at 1:45 pm

    why naming the body tag? there’s always one on every document.
    and as for id and not class, if you’re using javascript and getElementById it’s easier to manipulate the element… with class, not impossible, but requires more work…
    still agree that the number of instances is the prime factor for choosing the attribute :)

  7. caruso_g 13.03.2009 at 10:03 pm

    Please, use a sprite for images, it is not justified to continue using two different images for two different states.

  8. vocal 14.03.2009 at 3:33 am

    so this is very cool, but, I think it will be more lightweight if it use the Sprite technology …

  9. Tommie Hansen 14.03.2009 at 8:47 am

    Yeah, one should definitely use css-sprites in this example, everything else just cause a visible lag which doesn’t at all feel professional. A better way as well would be to assign the CSS-class via javascript + a document ready function (depending on the TEXT inside the A-tag). That way one wouldn’t have to litter down the markup with presentational fluff. A tad more advanced though… ;)

  10. Zen Elements 14.03.2009 at 9:39 am

    Thank you everyone for your comments, feedback and criticism on this post! It has been interesting hearing the debate going on regarding CLASS vs ID as well as the requesting of the CSS Sprites to be used.

    To @caruso_g, @vocal, @Tommie Hansen :-
    This tutorial was meant as a first steps guide to aligning icons/graphics in a listed navigation menu but I agree with you wholeheartedly regarding the use of the CSS sprite. It is more efficient in using a Sprite panel (if a controlled one) and the background-position declaration, so I am inspired to write a post toward that very very shortly.

    Thanks again everyone, your feedback is fantastic.

  11. Chase Swindler 16.03.2009 at 6:19 pm

    Technically rather than using 2 images for the hover, wouldn’t it make more sense to make them one image and on the hover set the positioning differently. i.e. resting state is top left, hover is bottom left. Set the height of the image to half of the actual height and then you have half as many images to load when the site is opened.

  12. Chase Swindler 16.03.2009 at 6:20 pm

    Oh, i think you’ve answered my comment already! :D

  13. Zen Elements 16.03.2009 at 7:36 pm

    Chase Swindler | Indeed I have but it is good to see the continued support for that way of doing things =] I’ve a few things on schedule but on my list of posts to complete… it’s in drafts ;]

  14. Samer Kamel 24.03.2009 at 5:32 pm

    @Crd – you would always need a body id attribute if you would like to make your life easier and have the page where you are in a website highlighted in the menu for example .. so instead of editing the menu code on every single page to have the menu button highlighed you can get away with using the body id tag matching the id of ur button ( or class ) so you would have the same menu code ( or even have it in a php include if you prefer ) and the only changed bit is the body id ;)

  15. photo retouching 07.05.2009 at 6:03 am

    Not really commenting on this article, just to say what a nicely designed website. The aesthetics and overall feel is great!

  16. Josh Compston 13.12.2009 at 12:51 am

    I also agree that this would have a smoother overall effect had you used sprites. Nice tut! I recently did a tut on sprites and how to use them….http://joshcompston.com/horizontal-navigation-bar-using-css-sprites/

 

Leave a Reply

(required; who are you?)

(required; we'll keep it safe!)

(optional; promote your site!)