Skip to content

Tabs

Introduction

The Tabs component provides a way to organize content into different sections that can be accessed one at a time. It follows WAI-ARIA guidelines and includes full keyboard support and proper ARIA attributes.

When to use

  • Organizing related content into sections
  • Switching between different views
  • Form sections
  • Product details pages
  • Settings panels
  • Dashboard sections

Usage

---
import { Tabs, TabsList, TabsTab, TabsPanel } from 'accessible-astro-components'
---
<Tabs>
<TabsList>
<TabsTab id="tab1" controls="panel1" selected>Tab 1</TabsTab>
<TabsTab id="tab2" controls="panel2">Tab 2</TabsTab>
<TabsTab id="tab3" controls="panel3">Tab 3</TabsTab>
</TabsList>
<TabsPanel id="panel1" labelledby="tab1" selected>
<h2>Panel 1</h2>
<p>Content for first panel</p>
</TabsPanel>
<TabsPanel id="panel2" labelledby="tab2">
<h2>Panel 2</h2>
<p>Content for second panel</p>
</TabsPanel>
<TabsPanel id="panel3" labelledby="tab3">
<h2>Panel 3</h2>
<p>Content for third panel</p>
</TabsPanel>
</Tabs>

Props

Tabs

PropTypeDefaultDescription
classstringundefinedOptional CSS class name

TabsList

PropTypeDefaultDescription
classstringundefinedOptional CSS class name

TabsTab

PropTypeDefaultDescription
idstringRequiredUnique identifier for the tab
controlsstringRequiredID of the panel this tab controls
selectedbooleanfalseWhether this tab is initially selected
classstringundefinedOptional CSS class name

TabsPanel

PropTypeDefaultDescription
idstringRequiredUnique identifier for the panel
labelledbystringRequiredID of the tab that labels this panel
selectedbooleanfalseWhether this panel is initially visible
classstringundefinedOptional CSS class name

Accessibility features

  • Proper ARIA roles (tablist, tab, tabpanel)
  • Keyboard navigation:
    • Left/Right arrows to move between tabs
    • Tab/Shift+Tab for focus management
  • Clear focus indicators
  • Proper ARIA states (aria-selected, aria-controls, aria-labelledby)
  • Semantic HTML structure
  • Proper focus management
  • Smooth transitions (respecting reduced-motion preferences)

Styling

.tabs {
--tab-padding: 1rem;
--tab-gap: 0.5rem;
--tab-border-width: 2px;
--tab-radius: 6px;
--tab-color-active: light-dark(#f0f0f0, #202020);
--tab-bg-active: light-dark(#202020, #dddddd);
}

Interactive example

First Panel

This is the content of the first panel. Try using the arrow keys to navigate between tabs!