This question already has answers here: Difference between id and name attributes in HTML (21 answers) Closed 2 years ago.
When using the HTML <input>
tag, what is the difference between the use of the name
and id
attributes especially that I found that they are sometimes named the same?
In HTML4.01:
Name Attribute
Valid only on ,
Name does not have to be unique, and can be used to group elements together such as radio buttons & checkboxes
Can not be referenced in URL, although as JavaScript and PHP can see the URL there are workarounds
Is referenced in JavaScript with getElementsByName()
Shares the same namespace as the id attribute
Must begin with a letter
According to specifications is case sensitive, but most modern browsers don't seem to follow this
Used on form elements to submit information. Only input tags with a name attribute are submitted to the server
Id Attribute
Valid on any element except