What is the difference between ID and CLASS in css selector? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the difference between ID and CLASS in css selector?

I'd and class selector

14th Jul 2018, 6:50 AM
Durgesh Gupta
Durgesh Gupta - avatar
4 Answers
+ 8
Id is unique it means it can be assigned to only one element. Where as class can be assigned to more than one elements. Class comes handy when you have to apply same css to a bunch a elements.
14th Jul 2018, 10:55 AM
Mitali
Mitali - avatar
+ 2
The id is used to identify a particular element and can not be repeated within the html. In contrast, class, you can use it as many times as you wish to give css styles to one or multiple elements (<div> </ div>, <p> </ p> <section> </ section>, etc.) within the html. On the other hand, an html tag can contain multiple class but not multiple id (only one). in this way you can summarize the css code in case different elements share the same style ... example: <div id=“text-info” class=“top info”></div> <div class=“top examples”></div> <p class=“info”></p> —— css —— #text-info{ border-radious: 15px; } .top{ top: 10px; } .info{ font-size: 24px; } .examples{ font-size: 20px; color: #ff0000; } ——————————- #text-info => only for first “div” .top => for both “div” .info => for first “div” and “p” .examples => for seccond “div” ——————————— REGARDS!
15th Jul 2018, 6:52 AM
Eze
14th Jul 2018, 7:11 AM
Louis
Louis - avatar
0
ID : YOU CAN ONLY HAVE SINGLE ID NAME MEANS YOU CAN USE ID IN ANY OF HTML TAGS YOU WANT BUT ID NAME GIVEN TO ONE TAG CANNOT BE USED IN ANOTHER. EG : <p id="paragraph"></p> THAN YOU CANT USE ID NAME paragraph IN ANY OTHER TAG HAVING ID. YOU CAN SELECT IT USING #. CLASS : YOU CAN HAVE CLASS NAME AS MUCH AS YOU WANT. EG : <p class="paragraph"></p> <p class="paragraph"></p> YOU CAN HAVE MULTIPLE CLASS HAVING paragraph AS A NAME. YOU CAN SELECT IT USING (.). Hope this helps☺️☺️.
14th Jul 2018, 7:11 AM
Meet Mehta
Meet Mehta - avatar