HTML name Attribute

Description

The name attribute in HTML is used to specify the name of an element. This attribute plays a crucial role in different contexts depending on the type of element it is associated with. For form elements like <input>, <textarea>, <select>, and others, the name attribute is used to identify the form data after it's submitted. This means that when a form is submitted, the data that gets sent to the server includes a pair of each field's name attribute value and its current value. For example, if you have an <input type="text" name="username">, the server receives the input value associated with the name "username".

Moreover, the name attribute is also used for fragment identifiers in anchor tags (<a>). In this context, it allows for linking to specific parts of a webpage. However, it's worth noting that the usage of the name attribute for anchors has been superseded by the id attribute in modern HTML practices, although it is still supported by browsers for backward compatibility.

The name attribute is a key part of ensuring that form data is correctly labeled and processed on the server side, and although its role has evolved, it remains a fundamental part of HTML.

Syntax

<tagname name="name">

Values

  • nameString value. The name of the element.

Applies To

The name attribute can be used on the following html elements.

Example

<form action="formscript.php" method="post">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="firstname" ><br><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lastname"><br><br>
<input type="submit" value="Submit">
</form>

Browser Support

The following table will show you the current browser support for the HTML name Attribute.

Desktop
Edge Chrome Firefox Opera Safari
YesYesYesYesYes
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
YesYesYesYesYesYes

Last updated by CSSPortal on: 29th March 2024