How to Create Vertical tabs in HTML

How to Create Vertical tabs in HTML. The Vertical Tabs element works as a container to show groups of content, sorted into tabs. Each tab label should compare with a block of related content. Only one tab’s contents are visible at any given time.

This element differs from the regular ‘tabs’ element, with the tabs organized on the left in a vertical space, instead of on the top in a horizontal space.

So, let’s begin.

How to Create Vertical tabs in HTML

HTML Code:

<h2>Vertical Tabs</h2>
<div class="softtab">
  <button class="tabcodeon" onclick="openCity(event, 'Pakistan')" id="defaultOpen">Pakistan</button>
    <button class="tabcodeon" onclick="openCity(event, 'Islamabad')">Islamabad</button>
  <button class="tabcodeon" onclick="openCity(event, 'Punjab')">Punjab</button>
  <button class="tabcodeon" onclick="openCity(event, 'Faislabad')">Faislabad</button>
<div id="Pakistan" class="softtabcontent">
  <p>Pakistan, officially the Islamic Republic of Pakistan, is a country in South Asia. It is the world's fifth-most populous country with a population exceeding 212.2 million. By area, it is the 33rd-largest country, spanning 881,913 square kilometres.</p>
<div id="Islamabad" class="softtabcontent">
  <p>Islamabad is the capital city of Pakistan, and is federally administered as part of the Islamabad Capital Territory. Islamabad is the ninth largest city in Pakistan, while the larger Islamabad-Rawalpindi metropolitan area is the country's fourth largest with a population of about 7.4 million.</p> 
<div id="Punjab" class="softtabcontent">
  <p>Punjab is Pakistan's most populous province, with an estimated population of 110,012,442 as of 2017. Forming the bulk of the transnational Punjab region, it is bordered by the Pakistani provinces of Sindh, Balochistan, and Khyber Pakhtunkhwa, the enclave of Islamabad, and Azad Kashmir.</p> 
<div id="Faislabad" class="softtabcontent">
  <p>Faisalabad, formerly known as Lyallpur, is the third-most-populous city in Pakistan, and the second-largest in the eastern province of Punjab. Historically one of the first planned cities within British India, it has long since developed into a cosmopolitan metropolis.</p>

CSS Code:

Read Also: How to Create Pagination using HTML and CSS

body {font-family: Arial;}
.softtab {
  overflow: hidden;
  border: 1px solid #fff;
  background-color: #ab1d72;
.softtab button {
  background-color: inherit;
  float: left;
  border: none;
  outline: none;
  cursor: pointer;
  padding: 14px 16px;
  transition: 0.3s;
  font-size: 17px;
.softtab button:hover {
  background-color: #5d1c80;
.softtabcontent {
  display: none;
  padding: 6px 12px;
  border: 1px solid #ccc;
  border-top: none;

Javascript Code:

Read Also: How to Create a fixed Social Media Sidebar

function openCity(evt, cityName) {
  var i, softtabcontent, tabcodeon;
  softtabcontent = document.getElementsByClassName("softtabcontent");
  for (i = 0; i < softtabcontent.length; i++) {
    softtabcontent[i].style.display = "none";
  tabcodeon = document.getElementsByClassName("tabcodeon");
  for (i = 0; i < tabcodeon.length; i++) {
    tabcodeon[i].className = tabcodeon[i].className.replace(" active", "");
  document.getElementById(cityName).style.display = "block";
  evt.currentTarget.className += " active";

In this tutorial, we’ve to design Vertical Tabs by using HTML, CSS, and a bit of Javascript.

Have a nice day.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top