A modern, responsive tabbed interface with smooth transitions
<head>
.This is the home tab content. You can put any content here.
This is the profile tab content. User information would go here.
This is the settings tab content. Configuration options would go here.
<!-- Font Awesome Icons; Make sure to add it in the <head> tag -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<div class="tabs-container">
<div class="tabs">
<button class="tab-btn active" data-tab="tab1">
<i class="fas fa-home"></i>
<span>Home</span>
</button>
<button class="tab-btn" data-tab="tab2">
<i class="fas fa-user"></i>
<span>Profile</span>
</button>
<button class="tab-btn" data-tab="tab3">
<i class="fas fa-cog"></i>
<span>Settings</span>
</button>
</div>
<div class="tab-content-container">
<div class="tab-content active" id="tab1">
<h3>Home Tab</h3>
<p>This is the home tab content. You can put any content here.</p>
</div>
<div class="tab-content" id="tab2">
<h3>Profile Tab</h3>
<p>This is the profile tab content. User information would go here.</p>
</div>
<div class="tab-content" id="tab3">
<h3>Settings Tab</h3>
<p>This is the settings tab content. Configuration options would go here.</p>
</div>
</div>
</div>
.tabs-container {
max-width: 600px;
margin: 0 auto;
font-family: var(--font-family, 'Arial, sans-serif');
}
.tabs {
display: flex;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
margin-bottom: 20px;
position: relative;
}
.tab-btn {
padding: 12px 20px;
background: none;
border: none;
cursor: pointer;
font-weight: 500;
color: #666;
display: flex;
align-items: center;
gap: 8px;
transition: all 0.3s ease;
position: relative;
flex: 1;
justify-content: center;
}
.tab-btn i {
font-size: 16px;
}
.tab-btn:hover {
color: #2575fc;
}
.tab-btn.active {
color: #2575fc;
}
.tab-btn.active::after {
content: '';
position: absolute;
bottom: -1px;
left: 0;
width: 100%;
height: 3px;
background: #2575fc;
border-radius: 3px 3px 0 0;
animation: slide-in 0.3s ease-out;
}
.tab-content-container {
position: relative;
min-height: 150px;
}
.tab-content {
opacity: 0;
visibility: hidden;
position: absolute;
width: 100%;
transform: translateY(10px);
transition: opacity 0.3s ease, transform 0.3s ease, visibility 0s 0.3s;
padding: 15px;
border-radius: 5px;
}
.tab-content.active {
opacity: 1;
visibility: visible;
transform: translateY(0);
transition: opacity 0.3s ease, transform 0.3s ease;
position: relative;
}
.tab-content h3 {
margin-top: 0;
margin-bottom: 15px;
color: #333;
}
.tab-content p {
margin: 0;
line-height: 1.6;
color: #666;
}
@keyframes slide-in {
from {
transform: scaleX(0);
}
to {
transform: scaleX(1);
}
}
/* Responsive styles */
@media (max-width: 500px) {
.tab-btn {
padding: 10px;
font-size: 14px;
flex-direction: column;
gap: 5px;
}
.tab-btn span {
display: none;
}
.tab-btn i {
font-size: 18px;
}
}
/* Dark mode styles */
@media (prefers-color-scheme: dark) {
.tabs {
border-bottom-color: rgba(255, 255, 255, 0.1);
}
.tab-btn {
color: #aaa;
}
.tab-btn:hover,
.tab-btn.active {
color: #8a3eff;
}
.tab-btn.active::after {
background: #8a3eff;
}
.tab-content h3 {
color: #eee;
}
.tab-content p {
color: #bbb;
}
}
/**
* Initialize the tab interface
*/
function initTabs() {
// Find all tab buttons
const tabButtons = document.querySelectorAll('.tab-btn');
// Find all tab content sections
const tabContents = document.querySelectorAll('.tab-content');
// Add click event to each tab button
tabButtons.forEach(button => {
button.addEventListener('click', () => {
// The tab id to show
const tabId = button.dataset.tab;
// Remove active class from all buttons
tabButtons.forEach(btn => btn.classList.remove('active'));
// Add active class to clicked button
button.classList.add('active');
// Hide all tab contents
tabContents.forEach(content => content.classList.remove('active'));
// Show the selected tab content
const activeTab = document.getElementById(tabId);
if (activeTab) {
activeTab.classList.add('active');
}
});
});
}
// Initialize the tabs when the DOM is fully loaded
document.addEventListener('DOMContentLoaded', initTabs);
/* Pills Style Tabs */
.tabs-pills .tabs {
border-bottom: none;
gap: 10px;
}
.tabs-pills .tab-btn {
border-radius: 50px;
background-color: rgba(0, 0, 0, 0.05);
transition: all 0.3s ease;
}
.tabs-pills .tab-btn.active {
background-color: #2575fc;
color: white;
}
.tabs-pills .tab-btn.active::after {
display: none;
}
/* Vertical Tabs */
.tabs-vertical {
display: flex;
gap: 20px;
}
.tabs-vertical .tabs {
flex-direction: column;
border-bottom: none;
border-right: 1px solid rgba(0, 0, 0, 0.1);
width: 200px;
}
.tabs-vertical .tab-btn {
justify-content: flex-start;
padding: 12px 15px;
border-radius: 5px 0 0 5px;
}
.tabs-vertical .tab-btn.active::after {
left: auto;
right: -1px;
bottom: 0;
width: 3px;
height: 100%;
border-radius: 3px 0 0 3px;
}
.tabs-vertical .tab-content-container {
flex: 1;
}
/* Dark theme for all tab variations */
@media (prefers-color-scheme: dark) {
.tabs-pills .tab-btn {
background-color: rgba(255, 255, 255, 0.08);
}
.tabs-pills .tab-btn.active {
background-color: #8a3eff;
}
.tabs-vertical .tabs {
border-right-color: rgba(255, 255, 255, 0.1);
}
}