What is the difference between class and id? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is the difference between class and id?

24th Jan 2016, 11:18 AM
Debashis Nath
Debashis Nath - avatar
10 Answers
+ 6
class can be used many times but id can be used only once. Basically in HTML terms id is like head and class is like body. Hope you get my point.
29th Apr 2016, 9:02 AM
Prakhar Yadav
Prakhar Yadav - avatar
+ 2
You can put the same class for many elements . But, "Id" just for one element
28th Jan 2016, 5:04 AM
Mohammed Ibrahem
Mohammed Ibrahem - avatar
+ 2
The class selector could be used on several elements but id selector is specific for a single element.
4th Feb 2016, 4:32 PM
Saurabh Srivastava
Saurabh Srivastava - avatar
+ 2
id is unique whereas class is not , when you use class the properties will be applied on all elements that have the same class name, hope this help
23rd Jun 2016, 2:06 PM
goory
goory - avatar
+ 1
if your prooerty is repeated than use class or in other case use id
29th Jun 2016, 11:04 AM
sunil vishwakarma
sunil vishwakarma - avatar
+ 1
id is unique whereas class is not. class can be used for multiple elements.
29th Jun 2016, 8:03 PM
Shivam
0
in addition id is used in javascripts
22nd Aug 2017, 4:48 PM
Михаил Кукли
Михаил Кукли - avatar
0
Id is used to target single element but class can be used to work on multiple elements
25th Aug 2017, 3:56 AM
Shivam Mishra
Shivam Mishra - avatar
0
ID are unique whereas classes are not .one ID can be set to one element only wereas classes can be set for many elements . USAGE : if u wanna style a single element , ID can be used . but if u want to style many elements by just writing few codes classes are handy .
25th Aug 2017, 2:06 PM
Sashi Verma
Sashi Verma - avatar
0
the major difference is that IDs can only be applied once in a page while class can be used as many times in a page as needed
25th Aug 2017, 7:10 PM
Nkechi Laura
Nkechi Laura - avatar