CSS Portal

HTML name Attribute

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

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.

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 information will show you the current browser support for the HTML name attribute. Hover over a browser icon to see the version that first introduced support for this HTML attribute.

This attribute is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 29th March 2024

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!