---
title: Tabs
description: Tab panels with labels, custom values and default index.
---

Tabs switch panels client-side via the runtime — no page reload. The tab list
is `role="tablist"` with proper `aria-selected` state.

## Simple items

```ts
tabs({ items: ['Preview', 'Code', 'Notes'] });
```

## Panels with content

```ts
tabs({
  label: 'Package manager',
  panels: [
    { title: 'bun', content: code('bun add @iconify-json/lucide') },
    { title: 'npm', content: code('npm install @iconify-json/lucide') },
    { title: 'pnpm', content: code('pnpm add @iconify-json/lucide') },
  ],
});
```

## Non-default start index

```ts
tabs({
  defaultIndex: 2,
  panels: [
    { title: 'Setup', content: '<p>Install and configure.</p>' },
    { title: 'Usage', content: '<p>Import and call the builder.</p>' },
    { title: 'Advanced', content: '<p>Override icons and labels.</p>' },
  ],
});
```

## Props

<PropsTable
  labels={{ prop: 'Option', type: 'Type', default: 'Default' }}
  type={{
    items: { type: 'string[]', description: 'Tab titles when <code>panels</code> is omitted.' },
    panels: { type: 'TabPanel[]', description: '<code>{ title?, value?, content }</code> — content can be HTML.' },
    label: { type: 'string', default: "''", description: 'Optional group label before the tab list.' },
    defaultIndex: { type: 'number', default: '0', description: 'Initially active tab.' },
  }}
/>

## Notes

- `value` (when set) is used as the `data-cpd-tab` value; otherwise it is
  derived from the title (`title.toLowerCase().replace(/\s/, '-')`).
- Panels with no content (items-only mode) render an empty active panel.
