Id vs class


I finnished the lessons with HTML and finnaly i start with CSS
but i noticed on the first lesson of CSS the code is very...different from what i was thought in school
mostly IDs used instead of div class etc.
they told me to always use Class because it makes it easier for you
and you can only use one ID where as you can use class as many as you would like.
So just to end this debate i have in my head .
what is better to use ID? or Class?
and Why?


i have on word for that, or actually two: poor teaching

If your teacher is convinced that classes are better then id's, he clearly doesn't understand the difference between them.

i found this stackoverflow question, to be very useful. The short answer is: Neither is better, they are different and you should use the right one at the right moment.

For the layout of a page, i would use div's. (since this are unique and important elements), i wouldn't use classes. The layout of your page is important and the names are unique so you use div.

If you have multiply ordered list for example, yea, then i would use classes. (since you can only use id's once)

to truly understand why this difference is some important, you should read about the point system css uses for conflicting properties, you can find a good read here


thank you very much il read it imm


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.