What is the difference in between the id and name attributes? They both seem to serve the exact same purpose of offering an identifier.

You are watching: Name vs id html

I would choose to recognize (especially through regards to HTML forms) whether or not utilizing both is important or encouraged for any type of factors.


*

*

The name attribute is offered as soon as sending data in a kind submission. Different controls respond in a different way. For instance, you may have actually a number of radio butlots via various id characteristics, however the exact same name. When submitted, tbelow is just the one worth in the response - the radio button you selected.

Of course, there"s more to it than that, however it will absolutely acquire you reasoning in the best direction.


*

*

Use name qualities for develop controls (such as and ), as that"s the identifier provided in the POST or GET call that happens on create submission.

Use id characteristics whenever you should deal with a specific HTML element through CSS, JavaScript or a fragment identifier. It"s feasible to look up aspects by name, also, yet it"s less complicated and also more reputable to look them up by ID.


*

Here is a brief summary:id is used to identify the HTML facet through the DocumentObject Model (via JavaScript or styled with CSS). id is expectedto be distinct within the web page.

name synchronizes to the form facet and also identifies what is postedago to the server.


The method I think about it and also usage it is simple:

id is supplied for CSS and also JavaScript/jQuery (has to be distinctive in a page)

name is supplied for form taking care of on the server once a kind is submitted through HTML (has to be distinct in a type - to some degree, view Paul"s comment below)


See this http://mindprod.com/jgloss/htmlforms.html#IDVSNAME

What’s the difference? The short answer is, use both and also don’t worry around it. But if you desire to understand also this goofiness, here’s the skinny:

id= is for use as a tarobtain choose this: for links prefer this: .

name= is likewise offered to label the areas in the message send to a server via an HTTP (HyperText Transfer Protocol) GET or POST as soon as you hit submit in a kind.

id= labels the fields for use by JavaScript and Java DOM (Document Object Model).The names in name= must be distinctive within a kind. The names in id= need to be distinct within the whole document.

Sometimes the name= and also id= names will differ, bereason the server is expecting the exact same name from assorted develops in the same document or assorted radio buttons in the very same develop as in the instance over. The id= should be unique; the name= have to not be.

See more: Find Cheap Flights From Iah To Ewr ), Houston To New York Iah To Ewr

JavaScript essential distinct names, yet there were as well many files currently out below without distinct name= names, so the W3 civilization developed the id tag that was required to be distinctive. Unfortunately older browsers did not understand also it. So you require both naming schemes in your forms.