CSS Tabs
A comprehensive guide to creating a fully functional tabbed structure with just HTML and CSS.
Tabs are one of the most frequently used HTML component, across a variety of web applications in infinite fashions.
What are HTML tabs?
HTML Tabs are most simplest system of focusing a content based on a specific title. We can simply swap the descriptive/explanatory content when we focus on a title. It can be made to slide or show/hide depending on our necessity.
To create a simple tabbed structure, we need to use a combination of HTML, CSS and Js. To see that example , please check the link here.
Here we are going to learn about creating a tab without using Js.
Tab with simple HTML and CSS
Radio buttons are awesome but used maily in forms. Lets make use of radio buttons to make tabs.
HTML
I created a simple HTML sructure with radio buttons and the contents inside the same parent container.
<div class="simple-tab">
<div>
<input type="radio" id="tab1" name="tab" value="tab1" checked>
<label for="tab1">Ipsos nosse</label>
<input type="radio" id="tab2" name="tab" value="tab2">
<label for="tab2">Illa videamus</label>
<input type="radio" id="tab3" name="tab" value="tab3">
<label for="tab3">Quis est tam</label>
<span>
<h4>Tab content 1</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Hic nihil fuit, quod quaereremus. Aliter enim nosmet ipsos
nosse non possumus. Duo Reges: constructio interrete. Sed haec
nihil sane ad rem; </p>
</span>
<span>
<h4>Tab content 2</h4>
<p>Nunc omni virtuti vitium contrario nomine opponitur. Sed ille,
ut dixi, vitiose. Quae cum essent dicta, discessimus. </p>
<p>Illi enim inter se dissentiunt. Invidiosum nomen est, infame,
suspectum. Quae contraria sunt his, malane? Illa videamus, quae a
te de amicitia dicta sunt. Tubulo putas dicere? Pauca mutat vel plura
sane; </p>
</span>
<span>
<h4>Tab content 3</h4>
<p>Disserendi artem nullam habuit. Reguli reiciendam; Illi enim
inter se dissentiunt. Si quae forte-possumus. Quis est tam dissimile
homini. </p>
<p>Sint modo partes vitae beatae. Sic consequentibus vestris
sublatis prima tolluntur. Aperiendum est igitur, quid sit voluptas;
Quid adiuvas? </p>
</span>
</div>
</div>
CSS
The CSS plays the main part here. We will make use of the ~ selector to reference items in relative to the checked radio buttons.
So that once a radio button is checked, it will trigger the relative content. Below is the entire css that could create the tab functionality.
This will give you the exact tab functionality.
Demo
or the demo can be found in the link below.
Demo .
Thank you reading it.
Last updated
Was this helpful?