Using JQuery tabs in an HTML 5 page

In this post I will show you how to create a simple tabbed interface using JQuery,HTML 5 and CSS.

Make sure you have downloaded the latest version of JQuery (minified version) from

Please find here all my posts regarding JQuery.Also have a look at my posts regarding HTML 5.

In order to be absolutely clear this is not (and could not be) a detailed tutorial on HTML 5. There are other great resources for that.Navigate to the excellent interactive tutorials of W3School.

Another excellent resource is HTML 5 Doctor.

Two very nice sites that show you what features and specifications are implemented by various browsers and their versions are and At this times Chrome seems to support most of HTML 5 specifications.Another excellent way to find out if the browser supports HTML 5 and CSS 3 features is to use the Javascript lightweight library Modernizr.

In this hands-on example I will be using Expression Web 4.0.This application is not a free application. You can use any HTML editor you like.You can use Visual Studio 2012 Express edition. You can download it here. 

Let me move on to the actual example.

This is the sample HTML 5 page

<!DOCTYPE html>
<html lang="en">
    <title>Liverpool Legends</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
    <link rel="stylesheet" type="text/css" href="style.css">
    <script type="text/javascript" src="jquery-1.8.2.min.js"> </script>
     <script type="text/javascript" src="tabs.js"></script>
        <h1>Liverpool Legends</h1>
    <section id="tabs">
            <li><a href="§ionid=1153&postid=9143136#first-tab">Defenders</a></li>
            <li><a href="§ionid=1153&postid=9143136#second-tab">Midfielders</a></li>
            <li><a href="§ionid=1153&postid=9143136#third-tab">Strikers</a></li>
   <div id="first-tab">
     <h3>Liverpool Defenders</h3>
     <p> The best defenders that played for Liverpool are Jamie Carragher, Sami Hyypia , Ron Yeats and Alan Hansen.</p>
   <div id="second-tab">
     <h3>Liverpool Midfielders</h3>
     <p> The best midfielders that played for Liverpool are Kenny Dalglish, John Barnes,Ian Callaghan,Steven Gerrard and Jan Molby.
   <div id="third-tab">
     <h3>Liverpool Strikers</h3>
     <p>The best strikers that played for Liverpool are Ian Rush,Roger Hunt,Robbie Fowler and Fernando Torres.<br/>


    <p>All Rights Reserved</p>

This is very simple HTML markup. 

I have styled this markup using CSS.

The contents of the style.css file follow

* {
    margin: 0;
    padding: 0;




#tabs {
    font-size: 0.9em;
    margin: 20px 0;
#tabs ul {
    float: left;
    background: #777;
    width: 260px;
    padding-top: 24px;

#tabs li {
    margin-left: 8px;
    list-style: none;
* html #tabs li {
    display: inline;
#tabs li, #tabs li a {
    float: left;
#tabs ul {
    border-top:2px red solid;
    background: #15ADFF;
#tabs ul a {
    color: #333333;
#tabs div {
    background: #15ADFF;
    clear: both;
    padding: 15px;
    min-height: 200px;
#tabs div h3 {
    margin-bottom: 12px;
#tabs div p {
    line-height: 26px;
#tabs ul li a {
    text-decoration: none;
    padding: 8px;
    font-weight: bold;


There are some CSS rules that style the various elements in the HTML 5 file. These are straight-forward rules.

The JQuery code lives inside the tabs.js file

$('#tabs div').hide();
$('#tabs div:first').show();
$('#tabs ul li:first').addClass('active');
$('#tabs ul li a').click(function(){
$('#tabs ul li').removeClass('active');
var currentTab = $(this).attr('href');
$('#tabs div').hide();
return false;

I am using some of the most commonly used JQuery functions like hide , show, addclass , removeClass

I hide and show the tabs when the tab becomes the active tab.

When I view my page I get the following result


Hope it helps!!!!!

1 Comment

Comments have been disabled for this content.