+ 2
What is the difference between class and id in html?
3 Answers
+ 13
You can use "many" same class name in in different elements in one webpage while you can only use "one" unique ID name. If you want to ID another part of the website, use another name.
+ 11
Id is more specific than class.
Multiple classes can be added to an element, but only one Id for each element
Also, class selectors are started with a ". " in CSS, while "#" is used for Id.
Example,
HTML :
<div id="div1" class="div">Some text</div>
CSS :
#div1 {
background-color: blue;
}
. div {
font-weight: bold;
}