+ 4

What is the difference between id and name attribute in input tag?

<input id="mysearch" name="searchitem" type="search" /> Sometimes i saw codes that does'nt put one of them. Not sure either id or name attributes.

22nd Jun 2017, 1:16 AM
Zareen Azara
Zareen Azara - avatar
4 Answers
+ 9
input name attribute is meant for screen readers and form processing, that's HTML5 making the web accessible to all. The id is purposely meant to be targeted by css and JavaScript for styling and dynamic manipulations.
22nd Jun 2017, 1:21 AM
Benneth Yankey
Benneth Yankey - avatar
+ 6
Id value is expected to be unique for each element in a document context (<html>), while name is expected to be unique in a <form> for unique or collection of elements (grroup of radio button for example )... https://developer.mozilla.org/en-US/docs/Web/API/Element/name https://developer.mozilla.org/en-US/docs/Web/API/Element/id
22nd Jun 2017, 1:50 AM
visph
visph - avatar
+ 3
name attribute is used to process a form submition id attribute is for identify the html element in css styling, or javascript processing
22nd Jun 2017, 1:38 AM
⏩▶Clau◀âȘ
⏩▶Clau◀âȘ - avatar
+ 2
Just want to add that the name attribute is also used in forms when submiting data to server.
22nd Jun 2017, 1:29 AM
Ulisses Cruz
Ulisses Cruz - avatar