Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I use the name attribute in HTML4/HTML5?

Tags:

html

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?

like image 228
Andrew De Andrade Avatar asked Oct 14 '10 06:10

Andrew De Andrade


People also ask

What is the difference between id and 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.

What is the use of name and id in form?

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.

Whats the difference between name and id HTML?

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.

What is the difference between HTML4 doctype and HTML5 doctype?

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 <!


2 Answers

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> 
like image 176
nico Avatar answered Sep 24 '22 10:09

nico


The name attribute is required, I think, on input elements (and their friends)...

<input type="text" name="email" value="" />
like image 45
alex Avatar answered Sep 24 '22 10:09

alex