The menu
tag in HTML is a semantic element that defines a list of commands or options — often used in context menus, toolbars, or settings panels. Though rarely used in everyday development, it’s part of HTML’s effort to make content more meaningful and accessible.
📌 What Is the <menu>
Tag?
The <menu>
tag represents a list of menu items, typically displayed to the user when right-clicking or accessing an options menu. It’s similar to the <ul>
(unordered list) tag, but with contextual meaning.
✅ HTML5 redefined
<menu>
for use with toolbar buttons, pop-up menus, or context menus.
🧪 Basic Example
<menu type="context" id="myMenu">
<menuitem label="Refresh" onclick="location.reload();"></menuitem>
<menuitem label="Save As" onclick="alert('Save not available');"></menuitem>
</menu>
<p contextmenu="myMenu">Right-click on this paragraph to see the menu.</p>
🖱️ In this example:
- The
<menu>
defines a right-click context menu. - Each
<menuitem>
defines an actionable command. - The paragraph links to that menu using
contextmenu="myMenu"
.
⚙️ Attributes of <menu>
Attribute | Description | Example |
---|---|---|
type | Defines how the menu is used: context , toolbar , or list | type="context" |
label (in <menuitem> ) | Visible text of the item | "Copy Link" |
📂 Structure Diagram
<menu type="context" id="menu1">
├── <menuitem label="Open">
├── <menuitem label="Save">
└── <menuitem label="Print">
This is conceptually similar to:
<ul>
<li>Open</li>
<li>Save</li>
<li>Print</li>
</ul>
But with interactive or actionable purpose.
❗ Browser Support Warning
⚠️ The
<menu>
and<menuitem>
tags are deprecated in modern browsers, including Chrome and Firefox.
They may not work reliably and are typically replaced with JavaScript + custom CSS dropdowns or modals.
✅ Modern Alternative: <ul>
+ JS
Here’s how you might implement a modern dropdown:
<ul class="custom-menu">
<li onclick="doSomething()">Option 1</li>
<li onclick="doSomethingElse()">Option 2</li>
</ul>
And use CSS/JS to show/hide it on right-click.
🎯 When to Use <menu>
Use Case | Recommendation |
---|---|
Context menus (right-click) | ❌ Use JS instead |
Semantic grouping of commands | ✅ Good for basic toolbars |
Interactive UI buttons | ✅ When paired with JavaScript |
🧠 Accessibility Note
Since <menu>
is not widely supported, always ensure keyboard navigation and ARIA roles if you’re replacing it with custom components.
✅ Conclusion
The <menu>
tag was once intended to provide native support for contextual and toolbar menus. Today, it’s mostly deprecated and replaced by more flexible solutions using CSS and JavaScript. However, it remains a useful semantic tool for special use cases and legacy applications.