Computer Science Canada

What is the difference between Class and ID?

Author:  HazySmoke)345 [ Fri Feb 09, 2007 12:29 am ]
Post subject:  What is the difference between Class and ID?

All HTML tags can accept attributes "class" and "id", but what is the difference between them?

I've been reading a book an HTML, and this book doesn't do a good job on explaining the difference. In fact, it seems to me that the author uses them interchangably.

Is there a difference?

Author:  md [ Fri Feb 09, 2007 1:02 am ]
Post subject:  RE:What is the difference between Class and ID?

There is a huge difference. An id identifies a particular tag, gives it a name that can be used by scripts, CSS, etc. to refer to that specific tag (or potentially all identically named tags). Classes are a CSS construct which allow you to specify CSS attributes, they in no way identify a tag or a set of tags.

Author:  rdrake [ Fri Feb 09, 2007 8:32 am ]
Post subject:  RE:What is the difference between Class and ID?

Basically like md said, the id tag is used to identify usually just one element. The class tag is usually used to identify multiple elements.

So if you want to apply CSS to one single element, you'd use id, otherwise to apply it to multiple elements, use class.

Author:  HazySmoke)345 [ Fri Feb 09, 2007 10:20 pm ]
Post subject:  Re: What is the difference between Class and ID?

Thanks guys. I've given each of you some bits. I can't give too many though Sad I'm broke.


: