HTML class attributes aren't just for CSS

HTML's class attribute was meant to be used in several ways, not just as a CSS tie-in. According to the HTML spec, class attributes are a general-purpose semantic hint. Here's an example of such a usage:

<div class="calendar">

There are at least three ways classes are useful outside the CSS context:

  1. They make HTML structurally self-documenting. HTML is fairly generic. Classes allow you to specify the meaning of various parts of your document, making it easier for yourself and others to unravel its meaning in the future.

  2. They serve as triggers for unobtrusive JavaScript. Now that hard-coded event attributes are dying off, class attributes allow JavaScript to dynamically select and operate on various parts of the document.

  3. Classes are a key part of microformats, which allow online tools to extract meaning from HTML code. Being plain old snippets of HTML, microformats are readable by humans using browsers. But because they're built in a standardized way, they can also be understood by software.

Comments:

Post a Comment:
Comments are closed for this entry.
About

My name is Greg Reimer and I'm a web technologist for the Sun.COM web design team.

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today