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.
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>
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>
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>
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.
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;
}
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;
}
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;
}
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;
}
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;
}
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
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.
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();
});
});
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
});
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');
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();
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');
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.
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.
// Show/Hide Tabs
jQuery('.tabs ' + currentAttrValue).show().siblings().hide();
// Show/Hide Tabs
jQuery('.tabs ' + currentAttrValue).fadeIn(400).siblings().hide();
// Show/Hide Tabs
jQuery('.tabs ' + currentAttrValue).siblings().slideUp(400);
jQuery('.tabs ' + currentAttrValue).delay(400).slideDown(400);
// Show/Hide Tabs
jQuery('.tabs ' + currentAttrValue).slideDown(400).siblings().slideUp(400);
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.
Join the newsletter to get the best articles, tutorials and exclusive freebies every two weeks.
kerem
June 8, 2015 at 4:21 pm
Mystery solved 😛 Lol…
In JSFiddle, just go Frameworks & Extensions section (the navigation column on the left side of page) and select jQuery 2.1.3
Then it is going to work.
Here is working demonstration: https://jsfiddle.net/o6zr4e80/1/
HGN
July 6, 2015 at 1:08 am
Thank you Kerem for sharing it!
Ganesh
June 8, 2015 at 10:43 am
Hi,
Thanks a lot for the tutorial. I too had the problem of switching the tabs so the work around that I came up with was to hide the tabs corresponding to the links clicked.
Of course I added the IDs “tab1” and “tab2” to the above anchor tags. I know that this is a basic approach but I was wondering if there was any downfalls to this approach.
Other than that, nice piece of code – I really appreciate the time you took to share it with us 🙂
David
June 2, 2015 at 9:22 am
To everyone having the problem where they click on the new tab but the content does not change, I found the following fix:
I believe this line of code in the jQuery code:
was a typo and intended to be
The issue is the naming, the original assumes the id’s for tab content are “tabs 1” when the html posted is using the name “tab1”. This solved the problem for me when viewing in chrome.
Morgan
June 3, 2015 at 3:58 pm
This change still isn’t making the tab content change on my page. Everything in my files is the same, except I have changed the text on my tabs to the names I want displayed, and I do not have
included in my CSS file (it made the first tab always be highlighted like it was being hovered over).
Any suggestions on what I can do to make the content change when I click the tabs? I have JQuery in my HTML file before the tag linking my JS file.
Seb Kay (Author)
June 4, 2015 at 7:54 am
Hey, sorry to see you both having trouble. Make sure you have a wrapper of .tabs around the entire thing, that’s what .tabs in the jQuery refers to. Each tab content pane also needs and ID that corresponds to the #id in each tab link.
If you’re still having trouble, post your code to JSFiddle and I’ll take a look 🙂
monica
June 2, 2015 at 5:00 am
how do i create the following tabs horizintally on my website
customers my services about
Sharad
June 1, 2015 at 5:39 am
Nice Post Helped me alot.
Bharath vijay
May 29, 2015 at 6:49 am
Hi, The tabs aren’t working for me . And yes i have included jQuery2.1.4 . I get an exception stating ” Uncaught Error: Syntax error, unrecognized expression: .tabs #”
Seb Kay (Author)
May 29, 2015 at 7:52 am
Can you post your code on JSFiddle? I’ll take a look and see if there’s anything wrong 🙂
Sophie
May 28, 2015 at 4:21 pm
Hey this is awesome! Just wondering if you had ay thoughts on how to disable a tab (so the use can’t click on it temporarily).
Seb Kay (Author)
May 29, 2015 at 7:51 am
Hey Sophie, great question. I’d advise a two step approach. First, make sure to to stop the functionality of any tab link with a class of
.disabled
. You could do this in the jQuery withThe second part is to add some styling to the
.disabled
class and change the cursor to “no-allowed”, like socursor:not-allowed;
,Rusk
May 26, 2015 at 9:30 am
I copied the code into a simple html file but cannot click the tabs.
Seb Kay (Author)
May 27, 2015 at 9:42 am
Are you including a copy of jQuery? It needs to be version 2.11.1 or higher 🙂
zira
May 26, 2015 at 3:13 am
I have applied your tutorial codes.however, tab link not work for me.url changed to tab2, but display still in tab1. please help.
Seb Kay (Author)
May 26, 2015 at 7:34 am
Hi, it sounds like the problem is how you’re including jQuery. Try including it from this URL in the head of your document (https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js).
Scipio
May 21, 2015 at 2:33 pm
This is great but how am I able to download the code in a single .html file which I will open in my browser and see the tabs? Copying the code from “View Page Source” didn’t work for me. Thanks in advance.
Seb Kay (Author)
May 22, 2015 at 7:39 am
You’ll need to have the CSS, JS and HTML all together for it to work. Do you konw how to include JS and CSS files into a HTML page?
Valentina
May 19, 2015 at 6:12 pm
I don’t get it how it works, that you can click on it and something happens…
Thank you
Oreb
May 15, 2015 at 9:24 am
Wow!! This is awesome 🙂 Thank you very much for this 🙂
mark
May 14, 2015 at 11:14 pm
My primary interest in tabbing is to reduce a page’s loading size. Does this code only ‘load’ the active tab or is it loading all tabs when the page is loaded? If all, what approach do you recommend for only loading the visible portion of a page? Thanks.
Seb Kay (Author)
May 15, 2015 at 8:24 am
Hey Mark, great question! This code actually loads all the tabs, as it’s primarily been designed for smaller amounts of information. If you’d like to only load the tabs content when clicked (and the active one on page load) I recommend using Ajax. You may want to look into jQuery UI for this.
rasha
May 12, 2015 at 9:42 pm
The Best tut for Jquery Tabs…
Gian
May 13, 2015 at 4:51 am
Why is it when click the tab menu. It doesnt go to other tab?
Seb Kay (Author)
May 13, 2015 at 7:53 am
Are you including a copy of jQuery before the tabs JavaScript code?
Jure
May 12, 2015 at 12:27 pm
Where do i place the jquerry code as im not familiar with it. i’ve tried including a separate file with tags and directly placing it above the html in tags, and none of those two procedures worked..
please help
Seb Kay (Author)
May 13, 2015 at 7:48 am
Hi Jure! Are you also including a copy of jQuery? You just need to include this URL (http://code.jquery.com/jquery-1.11.1.min.js), like you would the tabs.js file. Make sure it’s before the tabs.js file though.
Jarrod
May 7, 2015 at 12:15 am
Thanks for the tutorial, I was just wondering how I could center the tabs rather than having them left aligned like they are in your code?
Seb Kay (Author)
May 7, 2015 at 7:54 am
If you wrap the unordered list,
.tab-links
, in a div, addtext-align:center;
to the div anddisplay:inline-block;
to.tab-links
, it should be centered.Thanks for the reading!
Azhari
May 5, 2015 at 10:24 am
Very nice tutorial, easy to understand. Good Jobs!
Andrew
May 4, 2015 at 10:07 pm
Hello, I too would like to know how to change the jquery to allow the tab links to be bookmarked (hashable). For my application it would be best to link directly to a specific tab.
Thanks for the great tutorials!
peter
May 4, 2015 at 4:15 pm
I’m very new to jquery or javascript. Lets say when I click on tab 4 and go to another url or forward and then hit the back button of my browser it defaults to tab 1 when I needed to be on tab 4 or any other tab that was clicked on prior to me going forward and then going back?
e.preventDefault();
above should fix things but i don’t know where to place it inside the script. please send me the entire code with that being there because its not really clear where it has to go.
Aayush Thakur
May 2, 2015 at 6:08 pm
Thanks for this easy explanation, it really helped me. But i have a problem.
Suppose i am right now on tab#1 and i clicked on tab#2 , it doesn’t remember the position of the browser while i was on tab#1 it get resets to default up position of the web page , So i have to scroll again to read the data on tab#2. Please help me out.
Thanks in advance. 🙂
Maurice
May 1, 2015 at 9:57 am
Excellent tutorial
Oscar
April 21, 2015 at 6:21 pm
Really great tutorial and content. I am having a problem though. When I link back to the page that I have this on, the tabs do not switch. I have t ofully reload th epage before the tabs will switch. Any ideas?
rasha
April 20, 2015 at 1:37 pm
Thanks a lot
good tut
Squeezebox
April 17, 2015 at 7:47 pm
Nice compact tab design, great for automated page creation via a script which is just what I needed. Let me bang out a workable report demo in less than a day. Thanks a bunch. I got caught by the
issue in the CSS but once I got that I was set. It is also worth noting that the reference to the jQuery file needs to be before the jQuery code, a trap for young players!Seb Kay (Author)
April 20, 2015 at 8:32 am
Good catch! I used a CSS reset when I made the tabs and forgot to mention. Thanks for helping out 🙂
secco
April 20, 2015 at 5:26 pm
I got caught these two traps as well, but at the end I got everything up, running, and adjusted to fit my own layout in few hours. Thank you very much for the tutorial. I learned a lot of new things today and I did something I probably could not do alone… : )
Seb Kay (Author)
April 20, 2015 at 5:37 pm
No problem. Really glad I was able to help 🙂
Alexandru
April 16, 2015 at 4:51 pm
sorry.. i insert all you code into my site: but it don’t change tabs..
i loaded you the code i used for you tutorial there:
https://jsfiddle.net/enczLLh0/
please look at it and if you can help me.. before it worked but the slider image stopped..
now go the slider and i see the tabs.. but don’t change tab..
Brian
April 16, 2015 at 2:52 pm
Great code, I really like how simple this is. Can you tell me how to prevent the ‘active’ tab from making the page scroll to to the active #tab1 div when clicked? When I remove the ‘active’ class from the #tab1 div there is no scrolling when the tab is clicked but this obviously needs to be there to show the initial content on page load, otherwise it’s blank. Any takers? Cheers
Annabel
April 15, 2015 at 7:16 am
Hey! Firstly thankyou so much for this tutorial, it is very helpful. However, I seem to be having the same issues as most people, where the jQuery is not working (i cannot switch between tabs). I am working on adobe dreamweaver CS6, on a HTML 5 document. I have put the jQuery code in two tags in the header of the document. I noticed what you did for Mohamed (changing the jQuery to 2.1.0), and I was wondering how to do that for dreamweaver, or how else to fix this problem. Thankyou so much!
Werner
April 14, 2015 at 3:27 pm
Hey, thanks for the code. i appreciate it a lot, learning this stuff from scratch now so a big help.
Danilo
April 13, 2015 at 11:15 pm
How I can open specific tab from another link?
I want to link picture from my homepage, to open tab#3 for example. I can’t do that, cause everytime i put #tab3 in URL it opens first tab, cause all others are hidden?
Thanks
Cristian
April 12, 2015 at 2:21 am
Can you packaging it up into a ZIP folder??? PLEASE
Seb Kay (Author)
April 13, 2015 at 7:54 am
I’ll try to put the code together in a ZIP folder at some point soon 🙂
Mohamed
April 11, 2015 at 5:20 pm
thanks for this tutorial but sadly it didnt work ,i faced the same problem other faced,tabs won’t switch
please can you find what wrong,this is my code:
https://jsfiddle.net/euzdf2jb/
Seb Kay (Author)
April 13, 2015 at 7:57 am
Hi Mohamed, I took a look and it’s your reference to jQuery that’s not working. Here’s a working example of your code https://jsfiddle.net/euzdf2jb/1/. All I did was change the jQuery reference to 2.1.0 in the sidebar.
You can find a copy of jQuery to reference here: http://code.jquery.com/jquery-2.1.0.min.js
JP
April 10, 2015 at 9:38 am
Juste Thx, This tuto is really helpfull 🙂
Laurel
April 9, 2015 at 6:11 pm
Is there a way to have a border around the active tab and content area? I am trying to play around with the code now to figure it out..but I feel like this could have a simple solution and I am making it much more complicated than it needs to be!
Thanks!
Seb Kay (Author)
April 10, 2015 at 2:02 pm
The best way to achieve that would be a border on the left, top and right of the tab link and the right, bottom and left of the content area.
Mahendra Kralot
April 8, 2015 at 5:13 pm
Can You help me, my tabs are not switching. Just displaying tab1.
Seb Kay (Author)
April 10, 2015 at 2:03 pm
It sounds like a problem with the jQuery. Can you double check to make sure you’re including jQuery properly?
Dwayne Barsotta
April 8, 2015 at 9:33 am
I really enjoy this tutorial. Unfortunately I read it at 3:30am from bed. I can’t wait to try it on my site, thank you very much.
Ishmael
April 4, 2015 at 2:36 am
i tried everything so far and not sure what i am missing ive been working on a project for school and i had to leave that alone because something wasn’t working and now i try this one and it almost works not sure what i am missing and unless maybe you can help me with my old website maybe I wouldnt have to start over
Mark
April 1, 2015 at 10:12 am
Wow!! This is so helpful! This is a good guide for beginners like me!
stephan
March 31, 2015 at 9:03 am
I used ur tab example, which is great, and i modified it to my needings and all works perfectly. But: i want to jump from another page to a specified tab (Home -> tab5) which is pretty easy by putting the id at the end of the link, the problem is that since .tab is set to display:none you cant jump to them.
What other display settings are similar to yours so the jumps work again? I tried different settings in the css but somehow i just mess it up everytime i try to fix it.
Kim
March 30, 2015 at 7:38 pm
Hi,
It may be how my website is set up, but I am using SharePoint, and there is a big indent before where the tabs start in comparison to the content below. I can’t seem to figure out where to adjust that.
Nic
March 29, 2015 at 11:24 pm
Hey, when I try to add this code into my website, it just ” remove ” the content, it shows me a blank page with nothing in it. but when i remove the balisa it shows back the page.
Any suggestion ?
Seb Kay (Author)
March 30, 2015 at 9:51 am
Can you post the full code to JSFiddle for me to look at? It may be a syntax error causing the page to be removed instead of the tabs content.
Nic
March 30, 2015 at 2:49 pm
here’s the contact.php code:
the footer:
the header:
the CSS :
and the Javascript:
I just copied the code ( sorry about that. )
nic
March 30, 2015 at 3:16 pm
Never mind, i just found out about the little ” l ” at the end of the code. But now, the tabs are separeted from the actual tabs with the content. Gonna work on that! Thanks !
Once again, this code is pretty nice, good tutorial. I’m kinda starting in the buisness, and tutorials like this helps a lot.
Have a good day !
Tashfin
March 27, 2015 at 10:21 am
Hey,
I was wondering if I could have the files for the html, CSS and JQuery?
Seb Kay (Author)
March 30, 2015 at 9:50 am
I’ll see what I can do about packaging it up into a ZIP folder for you 🙂
mishtu
March 23, 2015 at 1:53 am
hi,
Thank you for the code. I am using squarespace to build my company’s website. I used the HTML and the CSS you have provided and I can see the tabs on my website. However, tab 1 is always highlighted with the content under it visible. I am unable to toggle to tab 2 and tab 3 🙁
Please could you guide me to make this work.
thanks
Mishtu
Seb Kay (Author)
March 23, 2015 at 9:07 am
Hey mishtu, can you give me an example of your code using JSFiddle? That way I can take a look and analyse the problem.
arnold subastil
March 30, 2015 at 7:06 am
It’s because of the jquery issue on line 6.
you have to remove the ‘.tabs’ .
Seb Kay (Author)
March 30, 2015 at 9:52 am
Thanks for helping out Arnold.
Mishtu, did his suggestion work for you?
einverne
March 20, 2015 at 1:03 pm
Great tutorial~ Thanks
peyman
March 14, 2015 at 2:24 am
very good tutorial + very good and simple explain.
thank u
DanelerH
March 13, 2015 at 4:35 am
Hello. I tried out the code and it works great. I was able to get it working almost perfectly. There’s just one problem: as you can see in the demo, you have a blue background and the tab content is in a white box. In my case, I have a background image with the tab’s content box covering a large chunk of it. I was wondering if there was a way to remove it. Thank you.
DanelerH
March 13, 2015 at 5:13 am
Nevermind. It appears that I figured it out. I just went into the CSS file and changed the color to “transparent”. Why I didn’t try that earlier, I’ll never know. Anyways, thank you for the code.
Rebecca
March 11, 2015 at 7:50 pm
I just love when there are running examples for any tutorial. It helps me understand what the code is doing. Easy to understand and quick to implement. The only issue was that I did not get the lines for the top and right side of the tab content. Maybe its something I did wrong. Good Work!!
Seb Kay (Author)
March 12, 2015 at 9:48 am
I’m really happy to hear the demo helped!
If you post your code over on JSFiddle I’d be happy to take a look 🙂
Nhoward
March 11, 2015 at 2:05 pm
It would be REALLY helpful if there were a step by step on how to implement this.
For instance, do I simply copy the HTML and paste it into my site and that’s it, or do I need to also do something with the CSS and if so what specifically do I need to do?
Seb Kay (Author)
March 12, 2015 at 9:47 am
You need to implement the HTML, CSS and jQuery which all work together to create the tabs effect. If you’re unfamiliar with the process of using CSS and jQuery, along with HTML, I highly suggest you check out this intro on the jQuery website before getting too deep into tutorials such as this one.
Djeneba
March 10, 2015 at 3:56 pm
Hello Seb,
Thank you so much for this tutorial, this is exactly what I was looking for. It’s so easy to understand it. I look forward to reading your other tutorial.
Best regards.
Seb Kay (Author)
March 10, 2015 at 4:05 pm
No problem at all, I’m glad to be of help!
Jesse
March 9, 2015 at 9:09 pm
Thanks for the quick and easy to understand tutorial. It took me no time to implement your code and understand what I was doing with it. I don’t consider myself a complete beginner, but I’m definitely still learning a lot of concepts that many web developers would probably call elementary. Your tutorial taught me something new and allowed me to create a web page I wouldn’t have been able to on my own, so many thanks!
I did have one issue though, which I figured out. And maybe it was something I did wrong, but I thought I’d mention it anyway. After copying your code my UL element had a 16px margin that caused the tabs to be separated from the content body. I found this to be the case in any browser. I fixed it by just adding this to the CSS:
.tabs ul{margin:0px;}
Thanks again!
Seb Kay (Author)
March 10, 2015 at 8:24 am
Hey Jesse,
Good call and well done for figuring it out. I actually left out that I used a CSS reset when I created this as the main point of the tutorial is the jQuery code. I’ll make sure to explain this in future tutorials, thanks for pointing it out though. I really appreciate the feedback!
Ankur
March 2, 2015 at 6:13 am
Hello there,great tutorial for a beginner like me.its really perfect for learning a new thing whwn compared to other tutorials on the web.Looking for more….!