posted on:December 16, 2009
Class Names Revisited
In this article I am going to remind us all about the class names. I’ll try to explain the true meaning of classes in HTML and take a look at their usage.
True Meaning of Class Names in HTML
Just as the element’s id, class names placed inside a class attribute are actually used to identify the element. Their "secondary" purpose is to be used as a more precise style sheet selector.
Class attribute is a part of the HTML structure so opinion that it’s there only for styling purpose is wrong. Sure, widely spread habit among web designers is to use class names almost exclusively for that purpose, but saying that class attribute is only for CSS selecting would be more or less the same as saying that element tag names or ids are there only to be used in style sheets.
Class attribute allows multiple class names. While element can have only one id you can assign as many class names to an element as you want. Think of it like this: YOU have your unique name, but you can also be identified as a web designer, male, athlete, student, friend, geek etc. While your name is your ID these attributes are your “class names”.
Just as you can belong to many groups of people HTML elements can belong to different “groups” so it makes sense that class attribute can accommodate many class names.
We said that classes in HTML are part if its structure. Just as you need to take care of semantic meaning when building structure of a document or wrapping content inside HTML elements, you need to take care of class name semantics.
How to choose a proper class name for the element? Well, remember that you need to identify the element not describe its appearance. Step away from thinking about classes as purely presentational tools. Let’s use that personal analogy once more, if you would assign “class name” for yourself you can’t describe yourself as a “red shirt” because next day you might want to wear a blue shirt. So, HTML element can’t be identified as “red”, cause it can easily change color.
Hope this article help you understand the meaning of class names or perhaps remind you what the class names stand for. 🙂
Enjoyed the article?
Then don't miss our next one! Subscribe to our RSS feed or share it with your friends.
Comments (11 Comments)
Sorry, the comment form is closed at this time.