The HTML name attribute assigns a name to an element, primarily for identifying form controls during data submission and for referencing the element in other elements or in JavaScript.
Definition and Usage
➔ The name attribute does not have to be unique throughout the document, multiple elements can share the same name.
➔ The name attribute is used on various elements, each with a specific purpose:
- Form controls (<input>, <select>, <textarea>, <button>): When a form is submitted, only form elements with the name attribute can send data to the server as name/value pairs.
- <form>: The name attribute provides a reference to the form in JavaScript.
- <map>: The name attribute in the map is used by the usemap attribute of the <img> element, which defines a relationship and client-side image map.
- <meta>: The name attribute specifies the type of metadata.
- <output>: Used in forms, the name of the output element used to generate the results of the calculation.
- <param>: Used with the <object> tag to specify parameters for an embedded object.
- <details>: The name attribute allows <details> elements to be grouped into an accordion.