# Tabs

SvTabs: a settings screen with real panels (line tabs, a disabled tab) plus a pill-style view switcher. Roving arrow-key focus, automatic activation.

Uses `@svgrid/grid` (MIT). Category: Layout. Live demo: https://svgrid.com/demos/320-tabs/

Install: `npm i @svgrid/grid` (Svelte 5).

## About this example

SvTabs in Svelte 5 as a settings screen: line tabs with real panels and a disabled tab, plus a pill-style view switcher. Focus roves between tabs with the arrow keys and activation is automatic, following the WAI-ARIA tabs pattern, with the active tab bound through bind:value.

SvTabs - a production settings screen: line tabs with real panels, plus a pill-style variant. Roving arrow-key focus, automatic activation. Copy-paste ready.

## Imports, features and API used

- Imports: `@svgrid/grid`

## Frequently asked questions

### How do I disable a tab?

Set disabled on its entry in tabs. It stays visible, is skipped by arrow-key navigation and cannot be activated.

### What is automatic activation?

Moving focus with the arrow keys also selects the tab, so keyboard users do not need a second key press; the panel changes as focus moves.

### How do I switch to the pill look?

Set variant='pill'. The tabs render as a segmented pill group instead of an underlined row, with the same behaviour.

## Related documentation

- [SvTabs](https://svgrid.com/docs/help/ui-components/sv-tabs.md)

## Related articles

- [Saved Views - Persist Grid Layout and Filters](https://svgrid.com/blog/saved-views-persist-layout/) - Give users named, switchable snapshots of column order, sorting, filters, and grouping - persisted to localStorage or a server adapter - using SvGrid's createNamedViews API.
- [Avoiding Layout Thrash in Custom Grid Cells](https://svgrid.com/blog/avoiding-layout-thrash-custom-cells/) - Layout thrash from interleaved DOM reads and writes is the most common cause of scroll jank in grids with custom cells - here is how to find it and design your way out of it.
- [Column Resizing and Reordering - Let Users Shape the Grid](https://svgrid.com/blog/column-resizing-and-reordering/) - How to wire drag-to-resize and drag-to-reorder in SvGrid, then persist the layout to localStorage so it survives page reloads.

## Source code (320-tabs.svelte)

```svelte
<script lang="ts">
  /**
   * SvTabs - a production settings screen: line tabs with real panels, plus a
   * pill-style variant. Roving arrow-key focus, automatic activation. Copy-paste
   * ready.
   */
  import { SvTabs } from '@svgrid/grid'
  import type { TabItem } from '@svgrid/grid'

  const tabs: TabItem[] = [
    { id: 'profile', label: 'Profile' },
    { id: 'security', label: 'Security' },
    { id: 'billing', label: 'Billing' },
    { id: 'team', label: 'Team', disabled: true },
  ]
  let active = $state('profile')
  const view: TabItem[] = [
    { id: 'grid', label: 'Grid' },
    { id: 'list', label: 'List' },
    { id: 'board', label: 'Board' },
  ]
  let viewMode = $state('grid')
</script>

<div class="wrap">
  <header>
    <h2>Tabs</h2>
    <p>WAI-ARIA tabs with roving arrow-key focus - settings screens, detail panels, view switchers. Line and pill variants.</p>
  </header>

  <div class="card">
    <SvTabs {tabs} bind:value={active}>
      {#snippet panel(id)}
        <div class="panel">
          {#if id === 'profile'}
            <h4>Profile</h4><p>Update your name, avatar and public bio. Changes are visible to your team immediately.</p>
          {:else if id === 'security'}
            <h4>Security</h4><p>Manage your password, two-factor authentication and active sessions.</p>
          {:else if id === 'billing'}
            <h4>Billing</h4><p>Your plan renews on the 1st. Update your card or download past invoices here.</p>
          {/if}
        </div>
      {/snippet}
    </SvTabs>
  </div>

  <div class="pillrow">
    <span class="pl">View</span>
    <SvTabs tabs={view} variant="pill" bind:value={viewMode} />
    <span class="cur">{viewMode}</span>
  </div>
</div>

<style>
  .wrap { padding: 20px; max-width: 560px; display: flex; flex-direction: column; gap: 22px; }
  header h2 { margin: 0 0 4px; font-size: 20px; font-weight: 700; }
  header p { margin: 0; color: var(--sg-muted, #64748b); font-size: 13.5px; line-height: 1.5; }
  .card { border: 1px solid var(--sg-border, #e2e8f0); border-radius: 12px; padding: 4px 16px 8px; }
  .panel h4 { margin: 0 0 6px; font-size: 15px; }
  .panel p { margin: 0; font-size: 13.5px; color: var(--sg-muted, #64748b); line-height: 1.6; }
  .pillrow { display: flex; align-items: center; gap: 12px; }
  .pl { font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--sg-muted, #64748b); }
  .cur { font-size: 13px; color: var(--sg-muted, #94a3b8); }
</style>
```

[View this example on GitHub](https://github.com/sv-grid/sv-grid/blob/main/examples/src/demos/320-tabs.svelte)
