0

What is the actual difference between ID and Class selectors in CSS when used practically?

I have been struggling to get the difference b/w these two selectors. Upon searching I found that the ID selector is only for a particular element and CLASS can be used on multiple elements, but I was able to use the ID selector on multiple html elements. Needed a bit more clarity in this. Thanks in advance.

2nd Dec 2023, 10:29 AM
Optimus Prime
Optimus Prime - avatar
2 Answers
+ 3
The web browser tolerates a lot of bad code, but you should NOT use the same ID on multiple elements of the same page. It should be the unique identifier of a single element. On the other hand, class is perfectly suitable to style many elements, potentially even different types of elements, at the same time.
2nd Dec 2023, 11:16 AM
Tibor Santa
Tibor Santa - avatar
+ 1
Thanks for the clarification mate.
2nd Dec 2023, 11:52 AM
Optimus Prime
Optimus Prime - avatar