CSS - Is CLASS or ID better?

SagaLore

Elite Member
Dec 18, 2001
24,036
21
81
A web-designer that I know has suggested that I use IDs, instead of CLASSes, because IDs don't have to look up the Z-order which allows it to load faster. But most information I'm reading based on the W3C standard suggests that I use CLASSes, and not IDs, because there are limitations with IDs.

Which one is better? What are the limitations of each?
 

Huma

Golden Member
Oct 10, 1999
1,301
0
0
from what I know:

IDs are required when you need to reference that particular div for things like dhtml layer swapping. Classes can't be referred to in this manner.

I will use classes to assign any styles to a span/div, and if I need to control that div, it gets an ID as well as a class.

z-index is usually automatically determined by nesting order if not specifically stated in your stylesheet.
 

Huma

Golden Member
Oct 10, 1999
1,301
0
0
well...

you're using styles to format almost everything on the page, so the site doesn't work in netscape 4.x, which is not so good, especially for a business website.

as useful as I find styles for handling things, i'm a table building sort of guy. the markup is a lot more readable without having to reference two pages to figure out what's being rendered, and it offers better crossbrowser compatibility.