+ 1

What is the difference between class and id?

(<div> <p class="first">This is a paragraph</p> <p> This is the second paragraph. </p></div><p class="first"> This is not in the intro section</p><p> The second paragraph is not in the intro section. </p>) if i write id instead of class in both place and css i gave thus #id the result same both cases. i could not understand clear this

28th Jul 2016, 7:29 PM
Abid Hussain
Abid Hussain - avatar
5 odpowiedzi
+ 4
1-You can use class any time and any where you want...but you must use id once 2-with class , you can select many tags , but with id , you can select needle in a hystack ((Select A Tag In Hundreds Tags)) 3-ID is more specific than Class , ID Has 100 score and class is 10 Example: HTML: <p class="color" id="color" > ID Is More Specific</p> CSS: #color { color: red; } .color { color: blue; } So The Paragraph Will Be Red , Because ID Has 90 Score More Than Class
30th Jul 2016, 11:06 AM
Mahbod Sr
Mahbod Sr - avatar
+ 2
both of them are block level elements. however id is used only once and should not be called again and again while vlass can be used again and again for some divs having similar styling..i suggest u to use class in every cases to avoid confusion... ids are used by javascript to call certain actions
29th Jul 2016, 4:45 AM
Shrijan Shrestha
Shrijan Shrestha - avatar
+ 2
thanks
29th Jul 2016, 4:48 AM
Abid Hussain
Abid Hussain - avatar
+ 1
id use for one element only .. class for many
7th Aug 2016, 11:26 PM
Khalid
Khalid - avatar
+ 1
when you are working with class .. the modifications are applied to that respective class where ever it is used or written. while working with id . your modifications remain unique . same class name can be used more than once. bt id name is used only once .
10th Aug 2016, 1:29 PM
Shivani