0
Hi, I’m new to html programming and wanted to know the difference between a class and an id? EX:
#principal{
}
.principal{
}
0
Hi, I’m new to html programming and wanted to know the difference between a class and an id? EX:
#principal{
}
.principal{
}
0
Id are unique, so it’s very common to use Javascript when we want to modify only one element, since classes are generalized, you can create a class and reuse it in other components.
From the little experience I have, I’d say when we use CSS it is very common to use more classes than id, when we want to work with Javascript we use more id for interaction (click, touch, etc) of that element.
However it is possible to work with an id and reuse it in various parts of your HTML, is not wrong, but is not common.
Source: Tableless
-4
They are pretty much the same thing. Both are used to name items created in HTML. I suggest you use an id on more important items like a main div and use classes on less important things like smaller Divs and etc.
Browser other questions tagged html css
You are not signed in. Login or sign up in order to post.