In this article, you will learn how to add tabs to your Blogger website. When you have multiple sections within the same topic, you can either display them one after another or organize them into tabs. This approach allows you to present your information in a more organized manner, enhancing user experience and engagement on your website.
This tab is designed using simple HTML, CSS, and JavaScript code, making it compatible with Blogger, WordPress, or any other platform.
So, let’s check how you can add a simple tab section to your Blogger blog post.
To add tabs to your Blogger post, log in to your Blogger dashboard and paste the following code into the HTML section. Ensure you copy all the HTML, CSS, and JavaScript code.
<div class="tabs">
<button class="tablinks" onclick="openTab(event, 'tab1')">Tab 1</button>
<button class="tablinks" onclick="openTab(event, 'tab2')">Tab 2</button>
<button class="tablinks" onclick="openTab(event, 'tab3')">Tab 3</button>
</div>
<div id="tab1" class="tab-content active">
<h2>Tab 1 Content</h2>
<p>This is the content of Tab 1.</p>
<p>Technology is not just a tool. It can give learners a voice that they may not have had before.</p>
<img src="https://images.pexels.com/photos/356056/pexels-photo-356056.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" alt="Image 1">
</div>
<div id="tab2" class="tab-content ">
<h2>Tab 2 Content</h2>
<p>This is the content of Tab 2.</p>
<p>Technology is best when it brings people together.</p>
<img src="https://images.pexels.com/photos/123335/pexels-photo-123335.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" alt="Image 2">
</div>
<div id="tab3" class="tab-content">
<h2>Tab 3 Content</h2>
<p>This is the content of Tab 3.</p>
<p>The true sign of intelligence is not knowledge but imagination.</p>
<img src="https://images.pexels.com/photos/256381/pexels-photo-256381.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" alt="Image 3">
<
.tabs {
display: flex;
}
.tablinks {
background-color: #f2f2f2;
color: black;
border: none;
outline: none;
cursor: pointer;
padding: 10px 20px;
margin: 2px;
font-size: 16px;
transition: background-color 0.3s;
flex: auto;
}
.tablinks:hover {
background-color: #ddd;
}
.tab-content {
display: none;
padding: 20px;
border-top: 2px solid #ccc;
font-size: 19px;
}
.active {
display: block;
}
<script>
function openTab(evt, tabName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tab-content");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(tabName).style.display = "block";
evt.currentTarget.className += " active";
}
</script>
Here, you can notice that we have added three tab sections with three buttons, each corresponding to a tab with its unique ID like tab1, tab2, and tab3.
If you want to add more tabs, you need to create a new button element along with its div section, assigning it a unique ID like tab4.
Once you add the three code sections in the HTML, go ahead and change its content. You can put any content inside the tabs, such as headings, paragraphs, images, blockquotes, code boxes, etc. As seen in the above section, I have included a code box along with a paragraph in the tab section.
After adding the three code sections, publish the page. You will have successfully added a tab section to your Blogger website. If you still have doubts, feel free to ask me in the comment section.

Post a Comment