HTML global attribute contextmenu

The contextmenu attribute installs 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.

What's new in HTML5

The contextmenu attribute is new in HTML5.


<element contextmenu="menu_id">

Attribute Values

The id of the <menu> element

Browser compatibility

contextmenu No No Yes No No


<!DOCTYPE html>
div {<!-- w  ww  .j a va2 s  .co  m-->
    background: yellow;
    border: 1px solid #cccccc;
    padding: 10px;

<div contextmenu="mymenu">
    <p>Right-click inside this box to see the context menu!</p>
    <menu type="context" id="mymenu">
      <menuitem label="Refresh from custom menu" onclick="" icon=""></menuitem>



Click to view the demo