Introduction

The Material Design Lite (MDL) menu component is a user interface element that allows users to select one of a number of options. The selection typically results in an action initiation, a setting change, or other observable effect. Menu options are always presented in sets of two or more, and options may be programmatically enabled or disabled as required. The menu appears when the user is asked to choose among a series of options, and is usually dismissed after the choice is made.

Menus are an established but non-standardized feature in user interfaces, and allow users to make choices that direct the activity, progress, or characteristics of software. Their design and use is an important factor in the overall user experience. See the menu component's Material Design specifications page for details.

To include an MDL menu component:

Note: The menu requires a non-static positioned parent element. Positioning options may not work properly if the menu is inside of a statically positioned node.

 1. Code a <button> element; this is the clickable toggle that will show and hide the menu options. Include an id attribute whose value will match the for (or data-mdl-for) attribute of the unordered list coded in the next step. Inside the button, code a <i> or <span> element to contain an icon of your choice.

<button id="menu1">
  <i></i>
</button>

 2. Code a <ul> unordered list element; this is the container that holds the options. Include a for attribute whose value matches the id attribute of the button element.

<ul for="menu1">
</ul>

 3. Inside the unordered list, code one <li> element for each option. Include any desired attributes and values, such as an id or event handler, and add a text caption as appropriate.

<ul for="menu1">
  <li>Continue</li>
  <li>Stop</li>
  <li>Pause</li>
</ul>

 4. Add one or more MDL classes, separated by spaces, to the button and span elements using the class attribute.

<button id="menu1" class="mdl-button mdl-js-button mdl-button--icon">
  <i class="material-icons">more_vert</i>
</button>

 5. Add one or more MDL classes, separated by spaces, to the unordered list and the list items using the class attribute.

<ul class="mdl-menu mdl-js-menu" for="menu1">
  <li class="mdl-menu__item">Continue</li>
  <li class="mdl-menu__item">Stop</li>
  <li class="mdl-menu__item">Pause</li>
</ul>

The menu component is ready for use.

Examples

A menu with three options.

<button id="menu-speed" class="mdl-button mdl-js-button mdl-button--icon">
  <i class="material-icons">more_vert</i>
</button>
<ul class="mdl-menu mdl-js-menu" for="menu-speed">
  <li class="mdl-menu__item">Fast</li>
  <li class="mdl-menu__item">Medium</li>
  <li class="mdl-menu__item">Slow</li>
</ul>

A menu with three options, with ripple effect on button and option links.

<button id="menu-speed" class="mdl-button mdl-js-button mdl-button--icon">
  <i class="material-icons">more_vert</i>
</button>
<ul class="mdl-menu mdl-js-menu mdl-js-ripple-effect" for="menu-speed">
  <li class="mdl-menu__item">Fast</li>
  <li class="mdl-menu__item">Medium</li>
  <li class="mdl-menu__item">Slow</li>
</ul>

A menu with three options, the second of which is disabled by default.

<button id="menu-speed" class="mdl-button mdl-js-button mdl-button--icon">
  <i class="material-icons">more_vert</i>
</button>
<ul class="mdl-menu mdl-js-menu" for="menu-speed">
  <li class="mdl-menu__item">Fast</li>
  <li class="mdl-menu__item" disabled>Medium</li>
  <li class="mdl-menu__item">Slow</li>
</ul>

Configuration options

The MDL CSS classes apply various predefined visual and behavioral enhancements to the menu. The table below lists the available classes and their effects.

MDL classEffectRemarks
mdl-buttonDefines button as an MDL componentRequired on button element
mdl-js-buttonAssigns basic MDL behavior to buttonRequired on button element
mdl-button--iconApplies icon (small plain circular) display effect to buttonRequired on button element
material-iconsDefines span as a material iconRequired on an inline element
mdl-menuDefines an unordered list container as an MDL componentRequired on ul element
mdl-js-menuAssigns basic MDL behavior to menuRequired on ul element
mdl-menu__itemDefines buttons as MDL menu options and assigns basic MDL behaviorRequired on list item elements
mdl-menu__item--full-bleed-dividerModifies an item to have a full bleed divider between it and the next list item.Optional on list item elements
mdl-js-ripple-effectApplies ripple click effect to option linksOptional; goes on unordered list element
mdl-menu--top-leftPositions menu above button, aligns left edge of menu with buttonOptional; goes on unordered list element
(none)Positions menu below button, aligns left edge of menu with buttonDefault
mdl-menu--top-rightPositions menu above button, aligns right edge of menu with buttonOptional; goes on unordered list element
mdl-menu--bottom-rightPositions menu below button, aligns right edge of menu with buttonOptional; goes on unordered list element

(1) The "more-vert" icon class is used here as an example. Other icons can be used by modifying the class name. For a list of available icons, see this page; hover over an icon to see its class name.

(2) The i or span element in "button"" element can be used interchangeably.

Note: Disabled versions of the menu options are provided, and are invoked with the standard HTML boolean attribute disabled or data-mdl-disabled. <li class="mdl-menu__item" disabled>Medium</li> This attribute may be added or removed programmatically via scripting.