Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

Dynamic Tab Panel using only HTML and CSS

This tutorial will guide you with easy code to create your own compact and lightweight version of Tabbed panel which work perfectly well. If you don’t know JavaScript not a problem all you need is HTML and CSS know how and you are good to go.


This tutorial is a very short and comprehensive. In this tutorial we will Make a Tab-Content switching system with only html and css. We won’t be using any JavaScript in this case. However if you are looking something similar to do with Angular JS you can check out this tutorial here: Dynamic Tab Switch Control with AngularJS.

In this tutorials as we mention there is no JavaScript used, so it is quick easy and lightweight. So for a start let us make the tabs and content section to map them. To make the tabs we are going to use the radio buttons and labels.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!doctype html>
<html>
<head>
<title>Tabs Demo</title>
<link rel="stylesheet" href="tabs.css" >
</head>
<body>
<input type="radio" name="tabs" id="tab1" checked="checked">
<label for="tab1">Hello World</label>
<input type="radio" name="tabs" id="tab2">
<label for="tab2">Hello World 2</label>
<input type="radio" name="tabs" id="tab3">
<label for="tab3">Hello World 3</label>
<input type="radio" name="tabs" id="tab4">
<label for="tab4">Hello World 4</label>
<input type="radio" name="tabs" id="tab5">
<label for="tab5">Hello World 5</label>
<div id="tab-content1" class="tab-content">
<h2>Tab Content 1</h2>
<p></p>
</div>
<div id="tab-content2" class="tab-content">
<h2>Tab Content 2</h2>
<p></p>
</div>
<div id="tab-content3" class="tab-content">
<h2>Tab Content 3</h2>
<p></p>
</div>
<div id="tab-content4" class="tab-content">
<h2>Tab Content 4</h2>
<p></p>
</div>
<div id="tab-content5" class="tab-content">
<h2>Tab Content 5</h2>
<p></p>
</div>
</body>
</html>
<!doctype html> <html> <head> <title>Tabs Demo</title> <link rel="stylesheet" href="tabs.css" > </head> <body> <input type="radio" name="tabs" id="tab1" checked="checked"> <label for="tab1">Hello World</label> <input type="radio" name="tabs" id="tab2"> <label for="tab2">Hello World 2</label> <input type="radio" name="tabs" id="tab3"> <label for="tab3">Hello World 3</label> <input type="radio" name="tabs" id="tab4"> <label for="tab4">Hello World 4</label> <input type="radio" name="tabs" id="tab5"> <label for="tab5">Hello World 5</label> <div id="tab-content1" class="tab-content"> <h2>Tab Content 1</h2> <p></p> </div> <div id="tab-content2" class="tab-content"> <h2>Tab Content 2</h2> <p></p> </div> <div id="tab-content3" class="tab-content"> <h2>Tab Content 3</h2> <p></p> </div> <div id="tab-content4" class="tab-content"> <h2>Tab Content 4</h2> <p></p> </div> <div id="tab-content5" class="tab-content"> <h2>Tab Content 5</h2> <p></p> </div> </body> </html>
<!doctype html>
<html>
	<head>
		<title>Tabs Demo</title>
		<link rel="stylesheet" href="tabs.css" >
	</head>
	<body>
		<input type="radio" name="tabs" id="tab1" checked="checked">
		<label for="tab1">Hello World</label>
		<input type="radio" name="tabs" id="tab2">
		<label for="tab2">Hello World 2</label>
		<input type="radio" name="tabs" id="tab3">
		<label for="tab3">Hello World 3</label>
		<input type="radio" name="tabs" id="tab4">
		<label for="tab4">Hello World 4</label>
		<input type="radio" name="tabs" id="tab5">
		<label for="tab5">Hello World 5</label>
		<div id="tab-content1" class="tab-content">
			<h2>Tab Content 1</h2>
			<p></p>
		</div>
		<div id="tab-content2" class="tab-content">
			<h2>Tab Content 2</h2>
			<p></p>
		</div>
		<div id="tab-content3" class="tab-content">
			<h2>Tab Content 3</h2>
			<p></p>
		</div>
		<div id="tab-content4" class="tab-content">
			<h2>Tab Content 4</h2>
			<p></p>
		</div>
		<div id="tab-content5" class="tab-content">
			<h2>Tab Content 5</h2>
			<p></p>
		</div>
	</body>
</html>

As you can see we have used radio and label, this way when we hide the radio the label will act as the Tab however underlying radio button will remain in operation. We have assigned the Id to each radio so that we can bind this id to a specific tab content div which we use for displaying content for the currently active tab.

The Stage is set all we need is a little design and CSS as logic to work our tabs and content switching. We use following CSS.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
body{
background:#9accc8;
padding:25px;
width:90%;
margin:0 auto;
font-family:arial;
}
input[name=tabs]{
display:none;
}
input[name=tabs] + label{
padding:5px;
background:#00A886;
border-radius:5px;
color:white;
}
input[name=tabs]:checked + label{
font-weight:bold;
border:solid 2px #fff;
}
.tab-content{
display:none;
}
#tab1:checked ~ #tab-content1, #tab2:checked ~ #tab-content2, #tab3:checked ~ #tab-content3, #tab4:checked ~ #tab-content4, #tab5:checked ~ #tab-content5 {
display:block;
}
body{ background:#9accc8; padding:25px; width:90%; margin:0 auto; font-family:arial; } input[name=tabs]{ display:none; } input[name=tabs] + label{ padding:5px; background:#00A886; border-radius:5px; color:white; } input[name=tabs]:checked + label{ font-weight:bold; border:solid 2px #fff; } .tab-content{ display:none; } #tab1:checked ~ #tab-content1, #tab2:checked ~ #tab-content2, #tab3:checked ~ #tab-content3, #tab4:checked ~ #tab-content4, #tab5:checked ~ #tab-content5 { display:block; }
body{
	background:#9accc8;
	padding:25px;
	width:90%;
	margin:0 auto;
	font-family:arial;
}



input[name=tabs]{
	display:none;
}

input[name=tabs] + label{
	padding:5px;
	background:#00A886;
	border-radius:5px;
	color:white;
	
}

input[name=tabs]:checked + label{
	font-weight:bold;
	border:solid 2px #fff;
}

.tab-content{
	display:none;
}

#tab1:checked ~ #tab-content1, #tab2:checked ~ #tab-content2,  #tab3:checked ~ #tab-content3, #tab4:checked ~ #tab-content4, #tab5:checked ~ #tab-content5 {
	display:block;
}

The body is nothing but style to the body, then We have hidden the radio buttons so that Labels can take the spot, added some colors to label, and we are using “:checked” property for checking which tab to display active and which content to show, at last hidden all the content bodies and mapped the radio button to the corresponding content body so that when one radio is checked the corresponding body is displayed.

You can check out the live demo here: Dynamic Tabs using CSS Demo

Buy Me A Coffee
If you find my content helpful, please consider supporting me!