YouTip LogoYouTip

Att Global Contextmenu

# HTML Global Attribute: contextmenu The `contextmenu` attribute is an HTML global attribute used to define a custom context menu (right-click menu) for an element. When a user right-clicks on the element, the specified custom menu is displayed instead of or in addition to the browser's default context menu. --- ## Definition and Usage * The `contextmenu` attribute associates an element with a `` element that acts as its context menu. * The value of the `contextmenu` attribute must match the `id` of the `` element you want to open. * This attribute was introduced in HTML5 to allow developers to build native-feeling web applications with custom right-click interactions. --- ## Syntax ```html ``` ### Attribute Values | Value | Description | | :--- | :--- | | *menu_id* | The `id` of the `` element that defines the custom context menu. | --- ## Code Example Below is an example of how the `contextmenu` attribute was designed to link a `
` element to a custom context menu: ```html
Right-click inside this box to see the custom context menu.
``` --- ## Browser Compatibility and Modern Alternatives ### Historical Context The `contextmenu` attribute and its associated `` element were introduced in the HTML5 specification. However, they never achieved broad cross-browser adoption. * **Firefox** was the only major browser that historically provided native support for this attribute. * **Chrome, Safari, Edge, and Opera** never implemented native support for the `contextmenu` attribute. ### Current Status: Deprecated > ⚠️ **Warning:** The `contextmenu` attribute and the `` element have been **deprecated** and removed from the official HTML Living Standard. Modern browsers no longer support them. ### Modern Alternative: JavaScript `contextmenu` Event To implement custom context menus in modern web applications, you should use the JavaScript `contextmenu` event combined with standard CSS and HTML. Here is a modern, cross-browser compatible implementation: ```html Modern Custom Context Menu
Right-click inside this area for a modern custom menu.
  • Refresh
  • Twitter
```
← Att Global DataAtt Global Contenteditable β†’