X

Headline

This is an important message requiring you to make a choice if you're based in the EU.

HTML <menu> Tag

The <menu> tag defines a list of commands. It is used for creating context menus, toolbars and listing form controls and commands.

Each list item in <menu> tag starts with the <li> or the <menuitem> elements.

The <menu> was a deprecated HTML tag in HTML 4.01 and has been redefined in HTML5. It works only for context menus. Use the <ul> element instead.

Syntax

The <menu> tag comes in pairs. The content must be written between opening (<menu>) and closing (</menu>) tags.

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      menuitem {
        display: block;
      }
    </style>
  </head>
  <body>
    <menu>
      <menuitem>ol - ordered list</menuitem>
      <menuitem>ul - unordered list</menuitem>
      <menuitem>menu - menu list</menuitem>
    </menu>
  </body>
</html>

Result

Let's see another example where the <menu> tag is used to create a context menu:

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <div style="background:#1c87c9; padding: 20px; text-align:center; color:#ffffff;" contextmenu="menuexample">
      <p>Right-click inside this box to open the context menu</p>
      <menu type="context" id="menuexample">
        <menuitem label="Refresh" onclick="window.location.reload();"></menuitem>
        <menu label="Share on...">
          <menuitem label="Twitter" onclick="window.open('//twitter.com/intent/tweet?text=' + window.location.href);"></menuitem>
          <menuitem label="Facebook" onclick="window.open('//facebook.com/sharer/sharer.php?u=' + window.location.href);"></menuitem>
        </menu>
        <menuitem label="Email This Page" onclick="window.location='mailto:?body='+window.location.href;"></menuitem>
      </menu>
    </div>
    <p><span style="color:red;">Reminder:</span> This works only in Firefox.</p>
  </body>
</html>

Result

Attributes

Attribute Value Description
label text Defines a visible label for the menu.
type popup
toolbar
context
Defines the type of the menu.

The <menu> tag also supports the Global attributes and the Event Attributes.

How to style <menu> tag

Common properties to alter the visual weight/emphasis/size of text in <menu> tag:?

  • CSS font-style property sets the style of the font. normal | italic | oblique | initial | inherit
  • CSS font-family property specifies a prioritized list of one or more font family names and/or generic family names for the selected element.
  • CSS font-size property sets the size of the font.
  • CSS font-weight property defines whether the font should be bold or thick. CSS text-transform Property controls text case and capitalization.
  • CSS text-decoration property specifies the decoration added to text, and is a shorthand property for text-decoration-line, text-decoration-color, text-decoration-style

Coloring text in <menu> tag:

  • CSS color property describes the color of the text content and text decorations
  • CSS background-color property sets the background color of an element.

Text layout styles for <menu> tag:

  • CSS text-indent property specifies the indentation of the first line in a text block.
  • CSS text-overflow property specifies how overflowed content that is not displayed should be signaled to the user.
  • CSS white-space property specifies how white-space inside an element is handled.
  • CSS word-break property specifies where the lines should be broken.

Other properties worth looking at for <menu> tag


Browser support

8+


Do you find this helpful?

Related articles