There are two aspects to choosing class names to use in your XHTML documents:
As you know, XHTML is a small language: it doesn't make a lot of fine-grained distinctions between the syntactic elements of your document. Consider, for example, the paragraph element.
In plain XHTML, there is only one kind of paragraph. As a writer (or “content provider”), however, you use several different kinds of paragraphs:
You can use the class attribute of XHTML to distinguish these different types of paragraph. So you can have different tags like
Why would you want to do this? Well, the obvious reason would be so that you could style the different kinds of paragraph differently. But you might also want to leave “clues” in the document so that a curious reader might better understand exactly what the document contains. (These clues could also be used by computer programs in various ways.)
To summarize: In selecting a class name, try to come up with a name that explains what the function of this particular XHTML element is in the context of your document.
The W3C offers some excellent tips on picking effective class names. (You should take a look at this brief document right now.)
Once you've decided on a suitable name for a class, you need to determine a legal XHTML expression that expresses that name.
First, do not use any XHTML tag as the name of a class. (Those sequences of characters are all reserved by the language for its own use.)
Second, it's a good idea to use names for your XHTML classes that follow the XML rules for the names of XML tags and attributes. This way, it would be easy for someone to write a computer program to convert your document into “pure” XML (which may be the way all web content is stored in a few years—so you might as well prepare now).
These are the naming rules for tags and attributes in XML:
(Incidentally, the rules given above apply to any identifiers used in your XHTML documents, i.e., the value of any id attribute.)
Don't forget that XML is case-sensitive, so the class my-opinion and My-Opinion are distinct classes. (On the other hand, these classes would be semantically identical, so you wouldn't want to use these distinct identifiers in your documents—pick one and stick with it.)
[ Return to the CPSCI 105-01 homepage ]
Brian J. Rosmaita <contact me>