Creating Tabs with HTML, CSS & jQuery

In this tutorial, we’re going to look at how to create tabs in HTML, CSS and jQuery. If you get stuck, don’t hesitate to ask me a question.

Tabs are a great way of grouping lots of content into a very small space. Think of tabs like the TARDIS…bigger on the inside. They can be incredibly handy when you have a lot of content that would simply fill up your page with too much information in one go.

You might also like: Creating an Accordion with HTML, CSS & jQuery.

Table of Contents

  1. Skip to the HTML
  2. Skip to the CSS
  3. Skip to the jQuery

1.) The HTML

Completed Code (HTML)

I go into detail on the specifics of the HTML layout below.

<div class="tabs">
	<ul class="tab-links">
		<li class="active"><a href="#tab1">Tab #1</a></li>
		<li><a href="#tab2">Tab #2</a></li>
		<li><a href="#tab3">Tab #3</a></li>
		<li><a href="#tab4">Tab #4</a></li>
	</ul>

	<div class="tab-content">
		<div id="tab1" class="tab active">
			<p>Tab #1 content goes here!</p>
			<p>Donec pulvinar neque sed semper lacinia. Curabitur lacinia ullamcorper nibh; quis imperdiet velit eleifend ac. Donec blandit mauris eget aliquet lacinia! Donec pulvinar massa interdum risus ornare mollis.</p>
		</div>

		<div id="tab2" class="tab">
			<p>Tab #2 content goes here!</p>
			<p>Donec pulvinar neque sed semper lacinia. Curabitur lacinia ullamcorper nibh; quis imperdiet velit eleifend ac. Donec blandit mauris eget aliquet lacinia! Donec pulvinar massa interdum risus ornare mollis. In hac habitasse platea dictumst. Ut euismod tempus hendrerit. Morbi ut adipiscing nisi. Etiam rutrum sodales gravida! Aliquam tellus orci, iaculis vel.</p>
		</div>

		<div id="tab3" class="tab">
			<p>Tab #3 content goes here!</p>
			<p>Donec pulvinar neque sed semper lacinia. Curabitur lacinia ullamcorper nibh; quis imperdiet velit eleifend ac. Donec blandit mauris eget aliquet lacinia! Donec pulvinar massa interdum ri.</p>
		</div>

		<div id="tab4" class="tab">
			<p>Tab #4 content goes here!</p>
			<p>Donec pulvinar neque sed semper lacinia. Curabitur lacinia ullamcorper nibh; quis imperdiet velit eleifend ac. Donec blandit mauris eget aliquet lacinia! Donec pulvinar massa interdum risus ornare mollis. In hac habitasse platea dictumst. Ut euismod tempus hendrerit. Morbi ut adipiscing nisi. Etiam rutrum sodales gravida! Aliquam tellus orci, iaculis vel.</p>
		</div>
	</div>
</div>

Tab Links

Starting off there’s a div with class="tabs". Inside there’s an unordered list, (or an ordered one if you like, it makes no real difference), with class="tab-links". Inside the list items there are anchor links. The first list item is marked as class="active". This indicates where to start the tabs.

Note: When the CSS is all done, the tab link parent with class="active" will be the highlighted one on page load.

<div class="tabs">
	<ul class="tab-links">
		<li class="active"><a href="#tab1">Tab #1</a></li>
		<li><a href="#tab2">Tab #2</a></li>
		<li><a href="#tab3">Tab #3</a></li>
		<li><a href="#tab4">Tab #4</a></li>
	</ul>
</div>

Tab Content

There’s a div with class="tab-content". Inside of that, we have 4 divs, each with class="tab", (this number corresponds to how many tab links there are). The currently visible tab will also need an active class, e.g. class="tab active".

<div class="tab-content">
	<div id="tab1" class="tab active">
		<p>Tab #1 content goes here!</p>
		<p>Donec pulvinar neque sed semper lacinia. Curabitur lacinia ullamcorper nibh; quis imperdiet velit eleifend ac. Donec blandit mauris eget aliquet lacinia! Donec pulvinar massa interdum risus ornare mollis.</p>
	</div>

	<div id="tab2" class="tab">
		<p>Tab #2 content goes here!</p>
		<p>Donec pulvinar neque sed semper lacinia. Curabitur lacinia ullamcorper nibh; quis imperdiet velit eleifend ac. Donec blandit mauris eget aliquet lacinia! Donec pulvinar massa interdum risus ornare mollis. In hac habitasse platea dictumst. Ut euismod tempus hendrerit. Morbi ut adipiscing nisi. Etiam rutrum sodales gravida! Aliquam tellus orci, iaculis vel.</p>
	</div>

	<div id="tab3" class="tab">
		<p>Tab #3 content goes here!</p>
		<p>Donec pulvinar neque sed semper lacinia. Curabitur lacinia ullamcorper nibh; quis imperdiet velit eleifend ac. Donec blandit mauris eget aliquet lacinia! Donec pulvinar massa interdum ri.</p>
	</div>

	<div id="tab4" class="tab">
		<p>Tab #4 content goes here!</p>
		<p>Donec pulvinar neque sed semper lacinia. Curabitur lacinia ullamcorper nibh; quis imperdiet velit eleifend ac. Donec blandit mauris eget aliquet lacinia! Donec pulvinar massa interdum risus ornare mollis. In hac habitasse platea dictumst. Ut euismod tempus hendrerit. Morbi ut adipiscing nisi. Etiam rutrum sodales gravida! Aliquam tellus orci, iaculis vel.</p>
	</div>
</div>

2 The CSS

I’m going to keep it simple with basic CSS (as opposed to an SCSS pre-processor like Sass, Less or Stylus). The bulk of this tutorial is aimed at beginners, so I’m taking that into account.

Completed Code (CSS)

I go into detail on the specifics of the CSS styling below.

/*----- Tabs -----*/
.tabs {
	width:100%;
	display:inline-block;
}

/*----- Tab Links -----*/
/* Clearfix */
	.tab-links:after {
	display:block;
	clear:both;
	content:'';
}

.tab-links li {
	margin:0px 5px;
	float:left;
	list-style:none;
}

.tab-links a {
	padding:9px 15px;
	display:inline-block;
	border-radius:3px 3px 0px 0px;
	background:#7FB5DA;
	font-size:16px;
	font-weight:600;
	color:#4c4c4c;
	transition:all linear 0.15s;
}

.tab-links a:hover {
	background:#a7cce5;
	text-decoration:none;
}

li.active a, li.active a:hover {
	background:#fff;
	color:#4c4c4c;
}

/*----- Content of Tabs -----*/
.tab-content {
	padding:15px;
	border-radius:3px;
	box-shadow:-1px 1px 1px rgba(0,0,0,0.15);
	background:#fff;
}

.tab {
	display:none;
}

.tab.active {
	display:block;
}

Tabs Container

The display:inline-block; adds a type of clearfix while also making it more ‘stable’ than if we used display:block;.

The reason we use a clearfix above yet not here is as follows: display:inline-block; sometimes adds 7px-ish of margin below the affected element with no way of removing it. Sometimes using a minus bottom margin works, but it depends heavily on how your HTML is structured. In this instance it’s fine.

/*----- Tabs -----*/
.tabs {
	width:100%;
	display:inline-block;
}

Tab Link Wrappers

We declare no list-style to stop it appearing as a default list. Then the margin so the links are spaced evenly apart, (using margin:0px 5px; is the same as using margin:0px 5px 0px 5px;).

.tab-links li {
	margin:0px 5px;
	float:left;
	list-style:none;
}

Tab Links

These are all basic styles which you should understand if you’re attempting this tutorial. If you don’t, please find the proper values and the definitions for each on the CSS-Tricks Almanac.

You may be wondering why I’ve used transition:all linear 0.15s; instead of transition:background linear 0.15s;. The reason is simple, in my experience, you have to think ahead. If you don’t then nasty, (sometimes hard to fix), bugs pop-up seemingly out of nowhere. By using background instead of all, we’d be limiting what can be transitioned on the :hover effect. Since this is a tutorial, many of you may want to change the text colour on hover. By using all instead of background that makes it possible.

.tab-links a {
	padding:9px 15px;
	display:inline-block;
	border-radius:3px 3px 0px 0px;
	background:#7FB5DA;
	font-size:16px;
	font-weight:600;
	color:#4c4c4c;
	transition:all linear 0.15s;
}

.tab-links a:hover {
	background:#a7cce5;
	text-decoration:none;
}

li.active a, li.active a:hover {
	background:#fff;
	color:#4c4c4c;
}

Tab Content

This is the background of the tab content section.

/*----- Content of Tabs -----*/
.tab-content {
	padding:15px;
	border-radius:3px;
	box-shadow:-1px 1px 1px rgba(0,0,0,0.15);
	background:#fff;
}

Non-Active/Active Tab Content

We set all tabs to display:none; which hides them. Then we set the active tab to display:block; so only that one will show up. It’s a simple case of using CSS the way it was designed, which was to cascade down. Hence the name, Cascading Stylesheets.

.tab {
	display:none;
}

.tab.active {
	display:block;
}

You might also like: Creating a Dropdown Menu with HTML & CSS


3 The jQuery

Below you can see the completed jQuery code. Keep scrolling for a good explanation of how it all works and what it all means.

Let me clarify something before we start: Everyone has their own way of coding, with jQuery this is mine. Writing it out like this makes it easier for a beginner to grasp, it’s also efficient.

Completed Code (jQuery)

jQuery(document).ready(function() {
	jQuery('.tabs .tab-links a').on('click', function(e) {
		var currentAttrValue = jQuery(this).attr('href');

		// Show/Hide Tabs
		jQuery('.tabs ' + currentAttrValue).show().siblings().hide();

		// Change/remove current tab to active
		jQuery(this).parent('li').addClass('active').siblings().removeClass('active');

		e.preventDefault();
	});
});

Basic Setup

You have to start by checking if the document is ready, for this we use:

jQuery(document).ready(function() {
	// Code Here
});

Next is to check if the user has clicked on a tab, to do that we simply reference every link that happens to be a tab link with .tab-links a.

jQuery('.tab-links a').on('click', function(e) {
	// More Code Here
});

Dynamic Variable

Next, we create a variable called currentAttrValue, (current attribute value), which grabs the href="" of the clicked anchor link.

var currentAttrValue = jQuery(this).attr('href');

Match Anchor Link to Div #ID

We need a way of matching up the .tab-link anchors with .tab sections. We start off by referring to the entire tabs component, with .tabs, then we say “If .tabs has a child with an #id that then matches a .tab-link href="", then they should be linked up”.

Then we say “Show the element with the referenced #id, such as #tab2, then find the other tabs, which are siblings of #tab2, and hide them”.

jQuery('.tabs ' + currentAttrValue).show().siblings().hide();

Giving The Tab Link an Active State

Changing the active state of the tab link is relatively the same as showing/hiding the tab content.

First, we look for jQuery(this), which is the current anchor link being clicked. Then we find it’s parent list item with .parent('li') tag. After that, we give that parent list item a class of .active by using .addClass('active'). Lastly, we find all siblings of that parent list item and remove, if any, classes of .active by using .siblings().removeClass('active').

jQuery(this).parent('li').addClass('active').siblings().removeClass('active');

Prevent Default Anchor Link Behaviour

You may notice that when you click an anchor link with an #id specified instead of an actual URL, it tends to add the #id into the address bar. E.G. http://sebkay.com becomes http://sebkay.com/#id. This can be a massive pain-point for users when trying to click the back button.

To get past that UX problem we use:

e.preventDefault();

This handy little function stops the default action of the clicked element from happening.

Remember when we put that function(e)at the start of our click event? Well, this is where that ties in.


Extra Credit: jQuery Animations

You may not like the way it just jumps to the new tab content without any nice animation of any kind, well here’s some extra credit.

To apply these changes simply replace the below snippet with the other code snippets that follow.

Default

// Show/Hide Tabs
jQuery('.tabs ' + currentAttrValue).show().siblings().hide();

Fade

// Show/Hide Tabs
jQuery('.tabs ' + currentAttrValue).fadeIn(400).siblings().hide();

Slide 1

// Show/Hide Tabs
jQuery('.tabs ' + currentAttrValue).siblings().slideUp(400);
jQuery('.tabs ' + currentAttrValue).delay(400).slideDown(400);

Slide 2

// Show/Hide Tabs
jQuery('.tabs ' + currentAttrValue).slideDown(400).siblings().slideUp(400);

Conclusion

If you’re reading this conclusion, (most people, including me, tend to leave after they’ve got the code they were after), then please leave a comment below with any problems or bugs regarding this tutorial. I’m writing this to help people learn and become the best they can be.

You might also like: 21 Must-Have Front End Development Tools.


Comments

Leave a Comment

Comments (561)

Mike

March 1, 2015 at 7:38 pm

Hi,
Thanks… very nice for a couple of reasons. At my (low intermediate) level of understanding of the Arcane Arts (PHP, JQuery and a zillion others) my natural inclination is to choose the standard, tried and tested turnkey component by default (in this case it’d have been JQuery UI tabs).

But there’s always going to be a tension, it seems to me, between accepting that the super-experts know best, and having something you can *control* (and tweak). I’m a bit of a fanatic of about error trapping and logging for this reason.

In particular when you talk about the CSS here I get a bit lost: I had to google “clearfix” and am still not much the wiser. But by using JQuery UI without knowing about some of the technical issues of CSS you do risk making your code rather fragile. So it’s good to hear explanation from an expert to a lowly serf like myself.

Couple of suggestions:
Could you not have the complete downloaded file (or files: .php, .css and .js) with the full HTML and stuff, for relative newbs? Because, not surprisingly, the source code on your demo page bears little relationship to the simple completed file.
Secondly, at the top of your page it says you have “345 comments” about this. I can see about 10. Where are the other 335? Or is this a glitch?

Reply

Emdadul hoque

February 27, 2015 at 6:56 pm

I want to add another tab. How can I add the another tab?
Html: Tab #5
div id=”tab5″ class=”tab”>
Tab #53 content goes here!
Donec pulvinar neque sed semper lacinia. Curabitur lacinia ullamcorper nibh; quis imperdiet velit eleifend ac. Donec blandit mauris eget aliquet lacinia! Donec pulvinar massa interdum ri.

When I click on tab5 then other tabs hidden. Why?
Can tell me please, How can I fix this?

Reply

Mike

March 1, 2015 at 7:52 pm

you have to add another list element (<LI>, under <UL class=”tab-links”>’ ) as well as another <DIV>

Reply

Shane Jackson

February 23, 2015 at 6:47 pm

Great post! Love it!

Is there anyway to get the tabs on a right table column to the right and let the content display on the left. Trying to turn it into something that’s its not. Trying to customise it to make it with as a content replacer.

Reply

Adrian

February 20, 2015 at 5:25 am

Also, I don’t know what am I missing, the active tab is showing the content from all tabs, I verified the code, but its all like in this tutorial, can you help me with this please?

Reply

Adrian

February 22, 2015 at 3:15 am

I have found what I am missing: you have to add this lines #tab2, #tab3, #tab4, #tab5 { display: none; } in order to prevent the active tab showing all content at once, only tab1 will be visible as it should be, unless you don’t want that of course…

Reply

Adrian

February 20, 2015 at 5:23 am

It is possible to center the tabs ? I mean the “menu”.

It works nice and I like this tutorial, it helped me, but I would like to know if you can center the tabs.

I am making a portfolio, so there will be galleries(thumbnails-zoom on click) in each tab, different categories.

Reply

parhamparsa

February 19, 2015 at 9:49 am

is it possible to close tabs?????

Reply

Leo

February 18, 2015 at 8:33 pm

I’m putting this in my WordPress webpage–while the CSS and HTML have worked fine, I can’t figure out how to properly call the jquery. I’ve tried referencing the .js file with


<script type="text/javascript"
src="/js/tablinks.js”>

in the header.php theme, but to no avail.

Any suggestions?

Reply

John

February 16, 2015 at 2:23 am

Thanks a lot for sharing. Great for beginners.

Reply

Lisa

February 13, 2015 at 8:25 am

Working perfectly in my site. Thank you for this amazing tutorial!

Reply

sameena

February 9, 2015 at 5:02 am

can u plz write the code to make the tab stay on the current page after clicking the submit button. need help ASAP!!

Reply

Jim

February 8, 2015 at 6:29 pm

Hello: Where did I go wrong?

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"

tabs

jQuery(document).ready(function() {
jQuery(‘.tabs .tab-links a’).on(‘click’, function(e) {
var currentAttrValue = jQuery(this).attr(‘href’);

// Show/Hide Tabs
jQuery('.tabs ' + currentAttrValue).show().siblings().hide();

// Change/remove current tab to active
jQuery(this).parent('li').addClass('active').siblings().removeClass('active');

e.preventDefault();
});

});

/—– Tabs —–/
.tabs {
width:100%;
display:inline-block;.
}

/*----- Tab Links -----*/
/* Clearfix */
.tab-links:after {
display:block;
clear:both;
content:'';
}

.tab-links li {
margin:0px 5px;
float:left;
list-style:none;
}

.tab-links a {
padding:9px 15px;
display:inline-block;
border-radius:3px 3px 0px 0px;
background:#7FB5DA;
font-size:16px;
font-weight:600;
color:#4c4c4c;
transition:all linear 0.15s;
}

.tab-links a:hover {
background:#a7cce5;
text-decoration:none;
}

li.active a, li.active a:hover {
background:#fff;
color:#4c4c4c;
}

/*----- Content of Tabs -----*/
.tab-content {
padding:15px;
border-radius:3px;
box-shadow:-1px 1px 1px rgba(0,0,0,0.15);
background:#fff;
}

.tab {
display:none;
}

.tab.active {
display:block;
}

<a href="#tab1" rel="nofollow">Tab #1</a>
<a href="#tab2" rel="nofollow">Tab #2</a>
<a href="#tab3" rel="nofollow">Tab #3</a>
<a href="#tab4" rel="nofollow">Tab #4</a>

Tab #1 content goes here!
Donec pulvinar neque sed semper lacinia. Curabitur lacinia ullamcorper nibh; quis imperdiet velit eleifend ac. Donec blandit mauris eget aliquet lacinia! Donec pulvinar massa interdum risus ornare mollis.

Tab #2 hello? content goes here!
Donec pulvinar neque sed semper lacinia. Curabitur lacinia ullamcorper nibh; quis imperdiet velit eleifend ac. Donec blandit mauris eget aliquet lacinia! Donec pulvinar massa interdum risus ornare mollis. In hac habitasse platea dictumst. Ut euismod tempus hendrerit. Morbi ut adipiscing nisi. Etiam rutrum sodales gravida! Aliquam tellus orci, iaculis vel.

Tab #3 content goes here!
Donec pulvinar neque sed semper lacinia. Curabitur lacinia ullamcorper nibh; quis imperdiet velit eleifend ac. Donec blandit mauris eget aliquet lacinia! Donec pulvinar massa interdum ri.

Tab #4 content goes here!
Donec pulvinar neque sed semper lacinia. Curabitur lacinia ullamcorper nibh; quis imperdiet velit eleifend ac. Donec blandit mauris eget aliquet lacinia! Donec pulvinar massa interdum risus ornare mollis. In hac habitasse platea dictumst. Ut euismod tempus hendrerit. Morbi ut adipiscing nisi. Etiam rutrum sodales gravida! Aliquam tellus orci, iaculis vel.

Reply

Noopur Phalak

February 7, 2015 at 2:43 pm

Hey, Nice tutorial, but, I have a problem. When I click the tabs, the content doesn’t change, it always shows the content of the first tab. Why might this be happening?

Reply

Steven

February 5, 2015 at 7:34 am

Hey, thanks for that great tutorial! Helped me a lot.

But there’s one open question: I would like to set the content to fix height. If the height is utilized completly by the content, it should get scrollable.

Thank you for your help.

Reply

Robin H

February 4, 2015 at 11:21 am

Hey thanks for the tutorial!

I have a problem that when I click the anchors it will scroll down to the links. Im using Skrollr.js and maybe there is a conflict. I couldn’t find anything to disable skrollr for specific functions.

Reply

Seb Kay (Author)

February 4, 2015 at 3:26 pm

This tabs code wouldn’t cause the scroll so yes it appears to be a conflict. Have you got a demo I can take a look at?

Reply

Ainu Qaghan

February 3, 2015 at 2:26 pm

Very helpful, thank you.

I was actually looking for more than just code snippets and in that regard, I really liked and appreciate this article.

Reply

Florin

January 31, 2015 at 8:19 pm

Hi,

Thank you very much for your work, code works really great!
One question though: I am trying to have the page reloaded to the same location tab! I have 1 button inside div tag, on each of the generated tabs! Each of these buttons (after pressed) should reload only its corresponding tab. Currently, first tab is always loaded!

Your help would be greatly appreciated!
Thank you in advance!

Reply

Shin

January 28, 2015 at 4:12 pm

Hello!
Thanks so much for this detail tutorial. Really appreciate it.

I copied and pasted the code into JSFiddle, but the tab doesn’t work when I click it. It only displays the first tab content. Could you take a look and let me know what is the issue?

Thanks again!

Reply

Seb Kay (Author)

January 28, 2015 at 4:24 pm

Hey Shin,

The problem is that you’re not properly including a version a jQuery. Here is the updated version: http://jsfiddle.net/qfgs55hz/1/ – If you look in the sidebar you’ll see it says jQuery 1.11.0, under “Frameworks & Extensions”.

Reply

Oliver

January 21, 2015 at 8:46 pm

Hello,

Thanks for this awesome code it really helped me!!

One problem… when the tabs are clicked the whole page scrolls away and you have to move it back down to see the tabs again.

How do I stop this?

Thanks again for all your hard work!!
🙂

Reply

Seb Kay (Author)

January 21, 2015 at 11:05 pm

Can you give me an example of a live preview? I’ve never encountered this bug, although if the tabs are at the bottom of the page it will naturally scroll the page to the new height.

Reply

Oliver

January 22, 2015 at 11:08 am

Hi Seb, thanks for your reply please take a look here..

http://www.brightonelectric.co.uk/#tab1

There are two tabbed areas they both have the same problem

Thanks again for you time 🙂

Reply

Seb Kay (Author)

January 23, 2015 at 9:00 am

Have you got any sort of smooth scroll or any other jQuery plugins active? The tabs alone wouldn’t be able to do what’s happening. It looks like some type of conflict.

Reply

Oliver

January 23, 2015 at 4:56 pm

Errr Not sure, the site was made using Squarespace.. Don’t know if they run and jQuery.
It’s the only jQuery I’ve put in that’s for sure..
🙂

Seb Kay (Author)

January 25, 2015 at 8:12 am

Definitely looks like a conflict. Can you check to see what plugins or services are enabled by Squarespace?

Geoff Kendall

January 19, 2015 at 2:55 pm

Thanks for this, Seb. I’ve rarely seen such a clear exposition of how to get a thing done. Hugely appreciated – and it does, most definitely, work as advertised – at least, in all the browsers I have tested so far and, being jQuery, that pretty much means it works everywhere.

Reply

Mark Anthony

January 19, 2015 at 3:43 am

Dear Seb, just folowed, copy pasted your code and somehow it does not work. i believe your tab is excellent. could you please help me to make this work?thanks

Reply

Seb Kay (Author)

January 19, 2015 at 11:03 am

Have you included a version of jQuery before you load the code for the tabs?

Reply

Szabolcs

January 17, 2015 at 5:45 pm

I’ll try to the same code, that you wrote. But someways, the first 3 tab working and the others aren’t. What’s the reason of the problem? Please help. www.felhaz.hu/kepek.html

Reply

Seb Kay (Author)

January 18, 2015 at 1:07 pm

The reason it’s not working is that tabs 4 to 6 are referencing tab content areas that don’t exist. Also the last 3 tabs are referencing like #tab04 whereas the others are referencing like #tab2.

Reply

Szabolcs

January 18, 2015 at 7:04 pm

That’s true, but when I rewrote, nothing happened. It’s the same problem.

Reply

Szabolcs

January 17, 2015 at 9:36 am

Please help me. I tried everything, but the tabs between 2013 till 2015 isn’t work. Not show anything. I’ll wait your early reply.

Reply

Szabolcs

January 17, 2015 at 9:37 am

Here is the website: http://felhaz.hu/kepek.html

Reply

sunny

January 14, 2015 at 5:37 pm

which library you use for jquery?

Reply

Seb Kay (Author)

January 14, 2015 at 5:48 pm

It’s jQuery version 1.11.1.

Reply

shel

January 14, 2015 at 4:38 pm

Your tutorial was awesome and clear to understand. I hate tutorials that assume the reader knows important details and leaves them out. On numerous occasions I spend more time debugging tutorials.

Yours was awesome! Thanks.

Reply

Justin

January 13, 2015 at 7:58 pm

What is the IE compatibility for this? Thanks. ~ Justin

Reply

Seb Kay (Author)

January 13, 2015 at 9:53 pm

Compatibility goes all the way back to IE7, so your safe to use it 🙂

Reply

Richard

January 6, 2015 at 4:25 am

You forgot to toggle the ‘active’ class on ‘.tab’, didn’t you? In the example code, you only toggled the visibility but not ‘active’, so the first ‘.tab’ is always active.

Reply

Khan

January 5, 2015 at 6:01 pm

I think .tab.active { } is never even used because you use show() to make the individual tabs visual.

I would do something like:
$(“.tab”).removeClass(“active”);
$(currentAttrValue).addClass(“active”);

Reply

Niki

December 30, 2014 at 1:04 pm

I used your tutorial to help me with an assignment. Everything worked great! Thank you!! 😀

Reply

taz

December 25, 2014 at 5:18 pm

the css and the html all worked out, the jquery part does not work at all. i tried placing the code in head, body direct and also via src.

Reply

mrhill

January 31, 2015 at 10:02 pm

Did you place the jquery code snippet between the tags?

Reply

Ankit

December 19, 2014 at 10:43 am

ThankS a lot….its working perfectly and very useful code

Reply

alan

December 16, 2014 at 7:09 pm

Thanks for the example and the working code. It was very clear and concise.

Reply

JaggerBomb

December 16, 2014 at 3:52 pm

Thanks a lot.! Very usefull and works perfectly for me.
It’s really personalizable (I’ve succeed in putting my tab-navigation on the left side)
PS: I’m french so please don’t mind the writing mistakes.

Reply

Rayhan

December 15, 2014 at 5:50 pm

Thanks a lot. I found many other tutorials on this but they are conflicting. Your code doesn’t conflicts with others jquery plugins.

Reply

Bruno Galvão

December 12, 2014 at 6:19 pm

It worked flawlessly! Great explanation, tks a lot!

Reply

john

December 12, 2014 at 3:12 pm

Could you please share the full source code to us? Thank you!

Reply

Andre

December 10, 2014 at 5:56 pm

Awesome. I was just hunting around for something to help me with tabs on my site and stumbled onto this. Works like a dream. and literally had it up and running and styled my way in 10 minutes. Thanks for the excellent tutorial

Reply

Kendrick

December 10, 2014 at 12:28 am

Doesn’t work for me. None of the tabs work when you hover over them. Maybe you left out something.

Reply

Antonette

December 9, 2014 at 7:30 am

Hallo Seb

Great post!

Could you maybe guide me on how I could align the tabs to be more left? There is a gap to the left of the first tab and I don’t know how to remove it or aleast make it smaller.

Thank you!
Antonette

Reply

Grace

December 8, 2014 at 12:01 pm

I have put into notepad everything you have said, and on appearance it looks great. However, when I go to click on the other tabs it doesn’t do anything. Do you have any idea why?

Reply

swapna

November 30, 2014 at 6:12 am

I am beginner,your site helps me alot..to understand..but my problem is that tabs are changing but context are not changing.Need your reply or help as soon as possible..

Reply

Aniruddh

December 17, 2014 at 4:31 pm

@Seb(Author): Thanks 🙂
@Swapna, you need to include jquery cdn or download the package.

Reply

Jaime

November 28, 2014 at 3:34 pm

Is there an easy way to go to a specific tab on a link click (like in a wizard, going to the next step, after completing the form on step 1)?

Reply

Amruta

November 14, 2014 at 9:29 am

May I know why you require atleast jquery 1.11.1? It worked for me only after changng to this library? Response would be appreciated

Reply

Matthew Dey

November 11, 2014 at 5:09 pm

This line is missing from within the

If you have a look at the demo page linked on this site and view the source code. Had me stumped for a while

Thanks for the code though, much appreciated

Reply

Matthew Dey

November 11, 2014 at 5:10 pm

doh, code has been stripped…. second attempt

….script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js”></script…..

Reply

wasii rana

November 11, 2014 at 12:22 pm

its helpfull thanks alot….

Reply

Andrew

November 9, 2014 at 4:11 pm

So, I was making a website, and the tabs show up, but jQuery doesn’t work. I was wondering maybe I have to linik them together with ? Please, I need help!

Reply

Brenda

November 7, 2014 at 1:28 am

Very useful 🙂 thank you very much!

Reply

John

November 7, 2014 at 12:08 am

I followed the steps, but because mine is a wordpress plugin to input popout with html.

It has a css, html but js input field instead of jquery.

The issue is when 1st load, on tab #1, it show all 4 tabs content, after click other tab then it go back to normal.

Any solution?

Reply

Eric

November 6, 2014 at 4:11 pm

I can’t seem to get this to work in wordpress. It is working fine in JSfiddle. Everything is enqueued properly as far as I know. I really don’t understand what the problem is.

Here is the test page eastgreenbushsalonandspa.com/test/

Can you offer any insight?

I have tried your code as is, I have tried it with jQuery(document).ready(function($) { and changed everything to $, I’ve tried everything I can think of.

Thanks for any help.

Reply

Rocky

November 6, 2014 at 1:50 pm

Worked beautifully. Thank you

Reply

Tara

November 4, 2014 at 6:21 pm

When using jQuery’s do you need to download jQuery onto your computer, and where do you put the above coding? In the css or html coding? I think the absence of the jQuery is the reason why the tabs won’t change content, do I need the jQuery for changing the tabs content when clicked? Other than that this has been wonderfully helpful, I myself am a beginner but your instructions were really easy to follow. I’m not sure if you’ll need to see my coding to help so let me know. Thank you!

Reply

abhirup

November 20, 2014 at 12:47 pm

tabs are working but the context is not changing Why?

Reply

Inspirational Newsletter


Join the newsletter to get the best articles, tutorials and exclusive freebies every two weeks.

No spam. You can unsubscribe at any time.