I know by reading the W3C documentation for HTML4.01 and HTML5 that the "name" attribute originally existed as a property of the <a>
tag to permit people to link to an anchor point within a document.
However, now that all major browser vendors allow linking to any HTML element within a document via the "id" attribute, is there still any real use for the "name" attribute? If so, how should I be using the "name" attribute?
The name attribute is for submitting a form element to the server; many elements may share the same name (e.g. radio buttons, which must have the same name within the set). The id attribute is for uniquely identifying any element (not just form elements). It must be unique throughout the entire document.
To put it very informally, id is what your frontend (CSS, JS) works with, while name is what your server receives and can then process.
The name Attribute This attribute is associated with the data within the element. Like the id attribute, the name attribute must begin with a letter and is case sensitive, but unlike the id attribute, it can be not unique. The name attribute cannot be referenced in CSS.
DOCTYPE for HTML4 is much longer as it is SGML-based. However, the reference to DTD has been withdrawn from HTML5 <! DOCTYPE> declaration, since it is not based on SGML. Therefore, there is no need to tell the browser about Type Definition of Document and with HTML5 a simple <!
One thing that comes to mind are radio buttons: you have to use name
to specify which ones are part of the same group.
<form>
<input type="radio" name="sex" value="male" /> Male<br />
<input type="radio" name="sex" value="female" /> Female
</form>
The name
attribute is required, I think, on input
elements (and their friends)...
<input type="text" name="email" value="" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With