Which of the following is the main difference between an ID and a class?

Questions & AnswersCategory: Programming LanguageWhich of the following is the main difference between an ID and a class?
Adam asked 3 years ago

Which of the following is the main difference between an ID and a class?
a. Classes are for use with spans and IDs are for use with DIVs
b. IDs are supposed to be only used once per page but Classes can be used multiple times per page, and one element can have more than one Class but should have only one ID
c. IDs are better than Classes
d. None of the above

1 Answers
Lokesh Kumar Staff answered 3 years ago

b. IDs are supposed to be only used once per page but Classes can be used multiple times per page, and one element can have more than one Class but should have only one ID
 
Explanation: The main difference between ID and class is that ID can be used only once in a web page but a class can be used multiple times. Moreover, an element can also have multiple classes but it can only have a single ID.