0
ID, Name and Class
what is the difference between ID, name and Class?
3 Answers
+ 6
'name' attribute is specific to form elements (<input>, <select>, and so on) and it's used to indentify date (as a key in a pair key/value) submited to server... however, in Html < 5 it's also an attribute of the <a> tag, but it's deprecated in Html5, and 'id' should be used instead:
https://www.w3schools.com/tags/att_a_name.asp
+ 3
id is used as unique identifier of an element.
class is used for mutiple elements having that property. Name or other attribute is a property of an html tag.
+ 2
Use aĀ classĀ when you want toĀ consistently style multiple elementsĀ throughout the page/site. in the Classes more than one element that shares the same style.
Additionally, a given element can have more than one class associated with it, while an element can only have one id. For example, you can give a div two classes whose styles will both take effect.
Use theĀ ID when you have aĀ single elementĀ on the page that will take the style. Remember that IDs must be unique.
eg: -main-content, header, footer, or left-sidebar.
* Each element can have only oneĀ id
* Each page can have only one element with thatĀ id
* You can use the sameĀ classĀ on multiple elements.
* You can use multipleĀ classes on the same element.