--- title: slug: Web/HTML/Element/menu translation_of: Web/HTML/Element/menu ---
{{HTMLRef}}{{SeeCompatTable}}

L'element HTML <menu> representa un grup d'ordres que l'usuari pot realitzar o activar. Això inclou tant llistes com menús, que poden aparèixer a la part de dalt de la pantalla, com també menús de context, com les que poden aparèixer sota d'un botó després d'haver fet click.

Nota d'ús: Els elements {{HTMLElement("menu")}} i {{HTMLElement("ul")}} representen una llista no ordenada d'ítems. La diferència clau es que {{HTMLElement("ul")}} conté principalment ítems per mostrar, mentre que {{HTMLElement("menu")}} està destinat a elements interactius

Notes: This element was deprecated in HTML4, però reintroduit en l'HTML5.1 (still working draft).")}}. This document describes current Firefox implementation. Type 'list' is likely to change to 'toolbar' and 'context' to 'popup' according to HTML5.1 working draft.")}}

Categories de contingut Contingut dinàmic. 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.)
Contingut permès 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")}}.
Omissió de l'etiqueta {{no_tag_omission}}
Elements pares permessos Qualsevol element que accepti contingut dinàmic.
Interfície DOM {{domxref("HTMLMenuElement")}}

Atributs

Aquest element inclou els atributs globals.

{{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: The context menu state, which represents a group of commands activated through another element. This might be through the {{htmlattrxref("menu", "button")}} attribute of a {{HTMLElement("button")}}, or an element with a contextmenu attribute. When nesting {{HTMLElement("menu")}} elements directly within one another, this is the missing value default if the parent is already in this state.
  • list: The list menu state, which represents a series of commands for user interaction. This is the missing value default, except where the parent element is a {{HTMLElement("menu")}} in the context menu state.

Exemples

Exemple 1

<!-- Un botó, que mostra un menú quan es clica -->
<button type="menu" menu="dropdown-menu">
  Dropdown
</button>

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

Resultat

{{EmbedLiveSample('Example_1', '', '', '', 'Web/HTML/Element/menu')}}

Exemple 2

<!-- un menú de context per a un simple editor, que conté dos botons de menú -->
<menu>
  <li>
    <button type="menu" value="File" menu="file-menu">
    <menu type="context" id="file-menu">
      <menuitem label="New..." onclick="newFile()">
      <menuitem label="Save..." onclick="saveFile()">
    </menu>
  </li>
  <li>
    <button type="menu" value="Edit" menu="edit-menu">
    <menu type="context" id="edit-menu">
      <menuitem label="Cut..." onclick="cutEdit()">
      <menuitem label="Copy..." onclick="copyEdit()">
      <menuitem label="Paste..." onclick="pasteEdit()">
    </menu>
  </li>
</menu>

Resultat

{{EmbedLiveSample('Example_2', '', '', '', 'Web/HTML/Element/menu')}}

Especificacions

Especificació Estat Comentaris
{{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')}} Definició inicial

Compatibilitat amb navegadors

{{CompatibilityTable}}

Característica Chrome Firefox (Gecko) Internet Explorer Opera Safari
Suport bàsic {{CompatUnknown}} {{CompatNo}}[1] {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
Característica Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Suport bàsic {{CompatUnknown}} {{CompatNo}}[1] {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

[1] Gecko has some implementation, though it is not compatible to the specification. Vegeu error 1100749.

Vegeu també