Microformats for you and me
After nearly 3 months sitting on my bookshelf, I got around to
What and How
Very simply, Microformats give our already semantic xhtml elements an extra layer of meaning when using a common set of attribute values. Consider the case of an “hCalendar”, a microformat that gives xhtml the structure of an events calendar. An events calendar is simply a set of events. This relationship is easily described by a parent-children relationship. The problem is that xhtml can easily describe parent-children relationships, yet it cannot semantically describe this calendar-events relationship. Microformats do just that… they provide a way to describe this common relationship through the use of attribute values.
To create an “hCalendar”, you would write something like the following:
> <div class="vcalendar">
>
> > <span class="vevent"/>
> > <div class="vevent"/>
> > <dl class="vevent"/>
>
> </div>
As you can see, the supplementary calendar-events structure is added by setting specific attribute values, in this case ‘vcalendar’ and ‘vevent’. Microformats use exiting attributes like ‘class’ and ‘rel’ as hooks for this structure, in the same way these attributes can be used as hooks for additional CSS information. Additionally, these attributes can be applied to whichever element you choose*. I demonstrated the use of the same attribute/value pair (class=“vevent”) on the ‘span’, ‘div’, and ‘dl’ elements in the example above.
[* The rules for applying attributes to elements are the same as the existing xhtml spec]
Why you should use them
While I foresee a wide array of future uses for Microformats, there are limited practical applications today. That being said, the small number does not mean they have limited value; their use can provide substantial value. For example: later this week I am going to re-write the concert-listing page for my orchestra website. I am going to use the hCalendar Microformat to code this season’s events. I will then use an open-source converter to allow users to download a iCal file of this calendar on the fly.
Why would I do this? Because it’s advantageous. Using the hCalendar Microformat I can…
Continue reading