| You are here : : Home > Free Resources > CSS Tutorials > CSS & jQuery Content Box with Tabs |
Free Web Design Resources
Other Web Design Resources
In this tutorial, you will learn how to create a tabbed content box using CSS and jQuery. You can also download the source code at the end of the tutorial.

Call of Duty: Black Ops bears the series' standard superbly,
delivering an engrossing campaign and exciting competitive multiplayer.

Mortal Kombat returns after a lengthy hiatus and puts players
back into the Tournament for 2D fighting with gruesome combat and fatalities.

Halo: Reach is the culmination of the superlative combat, sensational multiplayer, and seamless online integration that are the hallmarks of this superb series.

Portal 2 is an action shooter game from Valve Software that draws from the original formula of innovative gameplay, story, and music, which earned the original Portal more than 70 industry accolades.
| Browser Support | » | ![]() |
![]() |
![]() |
![]() |
|---|---|---|---|---|---|
| Language | » | CSS2, HTML4 & jQuery | |||
| Difficulty | » | Beginner | |||
| Estimated Completion Time | » | 15 minutes | |||
<head> tags. 1 2 3 4 5
<head>
<script type="text/javascript" src="jquery-1.5.2.min.js" ></script>
</head>
src attribute to the script tag.src attribute to "http://ajax.googleapis.com/
ajax/libs/jquery/1.4.2/jquery.min.js";
1 2 3 4 5 6 7
<head>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>
</head>
<ul> tag for creating the Menu Tab, and <li> tags for creating the Menu Tab Labels. class="tabs" for this <ul> tag.<li> element a rel attribute. This rel stands for Relationship. rel attributes value using jQuery.
<li> item have different rel value. We will use these rel attributes values to relate them to their contents.<li> item has a class="active", to make it the default active tab when someone opens the webpage.
1 2 3 4 5 6 7 8
<ul class="tabs">
<li class="active" rel="tab1"> Call of Duty</li>
<li rel="tab2"> Mortal Combat</li>
<li rel="tab3"> Halo</li>
<li rel="tab4"> Portal</li>
</ul>
<div> element with class="tab_container".<div class="tab_container"> will contain all the contents related to the Menu Tab in seperate <div> .id value equal to the rel value of the Menu Tab Item to which it is related.class="tab_content".
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
<div class="tab_container">
<div id="tab1" class="tab_content">
<p><img src="images/cod.jpg"> <br />
<strong>
Call of Duty: Black Ops bears the series' standard superbly,
delivering an engrossing campaign and exciting competitive multiplayer.
</strong>
</p>
</div><!-- #tab1 -->
<div id="tab2" class="tab_content">
<p><img src="images/mortal combat.jpg"> <br />
<strong>
Mortal Kombat returns after a lengthy hiatus and puts players
back into the Tournament for 2D fighting with gruesome combat.
</strong>
</p>
</div><!-- #tab2 -->
<div id="tab3" class="tab_content">
<p><img src="images/halo.jpg"> <br />
<strong>
Halo: Reach is the culmination of the superlative combat, sensational
multiplayer, and seamless online integration that are the hallmarks
of this superb series.
</strong>
</p>
</div><!-- #tab3 -->
<div id="tab4" class="tab_content">
<p><img src="images/portal.jpg"> <br />
<strong>
Portal 2 is an action shooter game from Valve Software that draws
from the original formula of innovative gameplay, story, and music,
which earned the original Portal more than 70 industry accolades.
</strong>
</p>
</div><!-- #tab4 -->
</div> <!-- .tab_container -->
<li> item will be highlighted when a mouse is hovered on it.display:none; property applied on the class="tab_content".
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
<style type="text/css"> ul.tabs { margin: 0; padding: 0; float: left; list-style: none; height: 32px; border-bottom: 1px solid #999999; border-left: 1px solid #999999; width: 100%; } ul.tabs li { float: left; margin: 0; cursor: pointer; padding: 0px 21px ; height: 31px; line-height: 31px; border: 1px solid #999999; border-left: none; font-weight: bold; background: #EEEEEE; overflow: hidden; position: relative; } ul.tabs li:hover { background: #CCCCCC; } ul.tabs li.active{ background: #FFFFFF; border-bottom: 1px solid #FFFFFF; } .tab_container { border: 1px solid #999999; border-top: none; clear: both; float: left; width: 100%; background: #FFFFFF; } .tab_content { padding: 20px; font-size: 1.2em; display: none; } </style>
<li> Menu Tab element and take the value of it's rel attribute and display the <div> whose id value matches the rel value of the Menu Tab Item.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<script type="text/javascript"> $(document).ready(function() { $(".tab_content").hide(); $(".tab_content:first").show(); $("ul.tabs li").click(function() { $("ul.tabs li").removeClass("active"); $(this).addClass("active"); $(".tab_content").hide(); var activeTab = $(this).attr("rel"); $("#"+activeTab).fadeIn(); }); }); </script>
<div> elements with class="tab_content". <div class="tab_content"> active Tab Content, by default. <li> items. class="active" from the previous Active Menu Tab. class="active" to the current clicked <li> Menu Tab Item. <div> with class="tab_content". rel attribute from the current clicked <li> Menu Tab Item to the activeTab variable. <div> whose id value matches the rel value of the current Active <li> Menu Tab Item. Join us on Facebook to keep updated with all the latest tutorials and web design freebies from EntheosWeb!
No portion of these materials may be reproduced in any manner whatsoever, without the express written consent of Entheos. Any unauthorized use, sharing, reproduction or distribution of these materials by any means, electronic, mechanical, or otherwise is strictly prohibited.