+ 13

Still can't get difference between id and class..!!☹️

17th Oct 2017, 5:16 PM
Raman Singh
41 Réponses
+ 21
In HTML : id = a label, a tag, a sticker, ... see it as you want. this label must be unique, no other element must use it inside your HTML. Then you can target in detail which element you want to work on inside your CSS or Javascript. Only use it if you want to apply something specific at this element, it's no need to give an id for each element. An element can have only one id. class = a model, a charter,.. every single element inside your HTML using the same class will receive the CSS. Become usefull to edit several element at once. An element can own infinity of class. e.g: <p id="my_unique_id" class="color_red big_text"... <ul> <li class="color_red"... The previous example use : - 1 id call "my_unique_id" - 2 class call "color_red" and "big_text" Two elements use the same class "color_red" and will receive the same CSS.
17th Oct 2017, 10:12 PM
Geoffrey L
Geoffrey L - avatar
+ 8
Try to think of it in terms of motor vehicles and license plates. A class would be the category of vehicle, such as a car versus a truck, and the ID would be the license plate on that vehicle. You can have two cars that are red, but legally you cannot have the same license on both of these cars at the same time. While it is possible to place a particular ID into your code multiple times, it is not correct. <div id="mycar"> <p class="car">This is my car.</p> </div> <p class="car"> This is you car. </p> <p class="van"> This is a van.</p> <p class="truck"> The is a truck. </p> .car { color: red ; } .truck { color: blue ; } .van { color : green ; } #mycar { background-color : black ; } I hope this helps someone to see this in a different way.
3rd Nov 2018, 12:01 AM
Dakota
+ 7
it's easy! Id is like roll no. of any student !(unique) while class is like gender.(defines the nature) Hope! my answer serves the purpose
5th Jul 2018, 10:23 AM
Rana
Rana - avatar
+ 5
The biggest different is that id is only used once whereas class can be used as many as you want.
29th Aug 2018, 5:23 PM
Maxwell D. Dorliea
Maxwell D. Dorliea - avatar
+ 3
ID is for one element whereas class could be for a group of elements
11th Jun 2018, 2:08 AM
Jorf VJ
Jorf VJ - avatar
+ 3
Id and class are one of the easy way css call html element or tag. You should write hash (# ) before you write a id name and period(. ) before a class name. Example of Id <p id="max">The big car</p> #max{color:blue;} Example of Class <p class="max">The big car</p> .max{color:blue;}
14th Nov 2018, 2:08 PM
Maxwell D. Dorliea
Maxwell D. Dorliea - avatar
+ 2
if we get away from the technical definition then ID can not be used more than once in a page it means if we are using ID in another division on any tag its value should be unique it should not be repeated where as we can use a Class as many times as we want to it doesn't matter if the values will repeat the same formatting effect will be applied to the same value as well
30th Jun 2018, 5:30 PM
Aditya Singh
Aditya Singh - avatar
+ 2
id can only be used for declared unique element. but in class it can be used for group of elements.
5th Aug 2018, 4:59 AM
Sandini Wijesinghe
+ 2
The <id> attribute assigns a unique name to an element. Yes , it can be used twice but the value must be different. The <class> attribute also assigns a name to an element. The value can be repeated over and over again in subsequent class attributes. Eg. <span id="x"> class ="info">blah <\span> <span id="y"> class ="info">blah <\span> <span id="z"> class ="info">blah <\span> As you can see, the values for the id attribute are specific and should not be repeated. However the class attribute has the same value repeated. You can also reference on the Web Consortium website on Html structure https://www.org/TR/html4/struct/global.html#class-id-example
22nd Nov 2018, 2:11 PM
Lordian Mur
Lordian Mur - avatar
+ 2
Id is unique and can only be used once while class can be used multiple times
12th Jun 2019, 10:44 AM
Ebugo_
Ebugo_ - avatar
+ 1
I think Id only works at one place whereas class can be called any time
22nd Oct 2017, 8:32 AM
harshit singh
harshit singh - avatar
+ 1
id is like class. But id is used once in an html page for a same name of element. we can use class a lot of time.
14th Jul 2018, 2:21 PM
Top Moumoute
Top Moumoute - avatar
+ 1
ID ek hi baar use KR skti ho pure page me.. Class jitne baar chaho otne baar use KR skti ho page me.
21st Aug 2018, 1:14 PM
Bazil Farooqui
Bazil Farooqui - avatar
+ 1
The major difference is that IDs can only be applied once per page, while classes can be used as many times on a page as needed.
19th Nov 2018, 11:44 AM
MICHAEL AIYEPADA
MICHAEL AIYEPADA - avatar
+ 1
IDs can only be used once per web page, whereas classes can be used multiple times. IDs are "heavier" in terms of CSS specificity: if an ID and class attribute reside on the same element, and that element's ID selector (in CSS) conflicts with its class selector, the ID selector wins out (all other things being equal). IDs are good for use when you want to use GetElementByID() in JavaScript. Otherwise, I'd stick to classes in HTML. YMMV. Hope this helps.
4th Dec 2018, 9:00 PM
Pdeyonghe
Pdeyonghe - avatar
+ 1
id is one and class multiple
20th Dec 2018, 4:56 PM
MЯOV
MЯOV - avatar
+ 1
The major difference is that IDs can only be applied once per page, while classes can be used as many times on a page as needed
20th Jan 2019, 10:29 PM
Muhamad Hendrik Wicaksono
Muhamad Hendrik Wicaksono - avatar
+ 1
Yep id is unique and class styling is across all tags. Id cant be duplicated :)
18th Feb 2019, 5:14 PM
Zion
Zion - avatar
+ 1
thank you guys, for answers....it was also tricky for me...
20th Feb 2019, 11:21 PM
ERNEST MOFOKENG
ERNEST MOFOKENG - avatar