I'm trying to figure out the "rules" for when I should use the ID attribute versus the CLASS attribute when setting styles for my HTML tags. I know ID is for handy reference in scripting, but it can also be used to apply styles. I know CLASS is used to apply styles. But can someone please tell me when it's better to use one versus the other?
Best way to think about it: id can be the target for a hyperlink. So you can do <p id="foo"> instead of <p><a name="foo"></a> and link to it with an <a href="/this/page#foo"> Not only is the former sematically cleaner, it is required in xhtml 1.1, where the name attribute has been dropped.
id must be unique on a page, and should carry some semantic meaning (ie, as something you might conceivably link to). A class is more generic, denoting a set of element of the "same" sort.
in that case, what would be the point of ever assigning styles to elements via the ID attribute? wouldn't it make more sense to always set styles with a class declaration and just to use ID for identifying?