W3Schools.com

HTML5 contextmenu Attribute

HTML5 Global Attributes HTML5 Global Attributes

Example

Specify a context menu for a <p> element. The context menu should appear when a user right-clicks on the element:

<p contextmenu="supermenu">This paragraph has a context menu called "supermenu" attached.</p>

<menu id="supermenu">
  <command label="Step 1: Write Tutorial" onclick="doSomething()">
  <command label="Step 2: Edit Tutorial" onclick="doSomethingElse()">
</menu>

Try it yourself »

Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The contextmenu attribute is not currently supported in any of the major browsers.


Definition and Usage

The contextmenu attribute specifies a context menu for an element. The context menu appears when a user right-clicks on the element.

The value of the contextmenu attribute is the id of the <menu> element to open.


Differences Between HTML 4.01 and HTML5

The contextmenu attribute is new in HTML5.


Syntax

<element contextmenu="menu_id">

Attribute Values

Value Description
menu_id The id of the <menu> element to open


HTML5 Global Attributes HTML5 Global Attributes
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$3.98 Unlimited Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Best Website Templates Top CSS Templates
CREATE HTML Websites
EASY WEBSITE BUILDER
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE