One of the common challenges when designing responsive design for mobile is the navigation menu. If the site has many sections or pages, it gets challenging to squeeze all the items into a small mobile resolution. The navigation most likely ends up running into multiple lines or the buttons stacking on top each other. So I'm going to review some of the design solution and provide a quick tutorial on how to create a mobile navigation with jQuery.
Problem
The screenshots below show the navigation layout issues on mobile. If the navigation has 3 or 4 buttons like Web Designer Wall, then the navigation won't wrap into two lines. But if the navigation contains 6 or more buttons, they will stack on top each other.

Solutions
1) Dropdown
One of the commonly used solution is to convert the navigation into a select dropdown. I'm not a big fan of this approach because the <select> element is not stylable with CSS. Javascript plugins like Chosen enables you to modify the dropdown menu, otherwise you end up with the default system dropdown styles. It also causes inconsistent user experience where the desktop version displays link tags and the mobile version displays as a dropdown menu. If you like this solution, here is a tutorial by CSS-Tricks on how to convert a menu to a dropdown.


2) Display as Block
Another quick fix is set each menu item as block elements so they display vertically. But this approach takes a lot of header space. If the navigation has many buttons, this is a bad idea because the readers have to scroll down through the long list of navigation before reaching the content.



3) Menu Icon
The last solution that I'm going to review is to use a menu icon/button to toggle the navigation. I like this method out of the three because it saves space (very important on mobile) and it gives you full control of styling with CSS. The menu icon can be styled to match with the overall design.




Mobile Navigation with jQuery (view demo)
This tutorial shows you how to create a mobile navigation with jQuery as seen on the sites listed above. jQuery will be used to prepend the menu icon and toggle the navigation. This trick doesn't require any extra/un-semantic HTML tags.
HTML
Below is the sample navigation HTML used in this tutorial:
<nav id="nav-wrap">
<ul id="nav">
<li><a href="#">Button</a></li>
<li><a href="#">Button</a></li>
</ul>
</nav>
jQuery Code
Include a copy of jQuery and the function below in between the <head> tag. The function will prepend the <div id="menu-icon"> in the <nav id="#nav-wrap"> tag. When the #menu-icon element is clicked, it will slide down the navigation.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
/* prepend menu icon */
$('#nav-wrap').prepend('<div id="menu-icon">Menu</div>');
/* toggle nav */
$("#menu-icon").on("click", function(){
$("#nav").slideToggle();
$(this).toggleClass("active");
});
});
</script>
It will render the HTML code like this (you need to Inspect Element or view generated source code to see this):
<nav id="nav-wrap">
<div id="menu-icon">Menu</div>
<ul id="nav">
<li><a href="#">Button</a></li>
<li><a href="#">Button</a></li>
</ul>
</nav>
CSS
I'm not going to explain every detail of the CSS code because it is pretty straight forward. Instead, I will talk about the key parts.
The #menu-icon is set to display:none initially. I used media query to change the #menu-icon to display:block if the viewport width is smaller than 600px.

In the media query, I set the navigation to display:none so it is hidden initially on mobile. When the #menu-icon is clicked, it will toggle the navigation as specified in the jQuery function at the above step.
Final Demo
To see the final mobile navigation, view the demo and narrow your browser window or check with your mobile phone.

Update:
Also read this CSS Based Responsive Navigation Menu tutorial.
Probably the simplest way of providing an alternative nav is to display/hide different DIVs, each containing a different nav style, depending on the screen size (using viewport). No jQuery needed (although we love jQuery). We’ve used it here http://www.scubashack.co.uk
Interesting idea, just looked at your example too and noticed that the menu doesnt dissappear if you click it again, i think this would be better as a toggle in case a user accidently clicks on the menu button.
Thanks for the feedback. The mobile menu is just at the bottom of the page, so if a visitor clicks “Menu”, they’re still on the same page. We could add a toggle that simply jumps back to the top of the page.
Really useful information, will look to implement the drop down menu at some point in the near future on my website, currently using the block example and even with only 4 or 5 menu items it still takes up too much space
Nice approach. Unfortunately it does not work without javascript….
Be interesting to see some stats for javascript enabled on mobile devices, id imagine that all smart phones have it but i could be wrong
I believe all your major phone browsers support javascript (iOS, Android & Windows Phone). Most web apps are built using javascript so they have a dynamic feel. You will get better support from javascript then you will CSS3 or webkit(iOS & Android only). Looking at you Android & Windows Phone.
Lol that doesn’t matter anymore kid, everything has JavaScript enabled… if you disable it, you’re a wanker.
Bug….
Resize browser to switch to mobile menu, open and close mobile menu, then resize back. Horizontal menu is gone….
you are absolutely right!!! Nick La should probably fix the bug first. It’s obvious he didn’t test the demo well enough before putting it up.
I’d stick to the dropdown menu solution though. why rely on javascript when you can use dropdown. it’s easier for users and lighter on the browser.
nice try though.
cmon, who does that?! nobody except webdesigners… and they can find bugs _anywhere_ if they just want to.
The Sony menu is very sexy, I like it !!!
I found this one also interessant http://www.moonservices.ch/
Great article! I also recently looked into the pros and cons of various navigation patterns for responsive design here: http://bradfrostweb.com/blog/web/responsive-nav-patterns/
Great stuff!
I’m noticing an issue with the navigation not displaying once you switch back to wider width. Steps to reproduce:
- Make screen size small and the navigation switches to the menu drop down
- Click to see the menu drop down and then click again to hide the menu
- Make screen size large and notice the navigation no longer displays
This is intended for mobile users, not for developers like yourself. Normal readers don’t narrow and then expand their browser window (only developers do that). If you want, you can add another media query to force the #nav to display:block !important; on desktop resolution.
way to go man. instead of admitting your mistake you tell us that the demo is only intended for devs and “normal readers” don’t resize browsers. great way to treat your readers!
“Normal readers don’t narrow and then expand their browser window ” That’s quite a sweeping statement. Have you got any stats to back that up?
common sense? That backs it up pretty well…
Hi Nick. I agree that normal users rarely resize their browsers explicitly. However, they do often switch from portrait to landscape and vice versa, so it’s essential that you add functionality that allows the user to change back and forth repeatedly.
For those concern about the navigation being hidden when switching from mobile version, check the demo again. I applied the fix that I mentioned above in the comment. Now the #nav is always visible on desktop version.
As Nick said, by simply adding @media screen and (min-width: 600px){ #nav{ display:block !important; } } the issue is solved, its a slick and well produced result that I’m implementing right now. Thanks for sharing Nick
on my galaxy s i switch frequently from portrait to landscape and back and got the same bug ;-) but even though i love this tutorial. Thanx..
Out of curiosity, why append the menu-icon div using javascript? Why not have it in the source in the first place, and do a display:none on non-mobile widths?
Just to be more semantic without adding unnecessary tags.
But that tag is necessary if you come at the problem from a mobile-first perspective. Plus, one could argue that adding “Menu” in some sort of appropriate heading tag (as opposed to a div) would make the whole thing more semantic.
By the way, I am not trying to be an asshole about it, so please do not take offense. This article comes at a very good time for me, and has some good info in it, so thank you.
Good point here. The “menu” text could be a heading tag and semantic. It works the same without prepending content with jQuery.
Struggeling on my first mobile first responsive website I have your toggle menu running. The only problem I have is still the bug. It isn’t switching back to normal menu.
I use mobile first so I have the defauld layout for mobile and use the media query to expand for bigger viewports.
How kan I get rid of the bug?
I don’t understand fully the comment fron Sean.
If no solution I’ll have to live with it, this toggle is the only menu I got worken,
So Thanks!!!!
Its always nice when someone bases a post on one you wrote over 2 months ago.
You made a better job of it, I’ll have to say. Well done.
http://blog.bleepsystems.com/2012/solving-a-responsive-design-navigation-problem/
Are you kidding? Your blog doesn’t come up within a relevant number of results for either “responsive design navigation” or “mobile navigation”. If Nick has ever heard of your blog I’d eat my hat. And even if he somehow had heard of it, to claim he based his post on yours is plain silly (and your tone implies he “ripped it off”). Nick lectures about these kinds of things all over the world. Responsive design mobile navigation best practices have been discussed constantly in the web design community (forums, twitter, conferences, videos, articles. podcasts, etc) over the last year or more. In fact most of these exact examples are covered in “Mobile First” by Luke Wroblewski, published Nov 2011 (ah hem, several months before your blog post). Anyone who frequents mediaqueri.es has been exposed to all of these navigation ideas already. Nick wrote a nice article summarizing the ideas and giving his thoughts on which he prefers. Nothing wrong with that… in fact I hope many more posts by various notable web designers add their own perspective. Bah you just wanted to stir up some controversy and drive clicks to your blog, which unfortunately you have succeeded at. Yay for nofollow at least.
Good ideas and good solutions for a real problem on mobiles. I guess the “lov&lux” version is the better to easily navigate and to stay a beautiful app.
thx for tips.
Thank you so much for this list, it really helps me out!
Great ideas!
But one problem is still alive…
how to navigate on sub navigation if the second level is default hidden. because hover don’t exist…
for examplel ul > li >ul >li
Hey. Why not make the addition of icons in CSS? I think JavaScript is useless. Correct me if I’m wrong. Thanks!
I like your preferred method of displaying the navigation as a drop-down. Great tutorial! Thanks for sharing!
Demo not working in Opera 11.62 on Mac OS X 10.7.3. The HEADER “content” property wipes out the entire menu! :(
@SEO-Backlink, all the sub navigations will be expanded when you click on the menu link, so this is not a problem.
In some cases you can decide to keep the toggle effect on hover to show the subnavigation, it will be replaced by an “onclick event” on most touchable screens
Seems bit complex than HTML but effective :)
Love this post to navigation given that mobile browsing is an unstoppable upward trend. I would really appreciate if Web Designer Wall gave some more insights into optimizing websites for mobile devices. Probably and interesting topic is optimizing CTRs (navigation ex-menus) within site pages, as links are not displayed equally in desktops/mobile. Thanks!
Great post. I agree with you and the other folks who prefer the last solution. It seems the most practical, and it has an elegance in it’s simplicity and control over to final look…
nice tutorial