[thelist] CSS id or class?

Simon Willison simon at incutio.com
Thu Aug 1 09:57:01 CDT 2002


At 09:49 01/08/2002 -0500, David.Cantrell at Gunter.AF.mil wrote:
>In the thread "I've found a great use for <span>", Simon Willison stated he
>uses IDs on his elements for styling purposes.
>
>My question is, when is it more appropriate to use ID vs class, and
>vice-versa?
>
>I would think ID is supposed to be unique in the document, though I may be
>wrong here.

You're exactly right. IDs should be used for things that only occur once,
classes for anything that appears multiple time. I tend to work by dividing
a document in to as few logical divs as possible and only giving them an ID
if I need to apply styles to them specifically. An excellent explanation of
when to use what can be seen here:

http://www.mako4css.com/BasClass.htm




More information about the thelist mailing list