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

Navigation rail

Move between destinations. Explore collapsed, expanded, and modal navigation.

InboxFavoritesSent
FactoryWeb ComponentsReactVueSvelteSolidJS
PublishedUpdated

A navigation rail holds three to seven top-level destinations in a column along the side of a medium or expanded window. In M3 Expressive it has two states: collapsed, a 96dp column with the labels under the icons, and expanded, a 220 to 360dp panel with the labels beside them, which replaces the navigation drawer.

Usage

Each destination has an id, a label and an icon; active marks the current one. A badge is a count or a short text, and badgeLabel says what it counts.

Vanilla
import { createNavigationRail } from 'material';

const rail = createNavigationRail({
  ariaLabel: 'Mail',
  items: [
    {
      id: 'inbox',
      label: 'Inbox',
      icon: inboxIcon,
      activeIcon: heartFilledIcon,
      badge: 24,
      badgeLabel: '24 unread',
      active: true,
    },
    { id: 'outbox', label: 'Outbox', icon: outboxIcon },
    { id: 'favorites', label: 'Favorites', icon: starIcon },
  ],
});
document.body.append(rail.element);
Web Components
<m-navigation-rail value="inbox" aria-label="Mail">
  <m-navigation-rail-item value="inbox" badge="24" badge-label="24 unread">Inbox</m-navigation-rail-item>
  <m-navigation-rail-item value="outbox">Outbox</m-navigation-rail-item>
  <m-navigation-rail-item value="favorites">Favorites</m-navigation-rail-item>
</m-navigation-rail>

<script type="module">
  const navigationRail = document.querySelector('m-navigation-rail');
  navigationRail.querySelector('m-navigation-rail-item[value="inbox"]').setAttribute('icon', inboxIcon);
  navigationRail.querySelector('m-navigation-rail-item[value="inbox"]').setAttribute('selected-icon', heartFilledIcon);
  navigationRail.querySelector('m-navigation-rail-item[value="outbox"]').setAttribute('icon', outboxIcon);
  navigationRail.querySelector('m-navigation-rail-item[value="favorites"]').setAttribute('icon', starIcon);
</script>
React
import { useState } from 'react';
import { NavigationRail, NavigationRailItem } from 'material/react';
import { inboxIcon, heartFilledIcon, outboxIcon, starIcon } from './app';

export function Example() {
  const [value, setValue] = useState("inbox");
  return (
    <NavigationRail value={value} onChange={(event) => setValue(event.detail.value)} ariaLabel="Mail">
      <NavigationRailItem value="inbox" icon={inboxIcon} selectedIcon={heartFilledIcon} badge="24" badgeLabel="24 unread">Inbox</NavigationRailItem>
      <NavigationRailItem value="outbox" icon={outboxIcon}>Outbox</NavigationRailItem>
      <NavigationRailItem value="favorites" icon={starIcon}>Favorites</NavigationRailItem>
    </NavigationRail>
  );
}
Vue
<script setup lang="ts">
import { ref } from 'vue';
import { MNavigationRail, MNavigationRailItem } from 'material/vue';
import { inboxIcon, heartFilledIcon, outboxIcon, starIcon } from './app';

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

<template>
  <MNavigationRail v-model="value" aria-label="Mail">
    <MNavigationRailItem value="inbox" :icon="inboxIcon" :selected-icon="heartFilledIcon" badge="24" badge-label="24 unread">Inbox</MNavigationRailItem>
    <MNavigationRailItem value="outbox" :icon="outboxIcon">Outbox</MNavigationRailItem>
    <MNavigationRailItem value="favorites" :icon="starIcon">Favorites</MNavigationRailItem>
  </MNavigationRail>
</template>
Svelte
<script lang="ts">
  import { NavigationRail, NavigationRailItem } from 'material/svelte';
  import { inboxIcon, heartFilledIcon, outboxIcon, starIcon } from './app';

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

<NavigationRail bind:value ariaLabel="Mail">
  <NavigationRailItem value="inbox" icon={inboxIcon} selectedIcon={heartFilledIcon} badge="24" badgeLabel="24 unread">Inbox</NavigationRailItem>
  <NavigationRailItem value="outbox" icon={outboxIcon}>Outbox</NavigationRailItem>
  <NavigationRailItem value="favorites" icon={starIcon}>Favorites</NavigationRailItem>
</NavigationRail>
SolidJS
import { createSignal } from 'solid-js';
import { NavigationRail, NavigationRailItem } from 'material/solid';
import { inboxIcon, heartFilledIcon, outboxIcon, starIcon } from './app';

export function Example() {
  const [value, setValue] = createSignal("inbox");
  return (
    <NavigationRail value={value()} onChange={(event) => setValue(event.detail.value)} ariaLabel="Mail">
      <NavigationRailItem value="inbox" icon={inboxIcon} selectedIcon={heartFilledIcon} badge="24" badgeLabel="24 unread">Inbox</NavigationRailItem>
      <NavigationRailItem value="outbox" icon={outboxIcon}>Outbox</NavigationRailItem>
      <NavigationRailItem value="favorites" icon={starIcon}>Favorites</NavigationRailItem>
    </NavigationRail>
  );
}

Examples

Expanded

The menu button at the top expands and collapses the rail; expanded sets the state it starts in, and expandedWidth its expanded width. A destination with href is a link, and keeps the browser's navigation.

Vanilla
import { createNavigationRail } from 'material';

const rail = createNavigationRail({
  expanded: true,
  expandedWidth: 320,
  items: [
    { id: 'inbox', label: 'Inbox', icon: inboxIcon, active: true },
    { id: 'outbox', label: 'Outbox', icon: outboxIcon, href: '/outbox' },
  ],
});
document.body.append(rail.element);
Web Components
<m-navigation-rail value="inbox" expanded expanded-width="320">
  <m-navigation-rail-item value="inbox">Inbox</m-navigation-rail-item>
  <m-navigation-rail-item value="outbox" href="/outbox">Outbox</m-navigation-rail-item>
</m-navigation-rail>

<script type="module">
  const navigationRail = document.querySelector('m-navigation-rail');
  navigationRail.querySelector('m-navigation-rail-item[value="inbox"]').setAttribute('icon', inboxIcon);
  navigationRail.querySelector('m-navigation-rail-item[value="outbox"]').setAttribute('icon', outboxIcon);
</script>
React
import { useState } from 'react';
import { NavigationRail, NavigationRailItem } from 'material/react';
import { inboxIcon, outboxIcon } from './app';

export function Example() {
  const [value, setValue] = useState("inbox");
  return (
    <NavigationRail value={value} onChange={(event) => setValue(event.detail.value)} expanded expandedWidth={320}>
      <NavigationRailItem value="inbox" icon={inboxIcon}>Inbox</NavigationRailItem>
      <NavigationRailItem value="outbox" icon={outboxIcon} href="/outbox">Outbox</NavigationRailItem>
    </NavigationRail>
  );
}
Vue
<script setup lang="ts">
import { ref } from 'vue';
import { MNavigationRail, MNavigationRailItem } from 'material/vue';
import { inboxIcon, outboxIcon } from './app';

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

<template>
  <MNavigationRail v-model="value" expanded :expanded-width="320">
    <MNavigationRailItem value="inbox" :icon="inboxIcon">Inbox</MNavigationRailItem>
    <MNavigationRailItem value="outbox" :icon="outboxIcon" href="/outbox">Outbox</MNavigationRailItem>
  </MNavigationRail>
</template>
Svelte
<script lang="ts">
  import { NavigationRail, NavigationRailItem } from 'material/svelte';
  import { inboxIcon, outboxIcon } from './app';

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

<NavigationRail bind:value expanded expandedWidth={320}>
  <NavigationRailItem value="inbox" icon={inboxIcon}>Inbox</NavigationRailItem>
  <NavigationRailItem value="outbox" icon={outboxIcon} href="/outbox">Outbox</NavigationRailItem>
</NavigationRail>
SolidJS
import { createSignal } from 'solid-js';
import { NavigationRail, NavigationRailItem } from 'material/solid';
import { inboxIcon, outboxIcon } from './app';

export function Example() {
  const [value, setValue] = createSignal("inbox");
  return (
    <NavigationRail value={value()} onChange={(event) => setValue(event.detail.value)} expanded expandedWidth={320}>
      <NavigationRailItem value="inbox" icon={inboxIcon}>Inbox</NavigationRailItem>
      <NavigationRailItem value="outbox" icon={outboxIcon} href="/outbox">Outbox</NavigationRailItem>
    </NavigationRail>
  );
}

With layout: 'modal', the collapsed rail is hidden and the expanded one opens over the page in a native modal dialog; Escape and the scrim collapse it. hideWhenCollapsed hides a standard rail while it is collapsed.

Vanilla
import { createNavigationRail } from 'material';

const rail = createNavigationRail({
  layout: 'modal',
  items: [
    { id: 'inbox', label: 'Inbox', icon: inboxIcon, active: true },
    { id: 'outbox', label: 'Outbox', icon: outboxIcon },
  ],
});
document.body.append(rail.element);
Web Components
<m-navigation-rail value="inbox" layout="modal">
  <m-navigation-rail-item value="inbox">Inbox</m-navigation-rail-item>
  <m-navigation-rail-item value="outbox">Outbox</m-navigation-rail-item>
</m-navigation-rail>

<script type="module">
  const navigationRail = document.querySelector('m-navigation-rail');
  navigationRail.querySelector('m-navigation-rail-item[value="inbox"]').setAttribute('icon', inboxIcon);
  navigationRail.querySelector('m-navigation-rail-item[value="outbox"]').setAttribute('icon', outboxIcon);
</script>
React
import { useState } from 'react';
import { NavigationRail, NavigationRailItem } from 'material/react';
import { inboxIcon, outboxIcon } from './app';

export function Example() {
  const [value, setValue] = useState("inbox");
  return (
    <NavigationRail value={value} onChange={(event) => setValue(event.detail.value)} layout="modal">
      <NavigationRailItem value="inbox" icon={inboxIcon}>Inbox</NavigationRailItem>
      <NavigationRailItem value="outbox" icon={outboxIcon}>Outbox</NavigationRailItem>
    </NavigationRail>
  );
}
Vue
<script setup lang="ts">
import { ref } from 'vue';
import { MNavigationRail, MNavigationRailItem } from 'material/vue';
import { inboxIcon, outboxIcon } from './app';

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

<template>
  <MNavigationRail v-model="value" layout="modal">
    <MNavigationRailItem value="inbox" :icon="inboxIcon">Inbox</MNavigationRailItem>
    <MNavigationRailItem value="outbox" :icon="outboxIcon">Outbox</MNavigationRailItem>
  </MNavigationRail>
</template>
Svelte
<script lang="ts">
  import { NavigationRail, NavigationRailItem } from 'material/svelte';
  import { inboxIcon, outboxIcon } from './app';

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

<NavigationRail bind:value layout="modal">
  <NavigationRailItem value="inbox" icon={inboxIcon}>Inbox</NavigationRailItem>
  <NavigationRailItem value="outbox" icon={outboxIcon}>Outbox</NavigationRailItem>
</NavigationRail>
SolidJS
import { createSignal } from 'solid-js';
import { NavigationRail, NavigationRailItem } from 'material/solid';
import { inboxIcon, outboxIcon } from './app';

export function Example() {
  const [value, setValue] = createSignal("inbox");
  return (
    <NavigationRail value={value()} onChange={(event) => setValue(event.detail.value)} layout="modal">
      <NavigationRailItem value="inbox" icon={inboxIcon}>Inbox</NavigationRailItem>
      <NavigationRailItem value="outbox" icon={outboxIcon}>Outbox</NavigationRailItem>
    </NavigationRail>
  );
}

A selection emits select with { id, index, originalEvent }; originalEvent.preventDefault() keeps a link's navigation to the app's router. The web component dispatches change with { value }, the destination's id. header puts an element of the app's, such as a FAB, under the menu button; the web component takes it in its header slot.

API

Options

items

Destinations; each needs a unique id, a label and an icon

TypeNavigationRailItemConfig[]
Default[]
expanded

Whether it starts expanded

Typeboolean
Defaultfalse
layout

Standard rails take layout width; modal rails expand over the page in a native dialog

Type'standard' | 'modal'
Default'standard'
hideWhenCollapsed

Hide the standard rail when collapsed (modal rails always do)

Typeboolean
Defaultfalse
expandedWidth

Expanded width in pixels, clamped to 220 to 360

Typenumber
Default280
showToggle

Show the menu button that expands and collapses the rail

Typeboolean
Defaulttrue
expandIcon

Menu button icon while collapsed

Typestring
DefaultMaterial Symbols menu
collapseIcon

Menu button icon while expanded

Typestring
DefaultMaterial Symbols menu_open
expandLabel

Accessible name of the menu button while collapsed

Typestring
Default'Expand navigation'
collapseLabel

Accessible name of the menu button while expanded

Typestring
Default'Collapse navigation'
header

Application-owned element under the menu button, such as a FAB

TypeHTMLElement
Defaultundefined
ripple

Press ripple, clipped to the active indicator

Typeboolean
Defaulttrue
ariaLabel

Accessible name of the rail

Typestring
Default'Primary navigation'
class

Additional CSS classes

Typestring
Defaultundefined
onSelect

Called with { id, index, originalEvent } when a destination is selected

Type(event) => void
Defaultundefined
onExpand / onCollapse

Called when the rail expands (expanded: true) or collapses (expanded: false)

Type({ expanded }) => void
Defaultundefined

Items

id

Unique identifier

Typestring
label

Label text

Typestring
icon

Icon markup

Typestring
activeIcon

Icon markup while active, for a filled variant

Typestring
href

Renders the destination as a link

Typestring
badge

A large badge with text, or true for a dot

Typestring | number | boolean
badgeLabel

Accessible description of the badge

Typestring
active

Initially active

Typeboolean
disabled

Not selectable, and out of the tab order

Typeboolean

Methods

expand() / collapse() / toggle()

Expansion state

ReturnsNavigationRailComponent
isExpanded()

Whether it is expanded

Returnsboolean
setActive(id) / getActive()

The active destination; setActive() emits nothing

ReturnsNavigationRailComponent / string | null
setItems(items) / getItems()

Replace or read the destinations

ReturnsNavigationRailComponent / NavigationRailItemConfig[]
setBadge(id, badge, label?)

Update a badge

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

Events

ReturnsNavigationRailComponent
destroy()

Remove listeners and the element

Returnsvoid

Events

select

A destination was clicked or activated from the keyboard

Payload{ id, value, index, originalEvent }
expand / collapse

The rail expanded or collapsed

Payload{ expanded }

Styling

Selecting a destination grows the secondary-container indicator out of the middle of the item on the spatial spring. Expanding glides the width, the items and the indicator on the same spring, and the label moves beside the icon at the midpoint behind a fade. None of it runs with reduced motion.

.mtrl-navigation-rail { }                                   /* the rail */
.mtrl-navigation-rail--expanded, .mtrl-navigation-rail--modal { }
.mtrl-navigation-rail__toggle { }                           /* the menu button */
.mtrl-navigation-rail__item, .mtrl-navigation-rail__item--active { }
.mtrl-navigation-rail__indicator { }                        /* the active indicator */
.mtrl-navigation-rail__badge { }                            /* --dot for the dot */

Measurements

From the M3 Expressive rail tokens (Android navigationrail, version 34.0.0):

Attribute Collapsed Expanded
Width 96dp 220–360dp, 280dp by default
Destination 64dp tall, the label under the icon 56dp tall, the label beside the icon
Active indicator A 56 × 32dp pill 56dp tall, the item's width less 40dp
Icon 24dp 24dp
Menu button 48dp, 40dp above the destinations 48dp