They say "id" is unique but we can use the same id name to style different elements, so how is it any different than class? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

They say "id" is unique but we can use the same id name to style different elements, so how is it any different than class?

21st Jul 2016, 7:44 AM
anil maharjan
anil maharjan - avatar
2 Answers
+ 1
Well, if you don't want to follow the standards then you're only "hurting" your self. The rules are there to make life easier for you.
21st Jul 2016, 8:15 PM
ZinC
ZinC - avatar
0
If you have the same id for multiple elements you will not pass validation. An id must be unique to an element. Think of it this way; you can style multiple elements the same by using class. But if you want something specific, such as creating a link to a specific section from one page to another, you would want to use id. There are more reasons of course. Here is some great reading material. Go to the section that talks about bar codes and serial numbers. Great comparison https://css-tricks.com/the-difference-between-id-and-class/
22nd Jul 2016, 1:30 AM
sirronMR