The basic difference between Id and class it that, an ID can be applied to only single type of elements no matter how many times you apply or how many ids you create but in slight edge class is same as id but can be applied to different types of elements Am I Right? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

The basic difference between Id and class it that, an ID can be applied to only single type of elements no matter how many times you apply or how many ids you create but in slight edge class is same as id but can be applied to different types of elements Am I Right?

2nd Jul 2016, 6:47 PM
Vedant Patadia
Vedant Patadia - avatar
4 Answers
+ 1
Actually I believe ID is only for a specific element. Each element can have only one ID, and each page can have only one element with that ID. So you couldn't have 2 elements with same ID. A class is like a global rule, multiple elements can share the same class and will be styled accordingly.
3rd Jul 2016, 4:51 AM
Brendan Bax
Brendan Bax - avatar
- 1
<h1 id="sd"> <p id="sd"> both works... <h1 id="s d"> not allowed. <h1 class="s d"> <p class="s"> both allowed and both r in 's' class and h1 is in 's' class as well as in 'd' class...
13th Jul 2016, 2:23 PM
Kanak Majhi
Kanak Majhi - avatar
- 1
you mean to say, a single tag type cannot have different IDs...wherever I use it in the HTML structure
13th Jul 2016, 2:56 PM
Vedant Patadia
Vedant Patadia - avatar
- 1
"Id" is to identify an element and being used in header and footer mainly, while "class" is to identify a group of elements and also yes you are right
23rd Jul 2016, 7:23 AM
Saman Jafari
Saman Jafari - avatar