MDUIDocs
Copy llms.txt linkCopy llms-full.txt linkView this page in MarkdownDiscuss this page with ChatGPTDiscuss full project docs with ChatGPT
Preset Colors
Custom Color
Extract from Wallpaper
Please select a wallpaper
Getting Started
AI-Assisted Development
Styles
Integration with Frameworks
Components
Avatar Badge BottomAppBar Button ButtonIcon Card Checkbox Chip CircularProgress Collapse Dialog Divider Dropdown Fab Icon Layout LinearProgress List Menu NavigationBar NavigationDrawer NavigationRail Radio RangeSlider Select SegmentedButton Slider Snackbar Switch Tabs TextField Tooltip TopAppBar
Functions
Libraries

NavigationRail

The navigation rail lets you switch between primary pages on tablets and desktop computers.

Usage

Import the component:

import 'mdui/components/navigation-rail.js';
import 'mdui/components/navigation-rail-item.js';

Import the TypeScript type:

import type { NavigationRail } from 'mdui/components/navigation-rail.js';
import type { NavigationRailItem } from 'mdui/components/navigation-rail-item.js';

Example: (Note: The style="position: relative" in the example is for demonstration purposes. Don't include it in production.)

Recent Images Library
<mdui-navigation-rail value="recent" style="position: relative">
  <mdui-navigation-rail-item icon="watch_later--outlined" value="recent">Recent</mdui-navigation-rail-item>
  <mdui-navigation-rail-item icon="image--outlined" value="images">Images</mdui-navigation-rail-item>
  <mdui-navigation-rail-item icon="library_music--outlined" value="library">Library</mdui-navigation-rail-item>
</mdui-navigation-rail>

Notes:

By default, this component uses the position: fixed style and automatically adds padding-left or padding-right to the body to prevent content from being obscured.

However, it falls back to position: absolute in the following cases:

  1. When the contained property of the <mdui-navigation-rail> component is true. In this case, it adds padding-left or padding-right style to the parent element.
  2. When the component is used inside the <mdui-layout></mdui-layout> component. In this case, padding-left or padding-right style is not added.

Examples

In Container

By default, the navigation rail appears on the left or right side of the viewport. To place it inside a container, add the contained attribute to the <mdui-navigation-rail> component. This makes the navigation rail position itself relative to the parent element (you need to add position: relative style to the parent element).

Right Placement

Set the placement attribute of the <mdui-navigation-rail> component to right to display the navigation rail on the right.

Display a Divider

Add the divider attribute to the <mdui-navigation-rail> component to add a divider to the navigation rail, distinguishing it from the page content.

Top/Bottom Elements

Inside the <mdui-navigation-rail> component, you can use the top and bottom slots to add elements at the top and bottom.

Vertical Alignment

Set the alignment attribute of the <mdui-navigation-rail> component to modify the vertical alignment of navigation items.

Icons

Use the icon attribute on the <mdui-navigation-rail-item> component to set the icon for the inactive state of the navigation item. The active-icon attribute sets the icon for the active state. Alternatively, use the icon and active-icon slots for the inactive and active states respectively.

Icon Only

The <mdui-navigation-rail-item> component can display icons without labels.

Use the href attribute on the <mdui-navigation-rail-item> component to turn the navigation item into a link. The download, target, and rel attributes are available for link-related functionality.

Badge

Add a badge to the <mdui-navigation-rail-item> component using the badge slot.

AttributePropertyReflectTypeDefault

Specifies the Material Icons name for the inactive state. Alternatively, use slot="icon".

Specifies the Material Icons name for the active state. Alternatively, use slot="active-icon".

The value of the navigation item.

The URL for the link. When set, the component renders as an <a> element and supports link-related attributes.

Downloads the linked URL.

Note: Only available when href is specified.

Controls where the linked URL opens. Possible values:

  • _blank: Opens in a new tab or window.
  • _parent: Opens in the parent browsing context, or _self if there is no parent.
  • _self: Opens in the current browsing context (default).
  • _top: Opens in the topmost browsing context, or _self if there are no ancestors.

Note: Only available when href is specified.

Specifies the relationship of the linked URL as space-separated link types. Possible values:

  • alternate: An alternate version of the current document.
  • author: The author of the current document or article.
  • bookmark: The permalink for the nearest ancestor section.
  • external: The referenced document is not part of the same site as the current document.
  • help: A link to context-sensitive help.
  • license: Content covered by the copyright license described by the referenced document.
  • me: Links to content owned by the current document's author.
  • next: The next document in the series.
  • nofollow: Not endorsed by the original author or publisher.
  • noreferrer: Prevents the Referer header from being sent. Same effect as noopener.
  • opener: Creates a new browsing context when the hyperlink would otherwise open in a top-level context that is not auxiliary (for example, when target="_blank" is specified).
  • prev: The previous document in the series.
  • search: Links to a resource that can be used to search through the current document and its related pages.
  • tag: Marks the current document with the given tag.

Note: Only available when href is specified.

Whether the element is focused when the page loads.

The element's tab order when navigating with the Tab key.

NameParametersReturns

Simulates a mouse click on the element.

Sets focus on the element. An optional object parameter may include a preventScroll property. If preventScroll is set to true, the page will not scroll to bring the focused element into view.

Removes focus from the element.

Name

Emitted when the navigation rail item gains focus.

Emitted when the navigation rail item loses focus.

Name

Text.

Icon.

Icon for the active state.

Badge.

Name

Container for the navigation item.

Indicator.

Badge.

Icon.

Icon for the active state.

Text.

Name

The corner radius of the indicator. You can use a specific pixel value, but it is recommended to reference design tokens.

AttributePropertyReflectTypeDefault

The value of the selected <mdui-navigation-rail-item>.

Sets the navigation rail's position. Possible values:

  • left: Displays on the left.
  • right: Displays on the right.

Sets the alignment of <mdui-navigation-rail-item> elements. Possible values:

  • start: Aligns to the top.
  • center: Aligns to the center.
  • end: Aligns to the bottom.

By default, the navigation rail is positioned relative to the body element. If set, it is positioned relative to its parent element.

Note: You must manually set position: relative; on the parent element when this attribute is set.

Adds a divider between the navigation rail and the page content.

Specifies the layout order within the <mdui-layout> component. Items are sorted in ascending order. The default value is 0.

Name

Emitted when the value changes.

Name

Contains <mdui-navigation-rail-item> components.

Top element.

Bottom element.

Name

Container for the top element.

Container for the bottom element.

Container for <mdui-navigation-rail-item> components.

Name

The corner radius of the component. You can use a specific pixel value, but it is recommended to reference design tokens.

The CSS z-index value of the component.

On this page