Possible Duplicate:
Use HTML tag names, classes or IDs in CSS?
In CSS, what are the major differences with classes and ids? Why use classes for xyz and why use ids for abc? I know there are similar questions on here, but none are really answered properly.
I know to use classes with multiple elements with the same properties and ids with unique properties or unique elements, but why? Wouldn’t it be an acceptable practice to just use classes so that you don’t confuse yourself switching between classes and ids? What is the difference in regards to speed and optimization, SEO, etc…?
Wouldn’t it be an acceptable practice to just use classes so that you don’t confuse yourself switching between classes and ids?
Yes it would be, but let’s say you have 1 class for 20 boxes that has like 20 css properties set and you want 1 div to have a different border color it would be better to just give an id to that div instead of creating a whole new class. (if you get what I mean)
Just add the
instead of creating a whole new class with the same 19 properties and 1 that is different. Ofcourse you aren’t force to use a id for this, you can also assign another extra class to this div. (Such as
<div class="box special">)What is the difference in regards to speed and optimization, seo, etc…?
This has a simply answer, if you optimize your css, it will result in a lower file size thus resulting in a faster load time which will improve your rankings. (Yes website speed/loading time does matter A LOT)