Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1073286 of <menu>

  • Revision slug: Web/HTML/Element/menu
  • Revision title: <menu>
  • Revision id: 1073286
  • Created:
  • Creator: Sebastianz
  • Is current revision? No
  • Comment Updated mobile browser compatibility information

Revision Content

{{HTMLRef}}{{SeeCompatTable}}

The HTML <menu> element represents a group of commands that a user can perform or activate. This includes both list menus, which might appear across the top of a screen, as well as context menus, such as those that might appear underneath a button after it has been clicked.

Usage note: The {{HTMLElement("menu")}} and {{HTMLElement("ul")}} elements both represent an unordered list of items. The key difference is that {{HTMLElement("ul")}} primarily contains items for display, whilst {{HTMLElement("menu")}} is intended for interactive items, to act on.

Notes: This element was deprecated in HTML4, but reintroduced in HTML5.1 (still working draft).")}}. This document describes current Firefox implementation. Type 'list' is likely to change to 'toolbar' according to HTML5.1 working draft.")}}

Content categories Flow content. Additionally, if in the list menu state, palpable content. (list menu is the default state, unless the parent element is a {{HTMLElement("menu")}} in the context menu state.)
Permitted content If the element is in the list menu state: flow content, or alternatively, zero or more occurrences of {{HTMLElement("li")}}, {{HTMLElement("script")}}, and {{HTMLElement("template")}}.
If the element is in the context menu state: zero or more occurrences, in any order, of {{HTMLElement("menu")}} (context menu state only), {{HTMLElement("menuitem")}}, {{HTMLElement("hr")}}, {{HTMLElement("script")}}, and {{HTMLElement("template")}}.
Tag omission {{no_tag_omission}}
Permitted parent elements Any element that accepts flow content.
DOM interface {{domxref("HTMLMenuElement")}}

Attributes

This element includes the global attributes.

{{htmlattrdef("label")}}
The name of the menu as shown to the user. Used within nested menus, to provide a label through which the submenu can be accessed. Must only be specified when the parent element is a {{HTMLElement("menu")}} in the context menu state.
{{htmlattrdef("type")}}
This attribute indicates the kind of menu being declared, and can be one of two values.
  • context: Indicates the popup menu state, which represents a group of commands activated through another element. This might be as a button menu referenced by a {{htmlattrxref("menu", "button")}} attribute of a {{HTMLElement("button")}} element, or as context menu for an element with a contextmenu attribute. This value is the default if the attribute is missing and the parent element is also a <menu> element.
  • toolbar: Indicates the toolbar state, which represents a toolbar consisting of a series of commands for user interaction. This might be in the form of an unordered list of {{HTMLElement("li")}} elements, or, if the element has no <li> element children, flow content describing available commands. This value is the default if the attribute is missing.

Examples

Context menu

HTML content

<!-- A <div> element with a context menu -->
<div contextmenu="popup-menu">
  Right-click to see the adjusted context menu
</div>

<menu type="context" id="popup-menu">
  <menuitem label="Action">
  <menuitem label="Another action">
  <hr>
  <menuitem label="Separated action">
</menu>

CSS content

div {
  width: 300px;
  height: 80px;
  background-color: lightgreen;
}

Result

{{EmbedLiveSample('Context_menu', '300', '80')}}

HTML content

<!-- A button, which displays a menu when clicked. -->
<button type="menu" menu="popup-menu">
  Dropdown
</button>

<menu type="context" id="popup-menu">
  <menuitem label="Action">
  <menuitem label="Another action">
  <hr>
  <menuitem label="Separated action">
</menu>

Result

{{EmbedLiveSample('Menu_button', '200', '50')}}

Toolbar

HTML content

<!-- A context menu for a simple editor,
    containing two menu buttons. -->
<menu type="toolbar">
  <li>
    <button type="menu" menu="file-menu">File</button>
    <menu type="context" id="file-menu">
      <menuitem label="New..." onclick="newFile()">
      <menuitem label="Save..." onclick="saveFile()">
    </menu>
  </li>
  <li>
    <button type="menu" menu="edit-menu">Edit</button>
    <menu type="context" id="edit-menu">
      <menuitem label="Cut..." onclick="cutEdit()">
      <menuitem label="Copy..." onclick="copyEdit()">
      <menuitem label="Paste..." onclick="pasteEdit()">
    </menu>
  </li>
</menu>

Result

{{EmbedLiveSample('Toolbar', '120', '100')}}

Specifications

Specification Status Comment
{{SpecName('HTML WHATWG', 'interactive-elements.html#the-menu-element', '<menu>')}} {{Spec2('HTML WHATWG')}}  
{{SpecName('HTML5.1', 'interactive-elements.html#the-menu-element', '<menu>')}} {{Spec2('HTML5.1')}} Initial definition

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Edge Opera Safari
type="context" {{CompatNo}} {{CompatGeckoDesktop("8")}}[1] {{CompatNo}} {{CompatNo}} {{CompatNo}} {{CompatNo}}
type="toolbar" {{CompatNo}} {{CompatNo}} {{CompatNo}} {{CompatNo}} {{CompatNo}} {{CompatNo}}
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
type="context" {{CompatNo}} {{CompatVersionUnknown}}[2] {{CompatNo}} {{CompatNo}} {{CompatNo}}
type="toolbar" {{CompatNo}} {{CompatNo}} {{CompatNo}} {{CompatNo}} {{CompatNo}}

[1] Only works as context menu, not as button menu.

[2] Nested menus are not supported.

See also

  • Other list-related HTML Elements: {{HTMLElement("ol")}}, {{HTMLElement("ul")}}, {{HTMLElement("li")}} and the obsolete {{HTMLElement("dir")}}.
  • The contextmenu global attribute can be used on an element to refer to the id of a menu with the context {{htmlattrxref("type","menu")}}.

Revision Source

<div>{{HTMLRef}}{{SeeCompatTable}}</div>

<p>The <strong>HTML <code>&lt;menu&gt;</code> element</strong> represents a group of commands that a user can perform or activate. This includes both list menus, which might appear across the top of a screen, as well as context menus, such as those that might appear underneath a button after it has been clicked.</p>

<div class="note"><strong>Usage note: </strong> The {{HTMLElement("menu")}} and {{HTMLElement("ul")}} elements both represent an unordered list of items. The key difference is that {{HTMLElement("ul")}} primarily contains items for display, whilst {{HTMLElement("menu")}} is intended for interactive items, to act on.</div>

<p class="note"><strong>Notes: </strong>This element was deprecated in HTML4, but reintroduced in HTML5.1 (still working draft).")}}. This document describes current Firefox implementation. Type 'list' is likely to change to 'toolbar' according to HTML5.1 working draft.")}}</p>

<table class="properties">
 <tbody>
  <tr>
   <th scope="row"><a href="/en-US/docs/Web/HTML/Content_categories">Content categories</a></th>
   <td><a href="/en-US/docs/Web/HTML/Content_categories#Flow_content">Flow content</a>. Additionally, if in the <em>list menu</em> state, palpable content. (<em>list menu</em> is the default state, unless the parent element is a {{HTMLElement("menu")}} in the <em>context menu</em> state.)</td>
  </tr>
  <tr>
   <th scope="row">Permitted content</th>
   <td>If the element is in the <em>list menu</em> state: <a href="/en-US/docs/Web/HTML/Content_categories#Flow_content">flow content</a>, or alternatively, zero or more occurrences of {{HTMLElement("li")}}, {{HTMLElement("script")}}, and {{HTMLElement("template")}}.<br />
    If the element is in the <em>context menu</em> state: zero or more occurrences, in any order, of {{HTMLElement("menu")}} (<em>context menu</em> state only), {{HTMLElement("menuitem")}}, {{HTMLElement("hr")}}, {{HTMLElement("script")}}, and {{HTMLElement("template")}}.</td>
  </tr>
  <tr>
   <th scope="row">Tag omission</th>
   <td>{{no_tag_omission}}</td>
  </tr>
  <tr>
   <th scope="row">Permitted parent elements</th>
   <td>Any element that accepts <a href="/en-US/docs/Web/HTML/Content_categories#Flow_content">flow content</a>.</td>
  </tr>
  <tr>
   <th scope="row">DOM interface</th>
   <td>{{domxref("HTMLMenuElement")}}</td>
  </tr>
 </tbody>
</table>

<h2 id="Attributes">Attributes</h2>

<p>This element includes the <a href="/en-US/docs/Web/HTML/Global_attributes">global attributes</a>.</p>

<dl>
 <dt>{{htmlattrdef("label")}}</dt>
 <dd>The name of the menu as shown to the user. Used within nested menus, to provide a label through which the submenu can be accessed. Must only be specified when the parent element is a {{HTMLElement("menu")}} in the <em>context menu</em> state.</dd>
 <dt>{{htmlattrdef("type")}}</dt>
 <dd>This attribute indicates the kind of menu being declared, and can be one of two values.
 <ul>
  <li><code>context</code>: Indicates the <em>popup menu</em> state, which represents a group of commands activated through another element. This might be as a button menu referenced by a {{htmlattrxref("menu", "button")}} attribute of a {{HTMLElement("button")}} element, or as context menu for an element with a <a href="/en-US/docs/HTML/Global_attributes#attr-contextmenu"><code>contextmenu</code></a> attribute. This value is the default if the attribute is missing and the parent element is also a <code>&lt;menu&gt;</code> element.</li>
  <li><code>toolbar</code>: Indicates the <em>toolbar</em> state, which represents a toolbar consisting of a series of commands for user interaction. This might be in the form of an unordered list of {{HTMLElement("li")}} elements, or, if the element has no <code>&lt;li&gt;</code> element children, flow content describing available commands. This value is the default if the attribute is missing.</li>
 </ul>
 </dd>
</dl>

<h2 id="Examples">Examples</h2>

<h3 id="Context_menu">Context menu</h3>

<h4 id="HTML_content">HTML content</h4>

<pre class="brush: html">
&lt;!-- A &lt;div&gt; element with a context menu --&gt;
&lt;div contextmenu="popup-menu"&gt;
  Right-click to see the adjusted context menu
&lt;/div&gt;

&lt;menu type="context" id="popup-menu"&gt;
  &lt;menuitem label="Action"&gt;
  &lt;menuitem label="Another action"&gt;
  &lt;hr&gt;
  &lt;menuitem label="Separated action"&gt;
&lt;/menu&gt;
</pre>

<h4 id="CSS_content">CSS content</h4>

<pre class="brush: css">
div {
  width: 300px;
  height: 80px;
  background-color: lightgreen;
}
</pre>

<h4 id="Result">Result</h4>

<p>{{EmbedLiveSample('Context_menu', '300', '80')}}</p>

<h3 id="Menu_button">Menu button</h3>

<h4 id="HTML_content_2">HTML content</h4>

<pre class="brush: html">
&lt;!-- A button, which displays a menu when clicked. --&gt;
&lt;button type="menu" menu="popup-menu"&gt;
  Dropdown
&lt;/button&gt;

&lt;menu type="context" id="popup-menu"&gt;
  &lt;menuitem label="Action"&gt;
  &lt;menuitem label="Another action"&gt;
  &lt;hr&gt;
  &lt;menuitem label="Separated action"&gt;
&lt;/menu&gt;
</pre>

<h4 id="Result_2">Result</h4>

<p>{{EmbedLiveSample('Menu_button', '200', '50')}}</p>

<h3 id="Toolbar">Toolbar</h3>

<h4 id="HTML_content_3">HTML content</h4>

<pre class="brush: html">
&lt;!-- A context menu for a simple editor,
    containing two menu buttons. --&gt;
&lt;menu type="toolbar"&gt;
  &lt;li&gt;
    &lt;button type="menu" menu="file-menu"&gt;File&lt;/button&gt;
    &lt;menu type="context" id="file-menu"&gt;
      &lt;menuitem label="New..." onclick="newFile()"&gt;
      &lt;menuitem label="Save..." onclick="saveFile()"&gt;
    &lt;/menu&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;button type="menu" menu="edit-menu"&gt;Edit&lt;/button&gt;
    &lt;menu type="context" id="edit-menu"&gt;
      &lt;menuitem label="Cut..." onclick="cutEdit()"&gt;
      &lt;menuitem label="Copy..." onclick="copyEdit()"&gt;
      &lt;menuitem label="Paste..." onclick="pasteEdit()"&gt;
    &lt;/menu&gt;
  &lt;/li&gt;
&lt;/menu&gt;
</pre>

<h4 id="Result_3">Result</h4>

<p>{{EmbedLiveSample('Toolbar', '120', '100')}}</p>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('HTML WHATWG', 'interactive-elements.html#the-menu-element', '&lt;menu&gt;')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5.1', 'interactive-elements.html#the-menu-element', '&lt;menu&gt;')}}</td>
   <td>{{Spec2('HTML5.1')}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Edge</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td><code>type="context"</code></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatGeckoDesktop("8")}}<sup>[1]</sup></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td><code>type="toolbar"</code></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td><code>type="context"</code></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatVersionUnknown}}<sup>[2]</sup></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td><code>type="toolbar"</code></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] Only works as context menu, not as button menu.</p>

<p>[2] Nested menus are not supported.</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>Other list-related HTML Elements: {{HTMLElement("ol")}}, {{HTMLElement("ul")}}, {{HTMLElement("li")}} and the obsolete {{HTMLElement("dir")}}.</li>
 <li>The <a href="/en-US/docs/HTML/Global_attributes#attr-contextmenu"><code>contextmenu</code></a> <a href="/en-US/docs/HTML/Global_attributes">global attribute</a> can be used on an element to refer to the <code>id</code> of a <code>menu</code> with the <code>context</code> {{htmlattrxref("type","menu")}}.</li>
</ul>
Revert to this revision