educative.io

Educative

Id vs name attributes

hi,
I was wondering what is the difference between the id and the name attribute…

Hi @ofek_lavi,

Thank you so much for your feedback. Let me provide you with an explanation that is as follows:

  • The name attribute of the input tag inside the html form is mainly used to reference form data after the form is submitted. So, the form elements with the name attribute will only have their values passed at the time of form submission. It can also be used to reference html elements in javascript.

  • On the other hand, id is used to specify a unique id for an html element. Not more than one html element can have the same id. The id attribute is used to point to a specific styling defined in a style sheet(css). It can also be used in javascript to access and manipulate the element based on the specific id.

Hopefully that clarifies the confusion.

Happy Learning!

thank you!