ID vs Class | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

ID vs Class

In CSS the major difference is that IDs can only be applied once per page, while classes can be used as many times on a page as needed. My question is why? Is that because ID works as a global attribute and class not or smth else in the logic? https://code.sololearn.com/W5HDCnlq0XZ8/?ref=app

5th Aug 2020, 3:51 PM
Bits!
2 Answers
+ 2
Class is used to target various element at a time hence it is common for all if they have similar style to do. Id is used to target a single element hence it should be different for all. And class is also a global attribute in html 5.
5th Aug 2020, 4:19 PM
Divya Mohan
Divya Mohan - avatar
6th Aug 2020, 2:21 AM
Bits!