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

App bar

Give a view its title and actions. Explore bar sizes and the scrolled appearance.

FactoryWeb ComponentsReactVueSvelteSolidJS
PublishedUpdated

An app bar shows the current screen's title, a navigation button and the screen's most important actions. M3 has four types: small and center-aligned, one 64dp row, and medium and large, with the headline on a second row, which compress to the small bar as the page scrolls.

Usage

The leading button is the navigation icon; the actions go at the trailing end. Icon buttons need ariaLabel to name them.

Vanilla
import { createAppBar, createIconButton } from 'material';

const topBar = createAppBar({ title: 'Inbox' });
topBar.addLeadingElement(createIconButton({ icon: backIcon, ariaLabel: 'Back' }).element);
topBar.addTrailingElement(createIconButton({ icon: searchIcon, ariaLabel: 'Search' }).element);
topBar.addTrailingElement(createIconButton({ icon: moreIcon, ariaLabel: 'More options' }).element);
document.body.append(topBar.element);
Web Components
<m-top-app-bar headline="Inbox">
  <m-icon-button slot="leading" aria-label="Back"></m-icon-button>
  <m-icon-button slot="trailing" aria-label="Search"></m-icon-button>
  <m-icon-button slot="trailing" aria-label="More options"></m-icon-button>
</m-top-app-bar>

<script type="module">
  const topAppBar = document.querySelector('m-top-app-bar');
  topAppBar.querySelector('m-icon-button[slot="leading"][aria-label="Back"]').setAttribute('icon', backIcon);
  topAppBar.querySelector('m-icon-button[slot="trailing"][aria-label="Search"]').setAttribute('icon', searchIcon);
  topAppBar.querySelector('m-icon-button[slot="trailing"][aria-label="More options"]').setAttribute('icon', moreIcon);
</script>
React
import { TopAppBar, IconButton } from 'material/react';
import { backIcon, searchIcon, moreIcon } from './app';

export function Example() {
  return (
    <TopAppBar headline="Inbox">
      <IconButton slot="leading" icon={backIcon} ariaLabel="Back" />
      <IconButton slot="trailing" icon={searchIcon} ariaLabel="Search" />
      <IconButton slot="trailing" icon={moreIcon} ariaLabel="More options" />
    </TopAppBar>
  );
}
Vue
<script setup lang="ts">
import { MTopAppBar, MIconButton } from 'material/vue';
import { backIcon, searchIcon, moreIcon } from './app';
</script>

<template>
  <MTopAppBar headline="Inbox">
    <template #leading>
      <MIconButton :icon="backIcon" aria-label="Back" />
    </template>
    <template #trailing>
      <MIconButton :icon="searchIcon" aria-label="Search" />
      <MIconButton :icon="moreIcon" aria-label="More options" />
    </template>
  </MTopAppBar>
</template>
Svelte
<script lang="ts">
  import { TopAppBar, IconButton } from 'material/svelte';
  import { backIcon, searchIcon, moreIcon } from './app';
</script>

<TopAppBar headline="Inbox">
  {#snippet leading()}
    <IconButton icon={backIcon} ariaLabel="Back" />
  {/snippet}
  {#snippet trailing()}
    <IconButton icon={searchIcon} ariaLabel="Search" />
    <IconButton icon={moreIcon} ariaLabel="More options" />
  {/snippet}
</TopAppBar>
SolidJS
import { TopAppBar, IconButton } from 'material/solid';
import { backIcon, searchIcon, moreIcon } from './app';

export function Example() {
  return (
    <TopAppBar headline="Inbox">
      <IconButton slot="leading" icon={backIcon} ariaLabel="Back" />
      <IconButton slot="trailing" icon={searchIcon} ariaLabel="Search" />
      <IconButton slot="trailing" icon={moreIcon} ariaLabel="More options" />
    </TopAppBar>
  );
}

Examples

A large bar that compresses

Past scrollThreshold pixels of window scroll, the bar takes its scrolled state: surface-container and one level of elevation. A medium or large bar also compresses to 64dp, its headline moving into the top row as Title Large; compressible: false keeps its height.

Vanilla
import { createAppBar } from 'material';

const topBar = createAppBar({ type: 'large', title: 'Photos', scrollThreshold: 8 });
document.body.append(topBar.element);
Web Components
<m-top-app-bar type="large" headline="Photos" scroll-threshold="8"></m-top-app-bar>
React
import { TopAppBar } from 'material/react';

export function Example() {
  return (
    <TopAppBar type="large" headline="Photos" scrollThreshold={8} />
  );
}
Vue
<script setup lang="ts">
import { MTopAppBar } from 'material/vue';
</script>

<template>
  <MTopAppBar type="large" headline="Photos" :scroll-threshold="8" />
</template>
Svelte
<script lang="ts">
  import { TopAppBar } from 'material/svelte';
</script>

<TopAppBar type="large" headline="Photos" scrollThreshold={8} />
SolidJS
import { TopAppBar } from 'material/solid';

export function Example() {
  return (
    <TopAppBar type="large" headline="Photos" scrollThreshold={8} />
  );
}

Following another scroller

scrollable: false stops the bar following the window. A bar over its own scrolling container is driven with setScrollState(scrolled); the web component follows the element whose id scroll-target names.

Vanilla
import { createAppBar } from 'material';

const topBar = createAppBar({ type: 'medium', title: 'Messages', scrollable: false });
document.body.append(topBar.element);
Web Components
<m-top-app-bar type="medium" headline="Messages" no-scroll></m-top-app-bar>
React
import { TopAppBar } from 'material/react';

export function Example() {
  return (
    <TopAppBar type="medium" headline="Messages" noScroll />
  );
}
Vue
<script setup lang="ts">
import { MTopAppBar } from 'material/vue';
</script>

<template>
  <MTopAppBar type="medium" headline="Messages" no-scroll />
</template>
Svelte
<script lang="ts">
  import { TopAppBar } from 'material/svelte';
</script>

<TopAppBar type="medium" headline="Messages" noScroll />
SolidJS
import { TopAppBar } from 'material/solid';

export function Example() {
  return (
    <TopAppBar type="medium" headline="Messages" noScroll />
  );
}

The bar is position: absolute at the top of its container, so that container needs position: relative. setType() switches the type and keeps what is in the leading and trailing containers.

API

Options

type

Height and headline placement

Type'small' | 'center' | 'medium' | 'large'
Default'small'
title

The headline

Typestring
scrollable

Follow window scrolling and toggle the scrolled state

Typeboolean
Defaulttrue
compressible

Let a medium or large bar compress to small once scrolled

Typeboolean
Defaulttrue
scrollThreshold

Pixels of scroll before the scrolled state turns on

Typenumber
Default4
onScroll

Called each time the scrolled state flips

Type(scrolled: boolean) => void
tag

The element to build the bar from

Typestring
Default'header'
class

Extra classes on the element

Typestring
prefix

Class-name prefix

Typestring
Default'mtrl'
componentName

Name used in class generation

Typestring
Default'top-app-bar'

Methods

setTitle(title) / getTitle()

The headline

ReturnsTopAppBar / string
addLeadingElement(element)

Appends to the leading container

ReturnsTopAppBar
addTrailingElement(element)

Appends to the trailing container

ReturnsTopAppBar
setType(type)

Switches type, keeping the containers and their contents

ReturnsTopAppBar
setScrollState(scrolled)

Turns the scrolled state on or off

ReturnsTopAppBar
getHeadlineElement()

The <h1> holding the headline

ReturnsHTMLElement
getLeadingContainer() / getTrailingContainer()

The containers

ReturnsHTMLElement
destroy()

Removes the bar and its window scroll listener

Returnsvoid

Events

The bar emits no events: onScroll reports the scrolled state, once per change.

Styling

The small type has no modifier class. The colors are the theme's: surface behind on-surface, and surface-container once scrolled.

.mtrl-top-app-bar { }
.mtrl-top-app-bar--center, .mtrl-top-app-bar--medium, .mtrl-top-app-bar--large { }
.mtrl-top-app-bar--compressible, .mtrl-top-app-bar--scrolled { }
.mtrl-top-app-bar__leading, .mtrl-top-app-bar__headline, .mtrl-top-app-bar__trailing { }
.mtrl-top-app-bar__row { }   /* medium and large only */

Measurements

Attribute Value
Height 64dp small and center; 112dp medium; 152dp large; 64dp compressed
Headline Title Large (small, center, compressed); Headline Small (medium); Headline Medium (large)
Horizontal padding 16dp, 12dp below the sm breakpoint
Space after the leading button 24dp
Space between actions 8dp
Scrolled Elevation level 2