ID, Name and Class | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

ID, Name and Class

what is the difference between ID, name and Class?

29th Oct 2017, 1:09 PM
A.J. Velasco
A.J. Velasco - avatar
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
29th Oct 2017, 1:21 PM
visph
visph - avatar
+ 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.
29th Oct 2017, 1:14 PM
Claudiu Stefan Haidu
Claudiu Stefan Haidu - avatar
+ 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.
29th Oct 2017, 1:26 PM
Elizabeth🌸
Elizabeth🌸 - avatar