<div class="tabs-container">
<div class="tab-buttons">
<button class="tab-button active" data-tab="tab1">Tab 1</button>
<button class="tab-button" data-tab="tab2">Tab 2</button>
<button class="tab-button" data-tab="tab3">Tab 3</button>
</div>
<div class="tab-content active" id="tab1">
<p>Content for Tab 1. This is the initially visible tab content.</p>
</div>
<div class="tab-content" id="tab2">
<p>Content for Tab 2. This section becomes visible when Tab 2 is clicked.</p>
</div>
<div class="tab-content" id="tab3">
<p>Content for Tab 3. Each tab can hold different information.</p>
</div>
</div>body {
font-family: Arial, sans-serif;
padding: 20px;
background-color: #f9f9f9;
display: flex; justify-content: center; align-items: center; min-height:100vh;
}
.tabs-container {
max-width: 600px;
width: 100%;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
overflow: hidden;
}
.tab-buttons {
display: flex;
background-color: #eef2f5;
}
.tab-button {
padding: 15px 20px;
cursor: pointer;
border: none;
background-color: transparent;
font-size: 1em;
color: #555;
transition: background-color 0.3s, color 0.3s;
flex-grow: 1; /* Distribute space equally */
text-align: center;
border-bottom: 3px solid transparent;
}
.tab-button:hover {
background-color: #dfe6eb;
color: #333;
}
.tab-button.active {
color: #007bff;
border-bottom: 3px solid #007bff;
font-weight: bold;
}
.tab-content {
display: none;
padding: 20px;
line-height: 1.6;
color: #333;
animation: fadeInContent 0.5s ease;
}
.tab-content.active {
display: block;
}
@keyframes fadeInContent {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}document.addEventListener('DOMContentLoaded', function() {
const tabButtons = document.querySelectorAll('.tab-button');
const tabContents = document.querySelectorAll('.tab-content');
tabButtons.forEach(button => {
button.addEventListener('click', () => {
// Remove active class from all buttons and contents
tabButtons.forEach(btn => btn.classList.remove('active'));
tabContents.forEach(content => content.classList.remove('active'));
// Add active class to the clicked button and corresponding content
button.classList.add('active');
const tabId = button.getAttribute('data-tab');
document.getElementById(tabId).classList.add('active');
});
});
});Nothing to show yetType HTML, CSS or JavaScript and your page appears here.
Click any element to find its code Esc
Check this code before you run it
It came from a shared link. It runs with fewer permissions, so it cannot open pop-ups, submit forms or start downloads.
0.00s / 0.00s
Nothing has animated yet. Hover, click or type in the preview and each CSS animation, transition or
element.animate() call shows up here as it plays.