JSFiddle - React, Tailwind, and code Playground
HTML
<div class="tab">
<img class="tablinks active" data-id="London" src="https://i.ytimg.com/vi/SfLV8hD7zX4/maxresdefault.jpg">
<li><a href="#" class="tablinks" data-id="Paris">Paris</a></li>
<li><a href="#" class="tablinks" data-id="Tokyo">Tokyo</a></li>
</div>
<div id="London" class="tabcontent">
<h3>London</h3>
<p>London is the capital city of England.</p>
</div>
<div id="Paris" class="tabcontent">
<h3>Paris</h3>
<p>Paris is the capital of France.</p>
</div>
<div id="Tokyo" class="tabcontent">
<h3>Tokyo</h3>
<p>Tokyo is the capital of Japan.</p>
</div>
<ul class="tab">
<li><a href="#" class="tablinks active" data-id="Warsaw">Warsaw</a></li>
<li><a href="#" class="tablinks" data-id="Copenhagen">Copenhagen</a></li>
<li><a href="#" class="tablinks" data-id="Moscow">Moscow</a></li>
</ul>
<div id="Warsaw" class="tabcontent">
<h3>Warsaw</h3>
<p>Warsaw is the capital city of Poland.</p>
</div>
<div id="Copenhagen" class="tabcontent">
<h3>Copenhagen</h3>
<p>Copenhagen is the capital of Denmark.</p>
</div>
<div id="Moscow" class="tabcontent">
<h3>Moscow</h3>
<p>Moscow is the capital of Russia.</p>
</div>
CSS
ul.tab {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
/* Float the list items side by side */
ul.tab li {float: left;}
/* Style the links inside the list items */
ul.tab li a {
display: inline-block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
transition: 0.3s;
font-size: 17px;
}
/* Change background color of links on hover */
ul.tab li a:hover {
background-color: #ddd;
}
/* Create an active/current tablink class */
ul.tab li a:focus, .active {
background-color: #ccc;
}
/* Style the tab content */
.tabcontent {
display: none;
padding: 6px 12px;
-webkit-animation: fadeEffect 1s;
animation: fadeEffect 1s;
}
@-webkit-keyframes fadeEffect {
from {opacity: 0;}
to {opacity: 1;}
}
@keyframes fadeEffect {
from {opacity: 0;}
to {opacity: 1;}
}
JavaScript
$('.tablinks.active').each(function(){
$($(this).data('id')).show();
});
$('.tablinks').click(function(){
$('.tabcontent').hide();
$('.tablinks').removeClass("active");
$('#'+$(this).addClass("active").data('id')).show();
});