[thelist] CSS id or class?

Kid Stevens kstevens89 at comcast.net
Thu Aug 1 10:59:01 CDT 2002


According to W3Cs's HTML 4.0 standards:
7.5.2 Element identifiers: the id and class attributes
Attribute definitions
id = name [p.50] [CS] [p.49]
This attribute assigns a name to an element. This name must be unique in a
document.
class = cdata-list [p.50] [CS] [p.49]
This attribute assigns a class name or set of class names to an element. Any
number of elements may be assigned the same class name or names. Multiple
class names must be separated by white space characters.
The id attribute assigns a unique identifier to an element (which may be
verified by
an SGML parser). For example, the following paragraphs are distinguished by
their
id values:
<P id="myparagraph"> This is a uniquely named paragraph.</P>
<P id="yourparagraph"> This is also a uniquely named paragraph.</P>
The id attribute has several roles in HTML:
As a style sheet [p.183] selector.
As a target anchor [p.145] for hypertext links.
As a means to reference a particular element from a script [p.254] .
As the name of a declared OBJECT element.
For general purpose processing by user agents (e.g. for identifying fields when
extracting data from HTML pages into a database, translating HTML documents
into other formats, etc.).
The class attribute, on the other hand, assigns one or more class names to an
element; the element may be said to belong to these classes. A class name
may be
shared by several element instances. The class attribute has several roles in
HTML:

At 9:49 AM -0500 8/1/02, 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. I used to use IDs a lot more, but for the past couple years have
>used class almost exclusively. I know ID comes into play with DHTML, so you
>may want to make sections of your code (nav links, etc) available for future
>scripting, but is there any other reason for choosing ID over class or the
>other way around?
>
>What scenarios call for either or both?
>
>Thanks,
>-dave
>--
>For unsubscribe and other options, including
>the Tip Harvester and archive of thelist go to:
>http://lists.evolt.org Workers of the Web, evolt !

--
Sincerely,
Kid Stevens

"A democracy is a sheep and two wolves deciding on what to have for lunch.
Freedom is a well armed sheep contesting the results of the decision."
 - Benjamin Franklin



More information about the thelist mailing list