You are here: Reference > HTML > attributes > name (abbr, acronym, address, ...)

name attribute (abbr, acronym, address, ...)

Browser support:
Sets the name of an element.
The name attribute has different meanings for HTML elements:
  • for form controls, it affects the contents of the message submitted to the server. See the name (form controls) attribute for details.
  • for anchor elements, it specifies the name for a target anchor. See the name (anchor) attribute for details.
  • for frame elements, it specifies the initial name for the contained window. See the name (frames) attribute for details.
  • for image maps, it helps to establish a relationship between an image and an image map. See the name (map) attribute for details.
  • for meta elements, use it together with the content attribute to create a well-defined meta tag. See the name (meta) attribute for details.
  • for param elements, it contains information about the data that is passed in the value attribute to the object. See the name (param) attribute for details.
The name attribute has a common functionality for all HTML elements. It specifies an identifier that can be used to get a reference to the element in scripting languages. This identifier can be used for the getElementsByName method to get an array of elements that have the same name.
In Firefox, Opera, Google Chrome and Safari, all HTML elements support the name attribute. In Internet Explorer, the elements mentioned above and some other HTML elements support this property. You can find the browser support of the name attribute for a HTML element on the page for the HTML element.
JavaScript page for this attribute: name. You can find other example(s) there.

Possible values:

String that sets the name of the element.
Default: this attribute has no default value.

Example HTML code 1:

This example illustrates the use of the getElementsByName method:
    <script type="text/javascript">
        function CollectByName () {
            var tags = document.getElementsByName ("regFrom");
            var count = tags.length;
            alert ("There are " + count + " element(s) with the specified name attribute: " + tags[0].name);
    <form name="regFrom" action="#URL#" method="post">
        <input type="radio" name="sex" value="female" />female
        <br />
        <input type="radio" name="sex" value="male" />male

    <form name="regFrom" action="#URL#" method="post">
        User Name: <input type="text" name="userName" />
        <br />
        Password: <input type="password" name="password" />

    <br /><br />
    <button onclick="CollectByName ()">Collect elements by name</button>
Did you find this example helpful? yes no

Supported by tags:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content