English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML Tag Directory

HTML contextmenu attribute

The contextmenu global attribute refers to the ID attribute of the <menu> used for the "context menu" of an element. A context menu is a menu that appears during user interaction (such as right-clicking). HTML5It allows us to customize this menu. Here are some implementation examples, including nested menus.

HTML Global Attributes

The contextmenu attribute is deprecated and will be removed from all browsers.

Online Example

Specify a context menu for the <div> element. When the user right-clicks on the element, the context menu will be displayed:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>HTML contextmenu 属性的使用(基础教程网 oldtoolbag.com)</title>
</head>
<body contextmenu="share">
<menu type="context" id="share">
    
     <menu label="share">/<menuitem label="Facebook">Facebook<
     <menuitem label="Twitter">Twitter</<menuitem label="Facebook">Facebook<
   </menu>
 </menu>
</body>
</html>
Test to see ‹/›

Browser Compatibility

IEFirefoxOperaChromeSafari

Currently, only the Firefox browser supports the contextmenu attribute.

Definition and Usage

The contextmenu attribute specifies the context menu of an element. When the user right-clicks on the element, the context menu will be displayed.
The value of the contextmenu attribute is the ID of the <menu> element to be opened.

HTML 4.01 and HTML5difference between

The contextmenu attribute is an HTML5 new attribute in the middle of.

Syntax

        <element contextmenu="menu_id">

Attribute Value

ValueDescription
menu_idThe id of the <menu> element to be opened.


HTML Global Attributes