<menu> : Menu element

Introduction

The <menu> element in HTML is used to define a list of commands or options that can be accessed by the user. It’s primarily used in conjunction with JavaScript to create custom context menus, toolbars, or other interactive menus within a web application.

Here’s a basic example of how the <menu> element can be used:

Output :

In this example:

  • The <menu> element contains a list of <li> (list item) elements, each of which contains a <button> element representing a command or option.
  • The type attribute of the <menu> element is set to “toolbar”, indicating that this menu represents a toolbar.
  • Each <button> element has an onclick attribute that triggers a JavaScript function when clicked. In this case, clicking a button will display an alert with the corresponding action (Save, Open, or Print).

It’s important to note that the <menu> element is not widely supported in modern browsers, and its usage is generally discouraged in favor of more flexible and accessible alternatives like using semantic HTML elements combined with CSS and JavaScript to create custom menus and controls.

Leave a Comment