HTML - <menu>
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.
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>Action</menuitem> <menuitem>Another action</menuitem> <hr> <menuitem>Separated action</menuitem> </menu>
CSS content
div { width: 300px; height: 80px; background-color: lightgreen; }
Result
Menu button
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>Action</menuitem> <menuitem>Another action</menuitem> <hr> <menuitem>Separated action</menuitem> </menu>
Result
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
Description
This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.
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.
<menu>
and <ul>
elements both represent an unordered list of items. The key difference is that <ul>
primarily contains items for display, whilst <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 <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 <li> , <script> , and <template> .If the element is in the context menu state: zero or more occurrences, in any order, of <menu> (context menu state only), <menuitem> , <hr> , <script> , and <template> . |
Tag omission | None, both the starting and ending tag are mandatory. |
Permitted parent elements | Any element that accepts flow content. |
DOM interface | HTMLMenuElement |
Browser Compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Edge | Opera | Safari |
---|---|---|---|---|---|---|
type="context" |
(Yes)[1] | 8 (8)[2] | No support | No support | (Yes)[3] | No support |
type="toolbar" |
No support | No support | No support | No support | No support | No support |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
type="context" |
No support | (Yes)[4] | No support | No support | No support |
type="toolbar" |
No support | No support | No support | No support | No support |
[1] This is implemented behind the preference Experimental Web Platform features and only works as context menu, not as button menu.
[2] Only works as context menu, not as button menu.
[3] This is implemented behind the preference Enable experimental Web Platform features and works as context menu, not as button menu.
[4] Nested menus are not supported.
See Also
- Other list-related HTML Elements:
<ol>
,<ul>
,<li>
and the obsolete<dir>
. - The
contextmenu
global attribute can be used on an element to refer to theid
of amenu
with thecontext
type
.
Specifications
Specification | Status | Comment |
---|---|---|
WHATWG HTML Living Standard The definition of '<menu>' in that specification. |
Living Standard | |
HTML5.1 The definition of '<menu>' in that specification. |
Working Draft | Initial definition |
License
© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/html/element/menu