Do we need to use both ID and name? Can they be the same?

In regards to the element, why do we use the ‘id’ and ‘name’ attribute when both have the same value?

My understanding is the ‘id’ attribute is required to connect with correct label element while the ‘name’ attribute is just a unique name for the input element.

The name attribute is used in the HTTP request sent by your browser to the server. The id is for CSS and JavaScript as a reference that the element with that id.

They do not have to be the same but they can be as in the case in the tutorial.

Id's must be unique to the tag that it is inside and only used once on any given html page.

name doesn’t have to be unique, for example there are cases where you would use it many times with radio buttons.

Here’s a link to an example where the name attribute is used many times:

Also, a page with a list of attributes:

8 Likes