+ 13
Still can't get difference between id and class..!!☹️
41 Antworten
+ 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.
+ 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.
+ 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
+ 5
The biggest different is that id is only used once whereas class can be used as many as you want.
+ 3
ID is for one element whereas class could be for a group of elements
+ 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;}
+ 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
+ 2
id can only be used for declared unique element. but in class it can be used for group of elements.
+ 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
+ 2
Id is unique and can only be used once while class can be used multiple times
+ 1
I think Id only works at one place whereas class can be called any time
+ 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.
+ 1
ID ek hi baar use KR skti ho pure page me..
Class jitne baar chaho otne baar use KR skti ho page me.
+ 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.
+ 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.
+ 1
id is one and class multiple
+ 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
+ 1
Yep id is unique and class styling is across all tags. Id cant be duplicated :)
+ 1
thank you guys, for answers....it was also tricky for me...