Search
MaterialComponentsDocs
Components overviewApp barBadgeButtonsButton groupButtonExtended FABFAB menuFABIcon buttonSplit buttonCardCarouselCheckboxChipsDate & time pickersDate pickerTime pickerDialogDividerListLoading & progressLoading indicatorProgressMenuNavigationNavigation barNavigation drawerNavigation railRadio buttonsSearchSelectSheetsBottom sheetSide sheetSliderSnackbarSwitchTabsText fieldToolbarTooltip

Tabs

Switch between related views. Try primary and secondary tabs, icons, and badges.

FactoryWeb ComponentsReactVueSvelteSolidJS
PublishedUpdated

Tabs organize related content at the same level, one view at a time. M3 has two variants: primary tabs sit at the top of the content pane, under an app bar, and secondary tabs subdivide one of those views. Tabs are for related content, not sequential steps.

Usage

Start one tab with state: 'active'; the component does not pick one. change fires with the tab's value whenever the selection changes.

Vanilla
import { createTabs } from 'material';

const tabs = createTabs({
  tabs: [
    { text: 'Flights', value: 'flights', state: 'active' },
    { text: 'Trips', value: 'trips' },
    { text: 'Explore', value: 'explore' },
  ],
});
tabs.on('change', ({ value }) => showPanel(value));
document.body.append(tabs.element);
Web Components
<m-tabs value="flights">
  <m-tab value="flights">Flights</m-tab>
  <m-tab value="trips">Trips</m-tab>
  <m-tab value="explore">Explore</m-tab>
</m-tabs>

<script type="module">
  const tabs = document.querySelector('m-tabs');
  tabs.addEventListener('change', (event) => showPanel(event.detail.value));
</script>
React
import { useState } from 'react';
import { Tabs, Tab } from 'material/react';
import { showPanel } from './app';

export function Example() {
  const [value, setValue] = useState("flights");
  return (
    <Tabs value={value} onChange={(event) => { setValue(event.detail.value); showPanel(event.detail.value); }}>
      <Tab value="flights">Flights</Tab>
      <Tab value="trips">Trips</Tab>
      <Tab value="explore">Explore</Tab>
    </Tabs>
  );
}
Vue
<script setup lang="ts">
import { ref } from 'vue';
import { MTabs, MTab } from 'material/vue';
import { showPanel } from './app';

const value = ref("flights");
</script>

<template>
  <MTabs v-model="value" @change="showPanel($event.detail.value)">
    <MTab value="flights">Flights</MTab>
    <MTab value="trips">Trips</MTab>
    <MTab value="explore">Explore</MTab>
  </MTabs>
</template>
Svelte
<script lang="ts">
  import { Tabs, Tab } from 'material/svelte';
  import { showPanel } from './app';

  let value = $state("flights");
</script>

<Tabs bind:value onchange={(event) => showPanel(event.detail.value)}>
  <Tab value="flights">Flights</Tab>
  <Tab value="trips">Trips</Tab>
  <Tab value="explore">Explore</Tab>
</Tabs>
SolidJS
import { createSignal } from 'solid-js';
import { Tabs, Tab } from 'material/solid';
import { showPanel } from './app';

export function Example() {
  const [value, setValue] = createSignal("flights");
  return (
    <Tabs value={value()} onChange={(event) => { setValue(event.detail.value); showPanel(event.detail.value); }}>
      <Tab value="flights">Flights</Tab>
      <Tab value="trips">Trips</Tab>
      <Tab value="explore">Explore</Tab>
    </Tabs>
  );
}

Examples

Icons and a badge

With a label, the icon sits above it and the row is 64dp tall. A tab with an icon and no label needs ariaLabel; without it the tab's name falls back to its value. A badge is a count or a short text, four characters at most.

Vanilla
import { createTabs } from 'material';

const tabs = createTabs({
  tabs: [
    { text: 'Video', value: 'video', icon: videoIcon, state: 'active' },
    { text: 'Photos', value: 'photos', icon: photoIcon, badge: 3 },
    { text: 'Audio', value: 'audio', icon: audioIcon },
  ],
});
document.body.append(tabs.element);
Web Components
<m-tabs value="video">
  <m-tab value="video">Video</m-tab>
  <m-tab value="photos" badge="3">Photos</m-tab>
  <m-tab value="audio">Audio</m-tab>
</m-tabs>

<script type="module">
  const tabs = document.querySelector('m-tabs');
  tabs.querySelector('m-tab[value="video"]').setAttribute('icon', videoIcon);
  tabs.querySelector('m-tab[value="photos"]').setAttribute('icon', photoIcon);
  tabs.querySelector('m-tab[value="audio"]').setAttribute('icon', audioIcon);
</script>
React
import { useState } from 'react';
import { Tabs, Tab } from 'material/react';
import { videoIcon, photoIcon, audioIcon } from './app';

export function Example() {
  const [value, setValue] = useState("video");
  return (
    <Tabs value={value} onChange={(event) => setValue(event.detail.value)}>
      <Tab value="video" icon={videoIcon}>Video</Tab>
      <Tab value="photos" icon={photoIcon} badge="3">Photos</Tab>
      <Tab value="audio" icon={audioIcon}>Audio</Tab>
    </Tabs>
  );
}
Vue
<script setup lang="ts">
import { ref } from 'vue';
import { MTabs, MTab } from 'material/vue';
import { videoIcon, photoIcon, audioIcon } from './app';

const value = ref("video");
</script>

<template>
  <MTabs v-model="value">
    <MTab value="video" :icon="videoIcon">Video</MTab>
    <MTab value="photos" :icon="photoIcon" badge="3">Photos</MTab>
    <MTab value="audio" :icon="audioIcon">Audio</MTab>
  </MTabs>
</template>
Svelte
<script lang="ts">
  import { Tabs, Tab } from 'material/svelte';
  import { videoIcon, photoIcon, audioIcon } from './app';

  let value = $state("video");
</script>

<Tabs bind:value>
  <Tab value="video" icon={videoIcon}>Video</Tab>
  <Tab value="photos" icon={photoIcon} badge="3">Photos</Tab>
  <Tab value="audio" icon={audioIcon}>Audio</Tab>
</Tabs>
SolidJS
import { createSignal } from 'solid-js';
import { Tabs, Tab } from 'material/solid';
import { videoIcon, photoIcon, audioIcon } from './app';

export function Example() {
  const [value, setValue] = createSignal("video");
  return (
    <Tabs value={value()} onChange={(event) => setValue(event.detail.value)}>
      <Tab value="video" icon={videoIcon}>Video</Tab>
      <Tab value="photos" icon={photoIcon} badge="3">Photos</Tab>
      <Tab value="audio" icon={audioIcon}>Audio</Tab>
    </Tabs>
  );
}

Secondary

Vanilla
import { createTabs } from 'material';

const tabs = createTabs({
  variant: 'secondary',
  tabs: [
    { text: 'Overview', value: 'overview', state: 'active' },
    { text: 'Specifications', value: 'specs' },
  ],
});
document.body.append(tabs.element);
Web Components
<m-tabs value="overview" variant="secondary">
  <m-tab value="overview">Overview</m-tab>
  <m-tab value="specs">Specifications</m-tab>
</m-tabs>
React
import { useState } from 'react';
import { Tabs, Tab } from 'material/react';

export function Example() {
  const [value, setValue] = useState("overview");
  return (
    <Tabs value={value} onChange={(event) => setValue(event.detail.value)} variant="secondary">
      <Tab value="overview">Overview</Tab>
      <Tab value="specs">Specifications</Tab>
    </Tabs>
  );
}
Vue
<script setup lang="ts">
import { ref } from 'vue';
import { MTabs, MTab } from 'material/vue';

const value = ref("overview");
</script>

<template>
  <MTabs v-model="value" variant="secondary">
    <MTab value="overview">Overview</MTab>
    <MTab value="specs">Specifications</MTab>
  </MTabs>
</template>
Svelte
<script lang="ts">
  import { Tabs, Tab } from 'material/svelte';

  let value = $state("overview");
</script>

<Tabs bind:value variant="secondary">
  <Tab value="overview">Overview</Tab>
  <Tab value="specs">Specifications</Tab>
</Tabs>
SolidJS
import { createSignal } from 'solid-js';
import { Tabs, Tab } from 'material/solid';

export function Example() {
  const [value, setValue] = createSignal("overview");
  return (
    <Tabs value={value()} onChange={(event) => setValue(event.detail.value)} variant="secondary">
      <Tab value="overview">Overview</Tab>
      <Tab value="specs">Specifications</Tab>
    </Tabs>
  );
}

Panels

Give each panel role="tabpanel", the id tabpanel-<groupId>-<value> and aria-labelledby="tab-<groupId>-<value>", when value is only [A-Za-z0-9_-]. Any other character gets a derived id (tabPanelIdFor) instead of that pattern. The tabs point at their panels with aria-controls, and show and hide them as the selection changes. Pin groupId in the factory's options, or the id is allocated. Keep a pinned group id to [A-Za-z0-9_].

<div role="tabpanel" id="tabpanel-travel-flights" aria-labelledby="tab-travel-flights">…</div>
<div role="tabpanel" id="tabpanel-travel-trips" aria-labelledby="tab-travel-trips" hidden>…</div>

The factory's row scrolls by default; scrollable: false divides it evenly between the tabs (fixed tabs). The web component takes the tabs, variant and the selection.

Set the responsive option on createTabs to switch a tab group's layout on narrow screens. The behaviour is a plugin: import tabsResponsive from material/components/tabs/responsive and pass the result as the option.

import { createTabs } from 'material/components/tabs';
import { tabsResponsive } from 'material/components/tabs/responsive';

const responsiveTabs = createTabs({
  tabs: [
    { text: 'Video', value: 'video', icon: videoIcon, state: 'active' },
    { text: 'Photos', value: 'photos', icon: photoIcon },
  ],
  responsive: tabsResponsive({
    smallScreen: { layout: 'icon-only' },
    breakpoints: { small: 600 },
  }),
});

Below the small breakpoint (600px by default), tabs built with an icon and a label take smallScreen.layout ('icon-only' by default), and the group carries the mtrl-tabs--responsive-small class while it does. The layout applies while the group is created, so a narrow page never paints the built layout first. setupResponsiveBehavior(tabs, config) still works and is deprecated in favour of the option; it is removed in 4.0.

API

Options

tabs

The tabs to build, in order

TypeTabConfig[]
Default[]
variant

Primary or secondary tabs

Type'primary' | 'secondary'
Default'primary'
scrollable

A horizontally scrolling row, 52dp in from both edges. false divides the row evenly between the tabs (fixed tabs)

Typeboolean
Defaulttrue
showDivider

The 1dp divider along the bottom of the row

Typeboolean
Defaulttrue
autoActivate

Whether an arrow key also selects the tab it moves to. By default it only moves focus, and Space or Enter selects

Typeboolean
Defaultfalse
responsive

Responsive layout plugin from tabsResponsive(config) in material/components/tabs/responsive

Type(tabs: TabsComponent) => void
Defaultundefined
indicator

The active indicator (below)

TypeIndicatorConfig
Default{}
groupId

The id every tab's id is built from, tab-<groupId>-<value>. Pin it when ids must survive a re-render

Typestring
Defaultallocated
on

Event handlers registered at creation, as with on()

Type{ change }
Defaultundefined
class

Additional CSS classes on the row

Typestring
Defaultundefined
prefix

Prefix for CSS class names

Typestring
Default'mtrl'

Tab options

Each entry of tabs, and the argument to addTab().

text

The label

Typestring
Defaultundefined
icon

Icon as SVG markup. With a label, the icon sits above it and the row is 64dp tall

Typestring
Defaultundefined
ariaLabel

The accessible name of a tab with an icon and no label; without it the name falls back to the tab's text, then its value, with any badge count joined after

Typestring
Defaultundefined
value

Identifies the tab to change, setActiveTab() and its panel

Typestring
Defaultundefined
state

Whether the tab starts active

Type'active' | 'inactive'
Default'inactive'
disabled

Whether the tab starts disabled

Typeboolean
Defaultfalse
badge

Badge content; keep it to four characters, including a "+"

Typestring | number
Defaultundefined
badgeConfig

Options for the badge: variant, color, size, position, max

Typeobject
Defaultundefined
ripple

Whether pressing the tab shows the ripple

Typeboolean
Defaulttrue
class

Additional CSS classes on the tab

Typestring
Defaultundefined

Indicator options

widthStrategy

auto: the label's width inset 2dp on each side (24dp at least) for primary tabs, the whole tab for secondary ones

Type'auto' | 'content' | 'dynamic' | 'fixed'
Default'auto'
height

Height in pixels

Typenumber
Default3 primary, 2 secondary
color

The indicator's color

Typestring
Defaulttheme primary
visible

Whether it starts shown; getIndicator().hide() and show() change it later

Typeboolean
Defaulttrue
fixedWidth

Width for the fixed strategy

Typenumber
Default40
animationDuration

Replaces Material's default spatial spring with a fixed duration in milliseconds

Typenumber
Defaultspring
animationTiming

An easing to use with animationDuration

Typestring
Defaultspring

Methods

Tabs

addTab(config)

Builds a tab and appends it

ReturnsTabComponent
add(tab)

Appends a tab built with createTab

ReturnsTabsComponent
removeTab(tabOrValue)

Removes and destroys a tab

ReturnsTabsComponent
getTabs()

The tabs, in order

ReturnsTabComponent[]
getActiveTab()

The active tab

ReturnsTabComponent | null
setActiveTab(tabOrValue)

Selects a tab, updates its panels and emits change. An unknown value clears the selection

ReturnsTabsComponent
getIndicator()

The indicator: show(), hide(), setColor(), update()

ReturnsTabIndicator
on(event, handler) / off(event, handler)

Events: change

ReturnsTabsComponent
destroy()

Destroys every tab and the row

Returnsvoid

Tab

getValue() / setValue(value)

The tab's value

Returnsstring / TabComponent
isActive()

Whether the tab is selected

Returnsboolean
setText(text) / getText()

The label

ReturnsTabComponent / string
setIcon(icon) / getIcon()

The icon

ReturnsTabComponent / string
setBadge(content) / getBadge() / showBadge() / hideBadge()

The badge

ReturnsTabComponent / string
enable() / disable()

Disabled state

ReturnsTabComponent
on(event, handler) / off(event, handler)

Events: click, focus, blur

ReturnsTabComponent
destroy()

Removes the tab

Returnsvoid

Events

change

The selected tab changed, by pointer, keyboard or setActiveTab(). tab and value are null when an unknown value cleared the selection

Payload{ tab, value }

The web component's change carries { value }.

Styling

.mtrl-tabs { }                          /* the row */
.mtrl-tabs--primary, .mtrl-tabs--secondary, .mtrl-tabs--scrollable { }
.mtrl-tabs__scroll { }                  /* the scrolling container */
.mtrl-tabs__indicator, .mtrl-tabs__divider { }
.mtrl-tabs--responsive-small { }        /* below the small breakpoint */

.mtrl-tab { }                           /* one tab, a button */
.mtrl-tab--active { }
.mtrl-tab--text-only, .mtrl-tab--icon-only, .mtrl-tab--icon-and-text { }
.mtrl-tab-panel { }

Measurements

From the M3 tabs specs, then Compose's PrimaryNavigationTabTokens and SecondaryNavigationTabTokens:

Attribute Value
Height 48dp with a label or an icon, 64dp with both
Label Title Small; primary (primary) or on-surface (secondary) when active, on-surface-variant when inactive
Icon 24dp
Tab padding 16dp on each side
Primary indicator 3dp, primary, top corners 3dp, the label's width inset 2dp on each side, 24dp at least
Secondary indicator 2dp, primary, the tab's full width
Divider 1dp outline-variant, inside the row's height
Scrollable edge 52dp before the first tab and after the last
States An inactive tab turns on-surface on hover, focus and press, over an on-surface layer; a press on a primary tab is primary, drawn by the ripple
Motion The indicator moves on the default spatial spring