Component
Tabbed Content
Tabbed Content.
- Component
- Vanilla
- HTML
- MIT
Preview
Live component
No interactive preview for this component.
Install it with the CLI below, or read the implementation on this page.
Install
Add to your project
npx devsnips add Vanilla/Components/Tabs/tabbed-content Vanilla/Components/Tabs/tabbed-content <!--
Responsive Tabbed Content Section
- Accessible tab panel implementation
- Keyboard navigation support
- Responsive design (switches to accordion on mobile)
- ARIA roles and states
- Minimal JavaScript for tab switching
-->
<div class="tabs-container" role="tablist" aria-label="Content tabs">
<div class="tab-list">
<button class="tab-button" role="tab" aria-selected="true" aria-controls="panel-1" id="tab-1">
Tab 1
</button>
<button class="tab-button" role="tab" aria-selected="false" aria-controls="panel-2" id="tab-2">
Tab 2
</button>
<button class="tab-button" role="tab" aria-selected="false" aria-controls="panel-3" id="tab-3">
Tab 3
</button>
</div>
<div class="tab-panels">
<div class="tab-panel" role="tabpanel" id="panel-1" aria-labelledby="tab-1" tabindex="0">
<h3>Panel 1 Content</h3>
<p>This is the content for the first tab panel. Add your content here.</p>
</div>
<div class="tab-panel" role="tabpanel" id="panel-2" aria-labelledby="tab-2" tabindex="0" hidden>
<h3>Panel 2 Content</h3>
<p>This is the content for the second tab panel. Add your content here.</p>
</div>
<div class="tab-panel" role="tabpanel" id="panel-3" aria-labelledby="tab-3" tabindex="0" hidden>
<h3>Panel 3 Content</h3>
<p>This is the content for the third tab panel. Add your content here.</p>
</div>
</div>
</div>
<style>
.tabs-container {
max-width: 800px;
margin: 2rem auto;
padding: 0 1rem;
}
.tab-list {
display: flex;
gap: 0.5rem;
border-bottom: 2px solid var(--ds-border, #ddd);
margin-bottom: 1rem;
}
.tab-button {
padding: 0.75rem 1.5rem;
border: none;
background: none;
cursor: pointer;
font-size: 1rem;
border-bottom: 2px solid transparent;
margin-bottom: -2px;
transition: all 0.3s;
}
.tab-button[aria-selected="true"] {
border-bottom-color: var(--ds-accent, #4a90e2);
color: var(--ds-accent, #4a90e2);
}
.tab-panel {
padding: 1rem;
}
/* Focus styles for accessibility */
.tab-button:focus-visible {
outline: 2px solid var(--ds-accent, #4a90e2);
outline-offset: -2px;
}
/* Responsive styles */
@media (max-width: 600px) {
.tab-list {
flex-direction: column;
gap: 0;
border-bottom: none;
}
.tab-button {
width: 100%;
text-align: left;
border: 1px solid var(--ds-border, #ddd);
border-bottom: none;
margin: 0;
}
.tab-button:last-child {
border-bottom: 1px solid var(--ds-border, #ddd);
}
.tab-button[aria-selected="true"] {
background: var(--ds-accent, #4a90e2);
color: white;
border-color: var(--ds-accent, #4a90e2);
}
.tab-panel {
border: 1px solid var(--ds-border, #ddd);
margin-top: 1rem;
}
}
/* devsnips-qa:quality-bar */
@media (prefers-reduced-motion: reduce){*{animation-duration:0.01ms !important;animation-iteration-count:1 !important;transition-duration:0.01ms !important;scroll-behavior:auto !important;}}
/* DevSnips design tokens (Swiss) — edit tokens.css to re-theme */
:root{
--ds-bg:#fff;--ds-surface:#fff;--ds-surface-2:#f7f7f7;--ds-surface-3:#ededed;--ds-foreground:#0a0a0a;--ds-muted:#525252;--ds-subtle:#a3a3a3;--ds-border:#e5e5e5;--ds-border-strong:#d4d4d4;--ds-accent:#2563eb;--ds-accent-hover:#1d4ed8;--ds-accent-fg:#fff;--ds-accent-soft:#eff6ff;--ds-success:#16a34a;--ds-success-soft:#f0fdf4;--ds-warning:#d97706;--ds-warning-soft:#fffbeb;--ds-danger:#dc2626;--ds-danger-soft:#fef2f2;--ds-info:#2563eb;--ds-info-soft:#eff6ff;--ds-font-sans:system-ui,-apple-system,'Segoe UI',Roboto,Inter,'Helvetica Neue',Arial,sans-serif;--ds-font-mono:ui-monospace,'SF Mono','JetBrains Mono',Menlo,Consolas,monospace;--ds-text-xs:.75rem;--ds-text-sm:.875rem;--ds-text-base:1rem;--ds-text-lg:1.125rem;--ds-text-xl:1.25rem;--ds-text-2xl:1.5rem;--ds-text-3xl:1.875rem;--ds-text-4xl:2.25rem;--ds-leading-tight:1.25;--ds-leading-normal:1.5;--ds-leading-relaxed:1.625;--ds-weight-normal:400;--ds-weight-medium:500;--ds-weight-semibold:600;--ds-weight-bold:700;--ds-space-0:0;--ds-space-px:1px;--ds-space-1:.25rem;--ds-space-2:.5rem;--ds-space-3:.75rem;--ds-space-4:1rem;--ds-space-5:1.25rem;--ds-space-6:1.5rem;--ds-space-8:2rem;--ds-space-10:2.5rem;--ds-space-12:3rem;--ds-space-16:4rem;--ds-radius-sm:.25rem;--ds-radius-md:.5rem;--ds-radius-lg:.75rem;--ds-radius-xl:1rem;--ds-radius-2xl:1.5rem;--ds-radius-full:9999px;--ds-shadow-sm:0 1px 2px 0 rgba(0,0,0,.05);--ds-shadow-md:0 4px 6px -1px rgba(0,0,0,.08),0 2px 4px -2px rgba(0,0,0,.05);--ds-shadow-lg:0 10px 15px -3px rgba(0,0,0,.1),0 4px 6px -4px rgba(0,0,0,.05);--ds-duration-fast:120ms;--ds-duration-normal:200ms;--ds-duration-slow:300ms;--ds-ease-out:cubic-bezier(.16,1,.3,1);--ds-ease-in-out:cubic-bezier(.4,0,.2,1);--ds-ring:0 0 0 2px #2563eb;--ds-container:1200px;--ds-gutter:1rem;
}
@media (prefers-color-scheme: dark){:root{--ds-bg:#0a0a0a;--ds-surface:#111;--ds-surface-2:#171717;--ds-surface-3:#1f1f1f;--ds-foreground:#fafafa;--ds-muted:#a3a3a3;--ds-subtle:#737373;--ds-border:#262626;--ds-border-strong:#404040;--ds-accent:#3b82f6;--ds-accent-hover:#60a5fa;--ds-accent-fg:#fff;--ds-accent-soft:#172554;--ds-success:#22c55e;--ds-success-soft:#052e16;--ds-warning:#f59e0b;--ds-warning-soft:#422006;--ds-danger:#ef4444;--ds-danger-soft:#450a0a;--ds-info:#3b82f6;--ds-info-soft:#172554;--ds-ring:0 0 0 2px #3b82f6;}}
</style>
<script>
const tabList = document.querySelector('.tab-list');
const tabs = tabList.querySelectorAll('.tab-button');
const panels = document.querySelectorAll('.tab-panel');
// Click handler
tabList.addEventListener('click', e => {
const target = e.target;
if (target.role !== 'tab') return;
// Deactivate all tabs
tabs.forEach(tab => {
tab.setAttribute('aria-selected', 'false');
tab.tabIndex = -1;
});
// Hide all panels
panels.forEach(panel => {
panel.hidden = true;
});
// Activate clicked tab
target.setAttribute('aria-selected', 'true');
target.tabIndex = 0;
// Show corresponding panel
const panelId = target.getAttribute('aria-controls');
document.getElementById(panelId).hidden = false;
});
// Key handler
tabList.addEventListener('keydown', e => {
const target = e.target;
if (target.role !== 'tab') return;
let selectedTab = target;
// Move left/right through tabs
switch (e.key) {
case 'ArrowLeft':
selectedTab = target.previousElementSibling || tabs[tabs.length - 1];
break;
case 'ArrowRight':
selectedTab = target.nextElementSibling || tabs[0];
break;
}
if (selectedTab !== target) {
selectedTab.click();
selectedTab.focus();
}
});
</script> # Snippet 05 Tabbed Content
Snippet 05 Tabbed Content with responsive design with animations.
**Technology:** vanilla
**Category:** components
**Subcategory:** tabs
**Tags:** tabs, animation, responsive, flexbox, layout, button, form, dropdown
**Responsive:** Yes 176 lines UTF-8 · LF · Spaces: 2
Continue browsing