Skip to main content brightness_auto motion_photos_off palette download more_vert
toc

Menus

Menus show a temporary set of actions or choices, opened from a button, a text field or a context.

File New Open Save
<md-gb-button popovertarget="file-menu">File</md-gb-button>
<md-gb-menu id="file-menu">
  <md-gb-menu-item>New</md-gb-menu-item>
  <md-gb-menu-item>Open</md-gb-menu-item>
  <md-gb-menu-item disabled>Save</md-gb-menu-item>
</md-gb-menu>

Install with shadcn/ui: npx shadcn@latest add https://material-web.dev/3.0/r/md-menu.json (setup)

  • Use it for temporary actions. A menu shows a short set of actions on demand. To show actions on screen at all times, use a toolbar.
  • Open it from many places. A menu can open from a button, an icon button, a split button or a text field, or as a context menu.
  • Organize long menus. Use groups with labels and dividers to separate related choices.
  • Choose a color. The standard color suits most menus; vibrant makes the selected items stand out.

A menu holds items, groups and dividers. An item holds a label and optional slots, including a submenu.

HTMLTS
<md-gb-button id="more">More</md-gb-button>
<md-gb-menu id="more-menu">
  <md-gb-menu-group>
    <md-gb-menu-item>
      <md-gb-icon slot="leading">share</md-gb-icon>
      Share
      <span slot="supporting-text">Send a link</span>
      <span slot="trailing-text">Ctrl+S</span>
      <md-gb-icon slot="trailing">chevron_right</md-gb-icon>
      <md-gb-menu slot="submenu">
        <md-gb-menu-item>Email</md-gb-menu-item>
        <md-gb-menu-item>Messages</md-gb-menu-item>
      </md-gb-menu>
    </md-gb-menu-item>
  </md-gb-menu-group>
  <md-gb-divider></md-gb-divider>
  <md-gb-menu-item>Delete</md-gb-menu-item>
</md-gb-menu>

A menu is a popover. Point an md-gb-button (or md-gb-icon-button, or a native button) at it with popovertarget, or call showPopover() from script. The menu positions itself next to the button and closes on Escape, when focus leaves, or when an item is chosen.

Sort Name Date modified Size
<md-gb-button popovertarget="sort-menu">Sort</md-gb-button>
<md-gb-menu id="sort-menu">
  <md-gb-menu-item>Name</md-gb-menu-item>
  <md-gb-menu-item>Date modified</md-gb-menu-item>
  <md-gb-menu-item>Size</md-gb-menu-item>
</md-gb-menu>

Fill the leading, supporting-text, trailing-text and trailing slots to add detail to an item.

Edit content_cut Cut Ctrl+X content_copy Copy Ctrl+C content_paste Paste Ctrl+V
<md-gb-button popovertarget="edit-menu">Edit</md-gb-button>
<md-gb-menu id="edit-menu">
  <md-gb-menu-item>
    <md-gb-icon slot="leading">content_cut</md-gb-icon>
    Cut
    <span slot="trailing-text">Ctrl+X</span>
  </md-gb-menu-item>
  <md-gb-menu-item>
    <md-gb-icon slot="leading">content_copy</md-gb-icon>
    Copy
    <span slot="trailing-text">Ctrl+C</span>
  </md-gb-menu-item>
  <md-gb-menu-item>
    <md-gb-icon slot="leading">content_paste</md-gb-icon>
    Paste
    <span slot="trailing-text">Ctrl+V</span>
  </md-gb-menu-item>
</md-gb-menu>

Wrap related items in an md-gb-menu-group. Set label for a heading, and checkable to single or multiple to make the items selectable like radio buttons or checkboxes. Use checked on the selected items.

View Name Date modified Hidden files File extensions
<md-gb-button popovertarget="view-menu">View</md-gb-button>
<md-gb-menu id="view-menu">
  <md-gb-menu-group label="Sort by" checkable="single">
    <md-gb-menu-item checked>Name</md-gb-menu-item>
    <md-gb-menu-item>Date modified</md-gb-menu-item>
  </md-gb-menu-group>
  <md-gb-divider></md-gb-divider>
  <md-gb-menu-group label="Show" checkable="multiple">
    <md-gb-menu-item checked>Hidden files</md-gb-menu-item>
    <md-gb-menu-item>File extensions</md-gb-menu-item>
  </md-gb-menu-group>
</md-gb-menu>

Set layout="grouped" to show each group on its own surface with a gap between them, instead of one surface with dividers.

Actions Undo Redo Cut Copy Paste
<md-gb-button popovertarget="actions-menu">Actions</md-gb-button>
<md-gb-menu id="actions-menu" layout="grouped">
  <md-gb-menu-group>
    <md-gb-menu-item>Undo</md-gb-menu-item>
    <md-gb-menu-item>Redo</md-gb-menu-item>
  </md-gb-menu-group>
  <md-gb-menu-group>
    <md-gb-menu-item>Cut</md-gb-menu-item>
    <md-gb-menu-item>Copy</md-gb-menu-item>
    <md-gb-menu-item>Paste</md-gb-menu-item>
  </md-gb-menu-group>
</md-gb-menu>

Set color="vibrant" to use the tertiary color roles instead of the surface-based standard style.

Theme System Light Dark
<md-gb-button popovertarget="theme-menu">Theme</md-gb-button>
<md-gb-menu id="theme-menu" color="vibrant">
  <md-gb-menu-group checkable="single">
    <md-gb-menu-item checked>System</md-gb-menu-item>
    <md-gb-menu-item>Light</md-gb-menu-item>
    <md-gb-menu-item>Dark</md-gb-menu-item>
  </md-gb-menu-group>
</md-gb-menu>

Put an md-gb-menu in an item's submenu slot. It opens beside the item on click, Enter, Space or the Right arrow key (Left in right-to-left layouts).

Share Copy link Send to Email Message
<md-gb-button popovertarget="share-menu">Share</md-gb-button>
<md-gb-menu id="share-menu">
  <md-gb-menu-item>Copy link</md-gb-menu-item>
  <md-gb-menu-item>
    Send to
    <md-gb-menu slot="submenu">
      <md-gb-menu-item>Email</md-gb-menu-item>
      <md-gb-menu-item>Message</md-gb-menu-item>
    </md-gb-menu>
  </md-gb-menu-item>
</md-gb-menu>

Set context-for to the id of an element to open the menu on a secondary click, the context menu key or a long press.

Right-click or long press this photo
Open in new window Save as Copy link
<div id="photo" tabindex="0">Right-click or long press this photo</div>
<md-gb-menu context-for="photo">
  <md-gb-menu-item>Open in new window</md-gb-menu-item>
  <md-gb-menu-item>Save as</md-gb-menu-item>
  <md-gb-menu-item>Copy link</md-gb-menu-item>
</md-gb-menu>

Set density from 0 (default) down to -3 to remove 4px of height per item for each step. Submenus inherit it. Keep it off by default and let people opt in.

Open Rename Duplicate Delete
<md-gb-button popovertarget="dense-menu">Open</md-gb-button>
<md-gb-menu id="dense-menu" density="-2">
  <md-gb-menu-item>Rename</md-gb-menu-item>
  <md-gb-menu-item>Duplicate</md-gb-menu-item>
  <md-gb-menu-item>Delete</md-gb-menu-item>
</md-gb-menu>
  • The menu has role="menu", and items have role="menuitem", or menuitemradio and menuitemcheckbox in checkable groups.
  • On the button that opens the menu, Up and Down open it and focus the first item; Enter and Space open it natively.
  • In an open menu, Up and Down move between items (disabled items included), Home and End go to the first and last item, and typing a letter jumps to the next item that starts with it.
  • Escape and Tab close the menu and return focus to the button. Left (Right in right-to-left layouts) closes a submenu.
  • Give a menu that has no clear visible title an aria-label.
Material Design 3Spec checked86% tokens

124 of 325 buildable spec units are tested, 35 are excluded with a written reason and 0 are uncovered (the target is 0). 97 of 113 token declarations match the spec (86%), and 16 have no spec token.

BaselineWidely availableChrome 124Edge 124Firefox 125Safari 17.4

The component’s own CSS and JavaScript rely only on web platform features that are Baseline widely available: it works in Chrome 124, Edge 124, Firefox 125, Safari 17.4 and later.

Newer features it uses where the browser has them (progressive enhancements):

WAI-ARIAaxe and ARIA 1.3 passMenu and Menubar

Roles the component renders: group (opens in a new tab), menu (opens in a new tab), menuitem (opens in a new tab), menuitemcheckbox (opens in a new tab), menuitemradio (opens in a new tab).

Follows the WAI-ARIA Authoring Practices: Menu and Menubar (opens in a new tab).

3 rendered states run through axe-core and the WAI-ARIA 1.3 role and attribute rules in a real browser, with no known gaps.

Lighthouse97 · 100 · 100 · 100
  • Performance
  • Accessibility
  • Best practices
  • SEO

Audits under 90:

  • Largest Contentful Paint
  • Largest Contentful Paint element
  • Eliminate render-blocking resources
  • Minify JavaScript
  • Reduce unused CSS
  • Enable text compression
  • Network dependency tree
  • Render blocking requests

Lighthouse 12.8.2 (desktop, 2026-11-08) on the component alone: its first example on a page of its own, without this site's shell. The modules are the development build (not bundled or minified), so the performance score is indicative.

A Material Design component.

Property Attribute Type Default
color
The color style: standard (surface-based) or vibrant (tertiary).
color MenuColor MENU_COLORS.standard
contextFor
The id of an element (in the same root) that opens this menu as a context menu on a secondary click, the context menu key or a long press (menus.md "Context menus ... usually open with a secondary click"; "Performs a specific action to trigger the menu, like right-click or press-and-hold").
context-for string ''
density
The density, from 0 (default) to -3 (menus.md "Density": "On web only, density levels control the spacing between elements. Increasing density decreases the top and bottom padding"). Each step removes 4px from the items' height; submenus inherit it. Values are clamped to that range. Dense items are smaller than the 48px recommended target, so don't apply density by default; let people opt in (grids-spacing.md "Avoid applying component scaling by default").
density Density
filterFor
The id of a text field (in the same root) the menu is attached to. As the person types in it, the menu opens (without taking focus) and shows only the items whose label contains the text, case-insensitively (menus.md "Filtering": "As someone types, the list of menu options filters to show relevant results"). The remaining items ease into their new position ("Menu items ease into their new position as the menu is filtered"), unless motion is reduced. Fires filter with the query.
filter-for string ''
layout
The layout: standard items on one surface, or grouped md-gb-menu-groups on separate surfaces with gaps between them.
layout MenuLayout 'standard'
Slot Description
default The menu's items, groups and dividers.
Method Description
closeAll
() => void
Closes this menu and every menu it is a submenu of.
filter
(query: string) => void
Shows only the items whose label contains query, easing the others into their new position.
showAt
(x: number, y: number) => void
Opens the menu at a point in the viewport (a context menu), keeping it inside the window: it opens below and after the point, and flips when there is no room.
Part Description
::part(menu) The menu's root element.
Property Description
--container-color
--container-elevation
--container-max-width
--container-min-width
--container-shape
--density-step Item height removed per density step (set on the items).
--gap Space between groups in the grouped layout.
--group-padding
--group-shape
--section-label-text
--section-label-text-color

A Material Design component.

Property Attribute Type Default
checkable checkable MenuItemCheckable null
label
The section label shown above the group's items.
label string ''
Slot Description
default Used to display the menu group's items.
Part Description
::part(group) The group's root element.
::part(label) The section label.

A Material Design component.

Property Attribute Type Default
checked checked boolean false
disabled disabled boolean false
Slot Description
default Used to display the item's primary label.
leading Used to display icons and content before the item's main content.
submenu An md-gb-menu to open as this item's submenu.
supporting-text Used to display supporting text below the main label.
trailing Used to display icons and content after the item's main content.
trailing-text Used to display metadata or text after the item's main content.
Event Description
change
Event
Fired when a checkbox or menu item is checked or unchecked.
input
InputEvent
Fired when a checkbox or menu item is checked or unchecked.
Method Description
closeSubmenu
() => void
Closes the item's submenu.
openSubmenu
(focus?: boolean) => void
Opens the item's submenu next to it and focuses its first item.
Part Description
::part(menu-item) The menu item's root element.
Property Description
--between-space
--bottom-space
--container-color
--height
--inner-corner-corner-size
--label-text
--label-text-axes
--label-text-color
--label-text-tracking
--leading-icon-color
--leading-icon-size
--leading-space
--shape
--supporting-text
--supporting-text-axes
--supporting-text-color
--supporting-text-tracking
--top-space
--trailing-icon-color
--trailing-icon-size
--trailing-space
--trailing-supporting-text
--trailing-supporting-text-axes
--trailing-supporting-text-color
--trailing-supporting-text-tracking
Install Material Web 3.0

Your browser did not offer to install the docs as an app. Install them from the browser instead:

Close
Send feedback
Bug Documentation Idea

Opens a new GitHub issue for material-components/material-web in a new tab, with this filled in.

Cancel Open issue