Skip to content

Material 3

Components

Tabs

Tabs organize content across different screens and views.

9:30

Saved media

Tabs organize groups of related content that are at the same level of hierarchy, and let people switch between them. Use tabs to group related content, not sequential content.

To move between the main destinations of an app, use a navigation bar or a navigation rail instead.

Tabs are composed of four parts, as with React Aria's Tabs:

PartUse
TabsThe container of the row and the panels. It holds the selection.
TabListThe row of tabs
TabA tab. Selecting it shows its panel.
TabPanelWhat a tab shows
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'

Basic tabs

Put a TabList of Tabs and a TabPanel for each tab in Tabs. Give a tab and its panel the same id.

Flights are listed here.
import { Icon, Tab, TabList, TabPanel, Tabs } from '@material-web/react'

export default function Basic() {
  return (
    <Tabs className="w-full">
      <TabList>
        <Tab id="flights">
          <Icon name="flight" />
          Flights
        </Tab>
        <Tab id="trips">
          <Icon name="luggage" />
          Trips
        </Tab>
        <Tab id="explore">
          <Icon name="explore" />
          Explore
        </Tab>
      </TabList>
      <TabPanel id="flights" className="p-space-300 text-body-md">
        Flights are listed here.
      </TabPanel>
      <TabPanel id="trips" className="p-space-300 text-body-md">
        Trips are listed here.
      </TabPanel>
      <TabPanel id="explore" className="p-space-300 text-body-md">
        Places to explore are listed here.
      </TabPanel>
    </Tabs>
  )
}

To render the tabs from data, pass items to the TabList and a function as its children. See Collections.

Tabs come in two variants. Set variant on the Tabs to primary (the default) or secondary.

Primary tabs

Primary tabs show the main content destinations, at the top of the content pane under an app bar. Use them when one set of tabs is needed. A selected primary tab is shown in the primary color, over an indicator as wide as its content.

Flights are listed here.
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'

export default function Primary() {
  return (
    <Tabs>
      <TabList>
        <Tab id="flights">Flights</Tab>
        <Tab id="trips">Trips</Tab>
        <Tab id="explore">Explore</Tab>
      </TabList>
      <TabPanel id="flights" className="p-space-300 text-body-md">
        Flights are listed here.
      </TabPanel>
      <TabPanel id="trips" className="p-space-300 text-body-md">
        Trips are listed here.
      </TabPanel>
      <TabPanel id="explore" className="p-space-300 text-body-md">
        Places to explore are listed here.
      </TabPanel>
    </Tabs>
  )
}

Secondary tabs

Secondary tabs separate related content within a content area, and establish hierarchy. A selected secondary tab is shown over an indicator across the whole tab.

An overview of the product.
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'

export default function Secondary() {
  return (
    <Tabs variant="secondary">
      <TabList>
        <Tab id="overview">Overview</Tab>
        <Tab id="specifications">Specifications</Tab>
      </TabList>
      <TabPanel id="overview" className="p-space-300 text-body-md">
        An overview of the product.
      </TabPanel>
      <TabPanel id="specifications" className="p-space-300 text-body-md">
        Every specification of the product.
      </TabPanel>
    </Tabs>
  )
}

Use secondary tabs when a screen needs more than one level of tabs, and place them below the primary tabs, such as in the panel of a primary tab.

Upcoming flights.
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'

const destinations = ['Flights', 'Trips', 'Explore']

export default function TwoLevels() {
  return (
    <Tabs>
      <TabList>
        {destinations.map((name) => (
          <Tab key={name} id={name}>
            {name}
          </Tab>
        ))}
      </TabList>
      {destinations.map((name) => (
        <TabPanel key={name} id={name}>
          <Tabs variant="secondary">
            <TabList>
              <Tab id="upcoming">Upcoming</Tab>
              <Tab id="past">Past</Tab>
            </TabList>
            <TabPanel id="upcoming" className="p-space-300 text-body-md">
              Upcoming {name.toLowerCase()}.
            </TabPanel>
            <TabPanel id="past" className="p-space-300 text-body-md">
              Past {name.toLowerCase()}.
            </TabPanel>
          </Tabs>
        </TabPanel>
      ))}
    </Tabs>
  )
}

Icons

Write a tab's icon and label as its children. An Icon is sized and colored by the tab. Use icons on every tab of a row, or on none of them.

For a tab with an icon alone, set an aria-label.

Your favorites.
import { Icon, Tab, TabList, TabPanel, Tabs } from '@material-web/react'

export default function Icons() {
  return (
    <Tabs>
      <TabList>
        <Tab id="favorites" aria-label="Favorites">
          <Icon name="favorite" />
        </Tab>
        <Tab id="nearby" aria-label="Nearby">
          <Icon name="location_on" />
        </Tab>
        <Tab id="recent" aria-label="Recent">
          <Icon name="history" />
        </Tab>
      </TabList>
      <TabPanel id="favorites" className="p-space-300 text-body-md">
        Your favorites.
      </TabPanel>
      <TabPanel id="nearby" className="p-space-300 text-body-md">
        What is nearby.
      </TabPanel>
      <TabPanel id="recent" className="p-space-300 text-body-md">
        What you opened recently.
      </TabPanel>
    </Tabs>
  )
}

Selection

Set the initial selection with defaultSelectedKey, or control it with selectedKey and onSelectionChange, as with React Aria's selection. The key is the id of the selected tab. With neither, the first tab is selected.

Selected: Trips
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'
import { useState } from 'react'
import type { Key } from 'react-aria-components'

const destinations = ['Flights', 'Trips', 'Explore']

export default function Controlled() {
  const [selected, setSelected] = useState<Key>('Trips')
  return (
    <Tabs selectedKey={selected} onSelectionChange={setSelected}>
      <TabList>
        {destinations.map((name) => (
          <Tab key={name} id={name}>
            {name}
          </Tab>
        ))}
      </TabList>
      {destinations.map((name) => (
        <TabPanel key={name} id={name} className="p-space-300 text-body-md">
          Selected: {String(selected)}
        </TabPanel>
      ))}
    </Tabs>
  )
}

A mouse selects a tab when it is pressed, and a touch when it is released.

Keyboard activation

Set keyboardActivation to manual (the default) or automatic. With manual, the arrow keys move the focus between the tabs, and Space or Enter selects the focused one. With automatic, the arrow keys select the tab they move to.

Flights are listed here.
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'

export default function AutomaticActivation() {
  return (
    <Tabs keyboardActivation="automatic">
      <TabList>
        <Tab id="flights">Flights</Tab>
        <Tab id="trips">Trips</Tab>
        <Tab id="explore">Explore</Tab>
      </TabList>
      <TabPanel id="flights" className="p-space-300 text-body-md">
        Flights are listed here.
      </TabPanel>
      <TabPanel id="trips" className="p-space-300 text-body-md">
        Trips are listed here.
      </TabPanel>
      <TabPanel id="explore" className="p-space-300 text-body-md">
        Places to explore are listed here.
      </TabPanel>
    </Tabs>
  )
}

Keeping panels mounted

A TabPanel is rendered only while its tab is selected, so what a person entered in it is lost when they switch tabs. Set shouldForceMount on a panel to keep it rendered. A panel whose tab is not selected is then inert, and it is still shown: hide it with a class such as inert:hidden.

import { Tab, TabList, TabPanel, Tabs, TextField } from '@material-web/react'

export default function KeepMounted() {
  return (
    <Tabs>
      <TabList>
        <Tab id="outbound">Outbound</Tab>
        <Tab id="return">Return</Tab>
      </TabList>
      <TabPanel id="outbound" shouldForceMount className="p-space-300 inert:hidden">
        <TextField label="Notes for the outbound flight" className="w-full" />
      </TabPanel>
      <TabPanel id="return" shouldForceMount className="p-space-300 inert:hidden">
        <TextField label="Notes for the return flight" className="w-full" />
      </TabPanel>
    </Tabs>
  )
}

Disabled

Set isDisabled on a Tab to disable it, or list its id in the disabledKeys of the Tabs. A disabled tab cannot be selected or focused, and the arrow keys skip it. Set isDisabled on the Tabs to disable every tab.

Flights are listed here.
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'

export default function Disabled() {
  return (
    <Tabs disabledKeys={['explore']}>
      <TabList>
        <Tab id="flights">Flights</Tab>
        <Tab id="trips" isDisabled>
          Trips
        </Tab>
        <Tab id="explore">Explore</Tab>
        <Tab id="saved">Saved</Tab>
      </TabList>
      <TabPanel id="flights" className="p-space-300 text-body-md">
        Flights are listed here.
      </TabPanel>
      <TabPanel id="trips" className="p-space-300 text-body-md">
        Trips are listed here.
      </TabPanel>
      <TabPanel id="explore" className="p-space-300 text-body-md">
        Places to explore are listed here.
      </TabPanel>
      <TabPanel id="saved" className="p-space-300 text-body-md">
        Saved places are listed here.
      </TabPanel>
    </Tabs>
  )
}

Icon position

The variant places the icon of a tab that has a label too:

VariantIconRow height
primaryOver the label64dp
secondaryBefore the label48dp

A row of tabs with a label alone, or an icon alone, is 48dp tall.

A primary tab stacks its icon over its label.
A secondary tab puts its icon before its label.
import { Icon, Tab, TabList, TabPanel, Tabs } from '@material-web/react'

export default function IconPosition() {
  return (
    <div className="flex flex-col gap-space-300">
      <Tabs>
        <TabList>
          <Tab id="overview">
            <Icon name="summarize" />
            Overview
          </Tab>
          <Tab id="specifications">
            <Icon name="list_alt" />
            Specifications
          </Tab>
        </TabList>
        <TabPanel id="overview" className="p-space-300 text-body-md">
          A primary tab stacks its icon over its label.
        </TabPanel>
        <TabPanel id="specifications" className="p-space-300 text-body-md">
          Every specification of the product.
        </TabPanel>
      </Tabs>
      <Tabs variant="secondary">
        <TabList>
          <Tab id="overview">
            <Icon name="summarize" />
            Overview
          </Tab>
          <Tab id="specifications">
            <Icon name="list_alt" />
            Specifications
          </Tab>
        </TabList>
        <TabPanel id="overview" className="p-space-300 text-body-md">
          A secondary tab puts its icon before its label.
        </TabPanel>
        <TabPanel id="specifications" className="p-space-300 text-body-md">
          Every specification of the product.
        </TabPanel>
      </Tabs>
    </div>
  )
}

Fixed tabs

By default, the tabs are fixed: they show all at once and divide the row equally, whatever the length of their labels. Fixed tabs are best for switching between related content quickly, such as between transportation methods in a map.

Routes by car.
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'

export default function Fixed() {
  return (
    <Tabs>
      <TabList>
        <Tab id="driving">Driving</Tab>
        <Tab id="transit">Public transit</Tab>
        <Tab id="walking">Walking</Tab>
      </TabList>
      <TabPanel id="driving" className="p-space-300 text-body-md">
        Routes by car.
      </TabPanel>
      <TabPanel id="transit" className="p-space-300 text-body-md">
        Routes by bus and train.
      </TabPanel>
      <TabPanel id="walking" className="p-space-300 text-body-md">
        Routes on foot.
      </TabPanel>
    </Tabs>
  )
}

The row is as wide as the Tabs. To make it narrower than its container, set a width on the Tabs in className.

Scrollable tabs

When a set of tabs cannot fit on screen, set isScrollable on the TabList. Each tab is then as wide as its label, and the row scrolls sideways. Scrollable tabs can have longer labels and a larger number of tabs, and are best for browsing on touch screens.

About the Alaskan.
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'

const breeds = [
  'Akita',
  'Alaskan',
  'Australian Shepherd',
  'Azawakh',
  'Barbet',
  'Basenji',
  'Beagle',
  'Border Collie',
  'Boxer',
  'Bulldog',
  'Chihuahua',
  'Dalmatian',
]

export default function Scrollable() {
  return (
    <Tabs defaultSelectedKey="Alaskan">
      <TabList isScrollable>
        {breeds.map((breed) => (
          <Tab key={breed} id={breed}>
            {breed}
          </Tab>
        ))}
      </TabList>
      {breeds.map((breed) => (
        <TabPanel key={breed} id={breed} className="p-space-300 text-body-md">
          About the {breed}.
        </TabPanel>
      ))}
    </Tabs>
  )
}

A scrollable row scrolls to the selected tab, and to a tab that the keyboard focuses. Its first and last tab are 52dp from the ends of the row.

Long labels

A label wraps when its tab is too narrow for it, and the row grows with it. To limit a label to two lines, put it in an element of your own with line-clamp-2.

Flights are listed here.
Flights are listed here.
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'

export default function LongLabels() {
  return (
    <>
      <Tabs className="w-80">
        <TabList>
          <Tab id="flights">Flights</Tab>
          <Tab id="trips">Trips and itineraries you have planned</Tab>
          <Tab id="explore">Explore</Tab>
        </TabList>
        <TabPanel id="flights" className="p-space-300 text-body-md">
          Flights are listed here.
        </TabPanel>
        <TabPanel id="trips" className="p-space-300 text-body-md">
          Trips are listed here.
        </TabPanel>
        <TabPanel id="explore" className="p-space-300 text-body-md">
          Places to explore are listed here.
        </TabPanel>
      </Tabs>
      <Tabs className="w-80">
        <TabList>
          <Tab id="flights">Flights</Tab>
          <Tab id="trips">
            <span className="line-clamp-2">Trips and itineraries you have planned</span>
          </Tab>
          <Tab id="explore">Explore</Tab>
        </TabList>
        <TabPanel id="flights" className="p-space-300 text-body-md">
          Flights are listed here.
        </TabPanel>
        <TabPanel id="trips" className="p-space-300 text-body-md">
          Trips are listed here.
        </TabPanel>
        <TabPanel id="explore" className="p-space-300 text-body-md">
          Places to explore are listed here.
        </TabPanel>
      </Tabs>
    </>
  )
}

Orientation

Set orientation="vertical" on the Tabs to stack the tabs in a column beside their panels. Each tab is as tall as its content, and the column is as wide as its widest tab, with the divider and the active indicator at its inline end. The up and down arrow keys then move between the tabs.

Account settings are listed here.
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'

export default function Vertical() {
  return (
    <Tabs orientation="vertical" className="w-full">
      <TabList>
        <Tab id="account">Account</Tab>
        <Tab id="notifications">Notifications</Tab>
        <Tab id="privacy">Privacy</Tab>
      </TabList>
      <TabPanel id="account" className="p-space-300 text-body-md">
        Account settings are listed here.
      </TabPanel>
      <TabPanel id="notifications" className="p-space-300 text-body-md">
        Notification settings are listed here.
      </TabPanel>
      <TabPanel id="privacy" className="p-space-300 text-body-md">
        Privacy settings are listed here.
      </TabPanel>
    </Tabs>
  )
}

With isScrollable on the TabList, the column scrolls up and down when it is taller than the Tabs. Set a height on the Tabs in className to limit it.

Give a tab an href to make it a link, for tabs that move between the pages of an app. Pressing a link tab follows its link and does not change the selection, so set selectedKey from the current location.

The location is #flights.
import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'
import { useState } from 'react'
import { RouterProvider } from 'react-aria-components'

export default function NavTabs() {
  // Stands in for the app's router: it keeps the current location in state.
  const [location, setLocation] = useState('#flights')
  return (
    <RouterProvider navigate={setLocation}>
      <Tabs selectedKey={location}>
        <TabList>
          <Tab id="#flights" href="#flights">
            Flights
          </Tab>
          <Tab id="#trips" href="#trips">
            Trips
          </Tab>
          <Tab id="#explore" href="#explore">
            Explore
          </Tab>
        </TabList>
        <TabPanel id={location} className="p-space-300 text-body-md">
          The location is {location}.
        </TabPanel>
      </Tabs>
    </RouterProvider>
  )
}

Third-party routing library

A tab's link goes through React Aria's RouterProvider. Wrap the app in it once to follow the links with a client-side router, in place of a full page load. See Routing.

With React Router, read the selected tab from the location:

import { Tab, TabList, TabPanel, Tabs } from '@material-web/react'
import { Outlet, useLocation } from 'react-router'

function SectionTabs() {
  const { pathname } = useLocation()
  return (
    <Tabs selectedKey={pathname}>
      <TabList>
        <Tab id="/flights" href="/flights">
          Flights
        </Tab>
        <Tab id="/trips" href="/trips">
          Trips
        </Tab>
      </TabList>
      <TabPanel id={pathname}>
        <Outlet />
      </TabPanel>
    </Tabs>
  )
}

Customization

Each part takes its own className: Tabs, TabList, Tab and TabPanel. A class of yours replaces the part's own class for the same property. See Styling for the classes, the states and the theme.

Pass a function as a tab's children to render them from its state: isHovered, isPressed, isFocused, isFocusVisible, isSelected and isDisabled. In this example, the icon of the selected tab is filled.

Flights are listed here.
import { Icon, Tab, TabList, TabPanel, Tabs } from '@material-web/react'

const destinations = [
  ['Flights', 'flight', 'Flights are listed here.'],
  ['Trips', 'luggage', 'Trips are listed here.'],
  ['Explore', 'explore', 'Places to explore are listed here.'],
] as const

export default function FunctionChildren() {
  return (
    <Tabs>
      <TabList>
        {destinations.map(([name, icon]) => (
          <Tab key={name} id={name}>
            {({ isSelected }) => (
              <>
                <Icon name={icon} className={isSelected ? 'icon-filled' : undefined} />
                {name}
              </>
            )}
          </Tab>
        ))}
      </TabList>
      {destinations.map(([name, , text]) => (
        <TabPanel key={name} id={name} className="p-space-300 text-body-md">
          {text}
        </TabPanel>
      ))}
    </Tabs>
  )
}
  • Color: The label of a selected primary tab and the active indicator of both variants use the primary color role. To change them together, set that role on the Tabs. See Theme.
  • Density: Add density-1, density-2 or density-3 to the Tabs, or to an element around it. Each step makes the row 4dp shorter. See Density.
  • States: Style a tab's state with its variant, such as hover:, selected: or disabled:. See States.
  • Functions: The children of a TabPanel can be a function of isFocused, isFocusVisible and isInert, and the children of Tabs a function of its orientation. The className and style of a TabList can be functions of its state. See Children as a function.
  • Every tab: To restyle all the tabs at once, change the theme.

Limitations

Scroll buttons

A scrollable row has no scroll buttons and shows no scrollbar. People scroll it with a swipe, a trackpad or the keyboard.