jQuery Tabbed Interface / Tabbed Structure Menu Tutorial

Written by Kevin Liew on 19 Mar 2009
675,963 Views • Tutorials


Nowadays, a lot of websites are using tab based content as a way to save spaces in a webpage. I have seen a lot of wordpress websites using a tabbed interface for its category, posts, comments and random posts content. It's a good "space-saver" and if used it correctly, it can boost your website usability as well. Right, first of all, we need to have the ideas and the design structure for this tabbed interface.

Before we start, if you are looking for a web hosting company, this is a good review - Hostgator Review.

My ideas:
  • Buttons on the top, content reside in different DIV elements,
  • Click on one of the buttons, it shows the relevant content;
  • Click on other buttons, it hides the existing and display the correct one.

The Design structure:

tab menu structure diagram

* Thanks to WeFunction.com for the amazing icons



In case the image above doesnt load, allow me to explain the design structure again. The UL#tabMenu is the buttons on the top a.k.a. Tabs. This is where you click, and it will trigger the jQuery to loads the content.

Inside the boxBody, you need to specify 5 DIVs, the number of DIV will depend on how many items you defined in #tabMenu, in this case, we have 5, therefre, you need 5 DIV elements defined in .boxBody.

The javascript loads the content based on the DIV's index in .boxBody. For example, if you clicked o the first button (the star or index 0), it will load the first DIV in the .boxBody (DIV index 0).

Therefore, arrangement of DIV in .boxBody must match with the arrangement of button in #tabMenu.

<div class="box">

  <ul id="tabMenu">
    <li class="posts selected"></li> <!-- default button-->
    <li class="comments"></li>
    <li class="category"></li>
    <li class="famous"></li>
    <li class="random"></li>

  <div class="boxTop"></div>

  <div class="boxBody">
  	<!-- default page-->
    <div id="posts" class="show parent">
        <li>Post 1</li>
        <li>Post 2</li>
        <li class="last">Post 3</li>
    <div id="comments" class="parent">
        <li>Comment 1</li>
        <li>Comment 2</li>
        <li class="last">Comment 3</li>
 	<div id="category" class="parent">
   	    <li>Category 1</li>
   	    <li>Category 2</li>
		<li class="last">Category 3</li>
  	<div id="famous" class="parent">
        <li>Famous post 1</li>
    	<li>Famous post 2</li>
    	<li class="last">Famous post 3</li>
	<div id="random" class="parent">
        <li>Random post 1</li>
	    <li>Random post 2</li>
    	<li class="last">Random post 3</li>


  <div class="boxBottom"></div>


3. CSS

You can always modify it to match your website. I will attach the psd file for this tutorial in the download and edit the css carefully. : ). Any suggestions please comment.


a {

a:hover {

#tabMenu {
	padding:0 0 0 15px;

#tabMenu li {

/* this is the button images */
li.comments {background:url(images/tabComment.gif) no-repeat 0 -32px;}
li.posts {background:url(images/tabStar.gif) no-repeat 0 -32px;}
li.category {background:url(images/tabFolder.gif) no-repeat 0 -32px;}
li.famous {background:url(images/tabHeart.gif) no-repeat 0 -32px;}
li.random {background:url(images/tabRandom.gif) no-repeat 0 -32px;}

li.mouseover {background-position:0 0;}
li.mouseout {background-position:0 -32px;}
li.selected {background-position:0 0;}

.box {

.boxTop {

.boxBody {

.boxBottom {
	background:url(images/boxBottom.gif) no-repeat;

.boxBody div.parent {

.boxBody div.show {

.boxBody #category a {

/* styling for the content*/
.boxBody div ul {
	margin:0 10px 0 25px;

.boxBody div li {
	border-bottom:1px dotted #8e8e8e; 
	padding:4px 0;

.boxBody div ul li.last {

.boxBody div li span {

/* IE Hacks */
*html .boxTop {margin-bottom:-2px;}
*html .boxBody div ul {margin-left:10px;padding-left:15px;}



4. Javascript

Alright, the fun part. It took me a while to read the jQuery documentation to make it works the way I want. And yes, I made it. As usual, I have put comments on each line. I put the animate effect on category page. I have a tutorial about it - Navigation List menu + Jquery Animate Effect Tutorial

$(document).ready(function() {	

  //Get all the LI from the #tabMenu UL
  $('#tabMenu li').click(function(){
    //perform the actions when it's not selected
    if (!$(this).hasClass('selected')) {    
	    //remove the selected class from all LI    
	    $('#tabMenu li').removeClass('selected');
	    //Reassign the LI
	    //Hide all the DIV in .boxBody
	    $('.boxBody div.parent').slideUp('1500');
	    //Look for the right DIV in boxBody according to the Navigation UL index, therefore, the arrangement is very important.
	    $('.boxBody div.parent:eq(' + $('#tabMenu > li').index(this) + ')').slideDown('1500');
  }).mouseover(function() {

    //Add and remove class, Personally I dont think this is the right way to do it, 
    //if you have better ideas to toggle it, please comment    
  }).mouseout(function() { 
    //Add and remove class

  //Mouseover with animate Effect for Category menu list  :)
  $('.boxBody #category li').mouseover(function() {

    //Change background color and animate the padding
    $(this).children().animate({paddingLeft:"20px"}, {queue:false, duration:300});
  }).mouseout(function() {
    //Change background color and animate the padding
    $(this).children().animate({paddingLeft:"0"}, {queue:false, duration:300});
  //Mouseover effect for Posts, Comments, Famous Posts and Random Posts menu list.
  $('.boxBody li').click(function(){
    window.location = $(this).find("a").attr("href");
  }).mouseover(function() {
  }).mouseout(function() {

5. Finally

You will get a beautiful jQuery Tabbed Side Menu!

However, in category page, if you were using IE, the LI can't be hightlighted when mouse hover it in (that's why we all hate IE). If you know what's the problem, please advise : )

Last but not least, check out the demo or download the source code to play with it. Any questions. please leave your comment :)

Support me by bookmark this article and share it to your friends : ) Thanks


15-9-2011: Fixed DIV issue.

14-4-2009: Remove click event in the LI, change the display attribute in #category to block.

Demo Download
Join the discussion

Comments will be moderated and rel="nofollow" will be added to all links. You can wrap your coding with [code][/code] to make use of built-in syntax highlighter.

Outlanders 10 years ago
I love this script!
Is there any possibility of adding a (nice) scroller to the content? I've tryied but acomplished nothing..
Web Dizajn 10 years ago
Great Job.. Thx from Sarajevo
tapas 10 years ago
Really it's an awsome web application of JQuery. You can find more jquery Application on the following websites

Vivek Kumar 9 years ago
Hey Kevin! Firstly, great job with the entire script! I have a specific question regarding the list under each tab.

I am trying to design something that will consist of two tabs (arranged vertically), each of which will display a drop-down vertical list to the right when clicked. This is similar to what your example above does but I've made some small changes to make it work.

Now, I'm trying to add *another* section to the right which will contain a picture and some information that corresponds to each of the list elements, when clicked. The three sets of information will be arranged from left to right, and the javascript animation of sliding up and down must apply to the right-most section as well. How do I incorporate this third section to the right given that the first two sections (main list and sub-list) work?

Thank you.
Scrapsforever 9 years ago
awesome jquery tutorials hope we will get more like this
Jack 9 years ago
Great Plugin Tool "Tabbed Interface ".

How can implement this plugin in my blog.
George Gina Lucy 9 years ago
"Lovely!! I'm using it on my current proyect, but I have a "small" problem. I just can't include anything besides text or image on the content part, it just stops working. " Thats the point, you´re right!!
Pigi 9 years ago
Fabulous design and clear demonstration of JQuery. I shared to many of my friends.
Matt G 9 years ago
I love it! thanks! I havent got the "selected" tab working yet for some reason. It's my first real go at jquery, this is a great place to start.
Shahaab 9 years ago
Brilliant ! :)
Thank You sir!
Lenin Ocaña 9 years ago
hello, excellent plugin!

have you tried to retrieve the tab data from a database and load it each time a tab is selected?
kevin Admin 9 years ago
Yes, the one i'm using in my website, all the data is loaded from database.
Nimish 9 years ago
I am the designer It helps me lot