Difference between id and class | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Difference between id and class

I am learning CSS.I want to know the the difference between id and class. i .e., when to use id and when to use class.

19th Mar 2017, 8:49 AM
Charan Kumar Reddy
Charan Kumar Reddy - avatar
3 Answers
+ 1
İ think İD is for one specific tag and class is for one or more tags. A tag can also have multiple classes like: <a class="marine sky important"> wich can be useful for css styling
19th Mar 2017, 8:57 AM
EagleEye
EagleEye - avatar
+ 1
Hello Charan Kumar Reddy. The main difference is that the Id must be unique. Only one element can have the Id name you chose for it. The class selector can be applied to several elements. For example you have like 5 paragraphs and you want to style only 3 of them, use the same class selector for these three and style it on your stylesheet. With an id name you can only style one paragraph. Usually don't use Id selectors to style your text. Better keep it for script once you'll be familiar with Javascript.
19th Mar 2017, 9:02 AM
Nicolas Bonnet
Nicolas Bonnet - avatar
0
thanks
19th Mar 2017, 9:18 AM
Charan Kumar Reddy
Charan Kumar Reddy - avatar