<div class="tab-demo">
<div class="demo-content">
<h2>Interactive Tab Menu Demo</h2>
<p>A versatile tab menu system with smooth animations, content switching, and customizable styling. Perfect for organizing related content into easily accessible sections.</p>
<div class="demo-controls">
<h3>Tab Style:</h3>
<div class="control-buttons">
<button class="control-btn active" data-style="default">Default</button>
<button class="control-btn" data-style="rounded">Rounded</button>
<button class="control-btn" data-style="minimal">Minimal</button>
<button class="control-btn" data-style="pills">Pills</button>
</div>
</div>
</div>
<div class="tab-container">
<div class="tab-menu" role="tablist" aria-label="Content sections">
<button class="tab-button active" role="tab" aria-selected="true" aria-controls="tab-panel-1" id="tab-1" data-tab="overview">
<span class="tab-icon">π</span>
<span class="tab-text">Overview</span>
<span class="tab-indicator"></span>
</button>
<button class="tab-button" role="tab" aria-selected="false" aria-controls="tab-panel-2" id="tab-2" data-tab="features">
<span class="tab-icon">β‘</span>
<span class="tab-text">Features</span>
<span class="tab-indicator"></span>
</button>
<button class="tab-button" role="tab" aria-selected="false" aria-controls="tab-panel-3" id="tab-3" data-tab="pricing">
<span class="tab-icon">π°</span>
<span class="tab-text">Pricing</span>
<span class="tab-indicator"></span>
</button>
<button class="tab-button" role="tab" aria-selected="false" aria-controls="tab-panel-4" id="tab-4" data-tab="support">
<span class="tab-icon">π§</span>
<span class="tab-text">Support</span>
<span class="tab-indicator"></span>
</button>
<button class="tab-button" role="tab" aria-selected="false" aria-controls="tab-panel-5" id="tab-5" data-tab="contact">
<span class="tab-icon">π</span>
<span class="tab-text">Contact</span>
<span class="tab-indicator"></span>
</button>
</div>
<div class="tab-content">
<div class="tab-panel active" role="tabpanel" aria-labelledby="tab-1" id="tab-panel-1">
<div class="panel-content">
<h3>π Project Overview</h3>
<p>Welcome to our comprehensive project overview. Here you'll find essential information about our platform, mission, and core objectives.</p>
<div class="content-grid">
<div class="content-item">
<h4>Mission Statement</h4>
<p>To provide innovative solutions that empower businesses and individuals to achieve their goals efficiently.</p>
</div>
<div class="content-item">
<h4>Core Values</h4>
<p>Innovation, reliability, customer satisfaction, and continuous improvement drive everything we do.</p>
</div>
</div>
<div class="action-buttons">
<button class="action-btn primary">Learn More</button>
<button class="action-btn secondary">Watch Demo</button>
</div>
</div>
</div>
<div class="tab-panel" role="tabpanel" aria-labelledby="tab-2" id="tab-panel-2">
<div class="panel-content">
<h3>β‘ Key Features</h3>
<p>Discover the powerful features that make our platform stand out from the competition.</p>
<div class="feature-list">
<div class="feature-item">
<span class="feature-icon">π</span>
<div class="feature-info">
<h4>Lightning Fast</h4>
<p>Optimized performance with sub-second response times</p>
</div>
</div>
<div class="feature-item">
<span class="feature-icon">π</span>
<div class="feature-info">
<h4>Secure & Reliable</h4>
<p>Enterprise-grade security with 99.9% uptime guarantee</p>
</div>
</div>
<div class="feature-item">
<span class="feature-icon">π±</span>
<div class="feature-info">
<h4>Mobile Responsive</h4>
<p>Perfect experience across all devices and screen sizes</p>
</div>
</div>
</div>
</div>
</div>
<div class="tab-panel" role="tabpanel" aria-labelledby="tab-3" id="tab-panel-3">
<div class="panel-content">
<h3>π° Pricing Plans</h3>
<p>Choose the perfect plan that fits your needs and budget.</p>
<div class="pricing-grid">
<div class="pricing-card">
<h4>Starter</h4>
<div class="price">$9<span>/month</span></div>
<ul class="features">
<li>β Basic features</li>
<li>β Email support</li>
<li>β 1GB storage</li>
</ul>
<button class="pricing-btn">Choose Plan</button>
</div>
<div class="pricing-card featured">
<h4>Professional</h4>
<div class="price">$29<span>/month</span></div>
<ul class="features">
<li>β All starter features</li>
<li>β Priority support</li>
<li>β 10GB storage</li>
<li>β Advanced analytics</li>
</ul>
<button class="pricing-btn">Choose Plan</button>
</div>
</div>
</div>
</div>
<div class="tab-panel" role="tabpanel" aria-labelledby="tab-4" id="tab-panel-4">
<div class="panel-content">
<h3>π§ Customer Support</h3>
<p>We're here to help you succeed with comprehensive support options.</p>
<div class="support-options">
<div class="support-item">
<span class="support-icon">π¬</span>
<h4>Live Chat</h4>
<p>Get instant help from our support team</p>
<span class="availability">Available 24/7</span>
</div>
<div class="support-item">
<span class="support-icon">π</span>
<h4>Knowledge Base</h4>
<p>Comprehensive guides and tutorials</p>
<span class="availability">Self-service</span>
</div>
<div class="support-item">
<span class="support-icon">π₯</span>
<h4>Video Tutorials</h4>
<p>Step-by-step video guides</p>
<span class="availability">On-demand</span>
</div>
</div>
</div>
</div>
<div class="tab-panel" role="tabpanel" aria-labelledby="tab-5" id="tab-panel-5">
<div class="panel-content">
<h3>π Get in Touch</h3>
<p>Ready to get started? Contact us today and let's discuss your needs.</p>
<div class="contact-info">
<div class="contact-item">
<span class="contact-icon">π§</span>
<div class="contact-details">
<h4>Email</h4>
<p>hello@example.com</p>
</div>
</div>
<div class="contact-item">
<span class="contact-icon">π±</span>
<div class="contact-details">
<h4>Phone</h4>
<p>+1 (555) 123-4567</p>
</div>
</div>
<div class="contact-item">
<span class="contact-icon">π</span>
<div class="contact-details">
<h4>Address</h4>
<p>123 Business St, City, State 12345</p>
</div>
</div>
</div>
<div class="contact-form">
<h4>Quick Contact</h4>
<form class="demo-form">
<input type="text" placeholder="Your Name" class="form-input">
<input type="email" placeholder="Your Email" class="form-input">
<textarea placeholder="Your Message" class="form-textarea"></textarea>
<button type="submit" class="form-submit">Send Message</button>
</form>
</div>
</div>
</div>
</div>
<div class="tab-info">
<div class="info-item">
<span class="info-label">Active Tab:</span>
<span class="info-value" id="activeTab">Overview</span>
</div>
<div class="info-item">
<span class="info-label">Tab Style:</span>
<span class="info-value" id="tabStyle">Default</span>
</div>
<div class="info-item">
<span class="info-label">Total Tabs:</span>
<span class="info-value" id="totalTabs">5</span>
</div>
</div>
</div>
</div>
.tab-demo {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 320px;
border-radius: 16px;
padding: 30px;
color: white;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.demo-content {
text-align: center;
margin-bottom: 30px;
}
.demo-content h2 {
margin: 0 0 12px 0;
font-size: 24px;
font-weight: 700;
}
.demo-content p {
margin: 0 0 20px 0;
opacity: 0.9;
line-height: 1.6;
}
.demo-controls h3 {
margin: 0 0 12px 0;
font-size: 16px;
font-weight: 600;
}
.control-buttons {
display: flex;
gap: 8px;
justify-content: center;
flex-wrap: wrap;
}
.control-btn {
padding: 6px 12px;
background: rgba(255, 255, 255, 0.2);
border: 1px solid rgba(255, 255, 255, 0.3);
border-radius: 6px;
color: white;
font-size: 12px;
cursor: pointer;
transition: all 0.3s ease;
}
.control-btn:hover,
.control-btn.active {
background: rgba(255, 255, 255, 0.3);
transform: translateY(-1px);
}
.tab-container {
background: white;
border-radius: 12px;
padding: 20px;
margin-bottom: 20px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}
.tab-menu {
display: flex;
background: #f8f9fa;
border-radius: 8px;
padding: 4px;
margin-bottom: 20px;
overflow-x: auto;
scrollbar-width: none;
-ms-overflow-style: none;
}
.tab-menu::-webkit-scrollbar {
display: none;
}
.tab-button {
display: flex;
align-items: center;
gap: 8px;
padding: 12px 16px;
background: transparent;
border: none;
border-radius: 6px;
color: #6b7280;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: all 0.3s ease;
position: relative;
white-space: nowrap;
min-width: fit-content;
}
.tab-button:hover {
background: rgba(59, 130, 246, 0.1);
color: #3b82f6;
}
.tab-button.active {
background: white;
color: #3b82f6;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.tab-icon {
font-size: 16px;
}
.tab-indicator {
position: absolute;
bottom: -2px;
left: 50%;
transform: translateX(-50%);
width: 0;
height: 2px;
background: #3b82f6;
border-radius: 1px;
transition: width 0.3s ease;
}
.tab-button.active .tab-indicator {
width: 80%;
}
.tab-content {
position: relative;
min-height: 300px;
}
.tab-panel {
position: absolute;
top: 0;
left: 0;
right: 0;
opacity: 0;
visibility: hidden;
transform: translateY(10px);
transition: all 0.3s ease;
}
.tab-panel.active {
opacity: 1;
visibility: visible;
transform: translateY(0);
position: relative;
}
.panel-content {
color: #374151;
}
.panel-content h3 {
margin: 0 0 16px 0;
font-size: 20px;
font-weight: 600;
color: #1f2937;
}
.panel-content p {
margin: 0 0 20px 0;
line-height: 1.6;
color: #6b7280;
}
.content-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 20px;
margin-bottom: 24px;
}
.content-item {
padding: 20px;
background: #f9fafb;
border-radius: 8px;
border: 1px solid #e5e7eb;
}
.content-item h4 {
margin: 0 0 8px 0;
font-size: 16px;
font-weight: 600;
color: #1f2937;
}
.content-item p {
margin: 0;
font-size: 14px;
color: #6b7280;
}
.action-buttons {
display: flex;
gap: 12px;
flex-wrap: wrap;
}
.action-btn {
padding: 10px 20px;
border: none;
border-radius: 6px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: all 0.3s ease;
}
.action-btn.primary {
background: #3b82f6;
color: white;
}
.action-btn.primary:hover {
background: #2563eb;
transform: translateY(-1px);
}
.action-btn.secondary {
background: #f3f4f6;
color: #374151;
border: 1px solid #d1d5db;
}
.action-btn.secondary:hover {
background: #e5e7eb;
}
.feature-list {
display: flex;
flex-direction: column;
gap: 16px;
}
.feature-item {
display: flex;
align-items: center;
gap: 16px;
padding: 16px;
background: #f9fafb;
border-radius: 8px;
border: 1px solid #e5e7eb;
}
.feature-icon {
font-size: 24px;
flex-shrink: 0;
}
.feature-info h4 {
margin: 0 0 4px 0;
font-size: 16px;
font-weight: 600;
color: #1f2937;
}
.feature-info p {
margin: 0;
font-size: 14px;
color: #6b7280;
}
.pricing-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 20px;
}
.pricing-card {
padding: 24px;
background: #f9fafb;
border: 1px solid #e5e7eb;
border-radius: 12px;
text-align: center;
transition: all 0.3s ease;
}
.pricing-card.featured {
border-color: #3b82f6;
background: #eff6ff;
transform: scale(1.05);
}
.pricing-card h4 {
margin: 0 0 12px 0;
font-size: 18px;
font-weight: 600;
color: #1f2937;
}
.price {
font-size: 32px;
font-weight: 700;
color: #3b82f6;
margin-bottom: 16px;
}
.price span {
font-size: 16px;
color: #6b7280;
}
.features {
list-style: none;
padding: 0;
margin: 0 0 20px 0;
}
.features li {
padding: 4px 0;
font-size: 14px;
color: #374151;
}
.pricing-btn {
width: 100%;
padding: 10px;
background: #3b82f6;
color: white;
border: none;
border-radius: 6px;
font-weight: 500;
cursor: pointer;
transition: all 0.3s ease;
}
.pricing-btn:hover {
background: #2563eb;
}
.support-options {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
}
.support-item {
text-align: center;
padding: 20px;
background: #f9fafb;
border-radius: 8px;
border: 1px solid #e5e7eb;
}
.support-icon {
font-size: 32px;
margin-bottom: 12px;
display: block;
}
.support-item h4 {
margin: 0 0 8px 0;
font-size: 16px;
font-weight: 600;
color: #1f2937;
}
.support-item p {
margin: 0 0 8px 0;
font-size: 14px;
color: #6b7280;
}
.availability {
display: inline-block;
padding: 4px 8px;
background: #dcfce7;
color: #166534;
font-size: 12px;
border-radius: 4px;
font-weight: 500;
}
.contact-info {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin-bottom: 24px;
}
.contact-item {
display: flex;
align-items: center;
gap: 12px;
padding: 16px;
background: #f9fafb;
border-radius: 8px;
border: 1px solid #e5e7eb;
}
.contact-icon {
font-size: 20px;
flex-shrink: 0;
}
.contact-details h4 {
margin: 0 0 4px 0;
font-size: 14px;
font-weight: 600;
color: #1f2937;
}
.contact-details p {
margin: 0;
font-size: 14px;
color: #6b7280;
}
.contact-form {
background: #f9fafb;
padding: 20px;
border-radius: 8px;
border: 1px solid #e5e7eb;
}
.contact-form h4 {
margin: 0 0 16px 0;
font-size: 16px;
font-weight: 600;
color: #1f2937;
}
.demo-form {
display: flex;
flex-direction: column;
gap: 12px;
}
.form-input,
.form-textarea {
padding: 10px 12px;
border: 1px solid #d1d5db;
border-radius: 6px;
font-size: 14px;
transition: border-color 0.3s ease;
}
.form-input:focus,
.form-textarea:focus {
outline: none;
border-color: #3b82f6;
}
.form-textarea {
resize: vertical;
min-height: 80px;
}
.form-submit {
padding: 10px;
background: #3b82f6;
color: white;
border: none;
border-radius: 6px;
font-weight: 500;
cursor: pointer;
transition: all 0.3s ease;
}
.form-submit:hover {
background: #2563eb;
}
.tab-info {
background: rgba(255, 255, 255, 0.1);
border-radius: 8px;
padding: 16px;
display: flex;
gap: 24px;
flex-wrap: wrap;
}
.info-item {
display: flex;
flex-direction: column;
gap: 4px;
}
.info-label {
font-size: 12px;
opacity: 0.8;
font-weight: 500;
}
.info-value {
font-size: 14px;
font-weight: 600;
}
/* Tab style variations */
.tab-menu.rounded .tab-button {
border-radius: 20px;
}
.tab-menu.minimal {
background: transparent;
padding: 0;
border-bottom: 1px solid #e5e7eb;
}
.tab-menu.minimal .tab-button {
border-radius: 0;
border-bottom: 2px solid transparent;
}
.tab-menu.minimal .tab-button.active {
background: transparent;
border-bottom-color: #3b82f6;
box-shadow: none;
}
.tab-menu.pills .tab-button {
border-radius: 20px;
margin: 0 4px;
}
.tab-menu.pills .tab-button.active {
background: #3b82f6;
color: white;
}
/* Responsive design */
@media (max-width: 768px) {
.tab-demo {
padding: 20px;
}
.tab-menu {
flex-direction: column;
gap: 4px;
}
.tab-button {
justify-content: center;
}
.content-grid,
.pricing-grid,
.support-options,
.contact-info {
grid-template-columns: 1fr;
}
.pricing-card.featured {
transform: none;
}
.control-buttons {
flex-direction: column;
align-items: center;
}
.control-btn {
width: 100px;
}
.tab-info {
flex-direction: column;
gap: 12px;
}
}
/* Focus styles for accessibility */
.tab-button:focus,
.action-btn:focus,
.pricing-btn:focus,
.form-submit:focus,
.control-btn:focus {
outline: 2px solid #3b82f6;
outline-offset: 2px;
}
/* Loading animation */
.tab-panel.loading {
opacity: 0.6;
}
.tab-panel.loading::after {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 20px;
height: 20px;
border: 2px solid #e5e7eb;
border-top: 2px solid #3b82f6;
border-radius: 50%;
animation: spin 1s linear infinite;
transform: translate(-50%, -50%);
}
@keyframes spin {
0% { transform: translate(-50%, -50%) rotate(0deg); }
100% { transform: translate(-50%, -50%) rotate(360deg); }
}
document.addEventListener('DOMContentLoaded', function() {
const tabButtons = document.querySelectorAll('.tab-button');
const tabPanels = document.querySelectorAll('.tab-panel');
const tabMenu = document.querySelector('.tab-menu');
const controlButtons = document.querySelectorAll('.control-btn');
const activeTab = document.getElementById('activeTab');
const tabStyle = document.getElementById('tabStyle');
const totalTabs = document.getElementById('totalTabs');
// Initialize tab functionality
function initTabs() {
tabButtons.forEach((button, index) => {
button.addEventListener('click', function() {
const tabId = this.getAttribute('data-tab');
switchTab(tabId, this);
});
// Keyboard navigation
button.addEventListener('keydown', function(e) {
let targetIndex;
switch(e.key) {
case 'ArrowLeft':
e.preventDefault();
targetIndex = index > 0 ? index - 1 : tabButtons.length - 1;
tabButtons[targetIndex].focus();
break;
case 'ArrowRight':
e.preventDefault();
targetIndex = index < tabButtons.length - 1 ? index + 1 : 0;
tabButtons[targetIndex].focus();
break;
case 'Home':
e.preventDefault();
tabButtons[0].focus();
break;
case 'End':
e.preventDefault();
tabButtons[tabButtons.length - 1].focus();
break;
case 'Enter':
case ' ':
e.preventDefault();
this.click();
break;
}
});
});
}
// Switch tab function
function switchTab(tabId, clickedButton) {
// Add loading state
const targetPanel = document.getElementById(`tab-panel-${getTabIndex(tabId) + 1}`);
targetPanel.classList.add('loading');
setTimeout(() => {
// Remove active class from all buttons and panels
tabButtons.forEach(btn => {
btn.classList.remove('active');
btn.setAttribute('aria-selected', 'false');
});
tabPanels.forEach(panel => {
panel.classList.remove('active');
});
// Add active class to clicked button and corresponding panel
clickedButton.classList.add('active');
clickedButton.setAttribute('aria-selected', 'true');
targetPanel.classList.add('active');
targetPanel.classList.remove('loading');
// Update info
updateTabInfo(clickedButton.querySelector('.tab-text').textContent);
// Show feedback
showFeedback(`Switched to ${clickedButton.querySelector('.tab-text').textContent} tab`);
}, 300);
}
// Get tab index by tab ID
function getTabIndex(tabId) {
const tabIds = ['overview', 'features', 'pricing', 'support', 'contact'];
return tabIds.indexOf(tabId);
}
// Update tab info
function updateTabInfo(tabName) {
activeTab.textContent = tabName;
}
// Style control handlers
controlButtons.forEach(button => {
button.addEventListener('click', function() {
const style = this.getAttribute('data-style');
// Update active button
controlButtons.forEach(btn => btn.classList.remove('active'));
this.classList.add('active');
// Update tab menu style
tabMenu.className = 'tab-menu';
if (style !== 'default') {
tabMenu.classList.add(style);
}
// Update style info
const styleNames = {
default: 'Default',
rounded: 'Rounded',
minimal: 'Minimal',
pills: 'Pills'
};
tabStyle.textContent = styleNames[style];
showFeedback(`Changed to ${styleNames[style]} style`);
});
});
// Form submission handler
const demoForm = document.querySelector('.demo-form');
if (demoForm) {
demoForm.addEventListener('submit', function(e) {
e.preventDefault();
const formData = new FormData(this);
const name = this.querySelector('input[type="text"]').value;
const email = this.querySelector('input[type="email"]').value;
const message = this.querySelector('textarea').value;
if (name && email && message) {
showFeedback('Message sent successfully!');
this.reset();
} else {
showFeedback('Please fill in all fields');
}
});
}
// Action button handlers
const actionButtons = document.querySelectorAll('.action-btn, .pricing-btn');
actionButtons.forEach(button => {
button.addEventListener('click', function() {
const action = this.textContent.trim();
showFeedback(`${action} clicked!`);
});
});
// Auto-rotate tabs (optional)
let autoRotate = false;
let rotateInterval;
function startAutoRotate() {
if (autoRotate) return;
autoRotate = true;
let currentIndex = 0;
rotateInterval = setInterval(() => {
currentIndex = (currentIndex + 1) % tabButtons.length;
tabButtons[currentIndex].click();
}, 5000);
}
function stopAutoRotate() {
autoRotate = false;
if (rotateInterval) {
clearInterval(rotateInterval);
}
}
// Stop auto-rotate on user interaction
tabButtons.forEach(button => {
button.addEventListener('click', stopAutoRotate);
});
// Feedback function
function showFeedback(message) {
const existing = document.querySelector('.demo-feedback');
if (existing) existing.remove();
const feedback = document.createElement('div');
feedback.className = 'demo-feedback';
feedback.textContent = message;
feedback.style.cssText = `
position: fixed;
top: 20px;
left: 50%;
transform: translateX(-50%);
background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
color: white;
padding: 12px 20px;
border-radius: 8px;
font-size: 14px;
font-weight: 500;
z-index: 10001;
box-shadow: 0 4px 15px rgba(72, 187, 120, 0.3);
opacity: 0;
transition: opacity 0.3s ease;
`;
document.body.appendChild(feedback);
requestAnimationFrame(() => {
feedback.style.opacity = '1';
});
setTimeout(() => {
feedback.style.opacity = '0';
setTimeout(() => feedback.remove(), 300);
}, 2500);
}
// Initialize
initTabs();
updateTabInfo('Overview');
totalTabs.textContent = tabButtons.length;
// Initial feedback
setTimeout(() => {
showFeedback('Try different tab styles and navigate with keyboard arrows!');
}, 1000);
// Optional: Start auto-rotate after delay
// setTimeout(startAutoRotate, 10000);
});