Arieh.co.il

Semantics – going beyond HTML – Microformats

As I tried to point out in my previous posts, HTML is a very rich language when it comes to describe semantic structures. But sometimes we might find that there are some structures we would like to describe more precisely than possible with the current list of elements. A good example is how we usually give some common id's to our sections- #header to the header DIV, #menu to the site's main menu, #footer to the footer and so on. Now – if you know about HTML5 you already know that many of these problems are solved there, but for various reasons I still avoid using H5 for most of my sites. For XHTML 1.0, there is one nice solution for us – microformats.

What are microformats?

Microformats are a set of standards that use an existing HTML tool – the class attribute – to introduce new semantic structures without harming the validation of our HTML.

The hCard

The hCard microformat is a way to markup contact details. Lets look at this example:

Name:
Arieh Glazer
Address
Sigalit st. Migdal Haemek Israel
Phone Numbers:
Home: 04-1235-678
Mobile:052-1235-678
Email:
Workarieh.glazer@gmail.com

This is a very semantic way to describe our contact information. But when a robot (such as google) looks at it, it might be hard for it to scrap the data in the exact way we meant it (well, google is probably a bad example because it is just smarter than anything we can imagine, but you can see my point). Now let's look at our hCard:

Name
Arieh Glazer
Address
Sigalit st. Migdal Haemek Israel
Phone Numbers:
Home: 04-1235-678
Mobile: 052-1235-678
Email:

Not too much markup addition, but a much richer meaning. Since not all class name are understandable, let's go over them:

As you can see – using almost the same markup, we doubled it's meaning. There are much more option to the hCard MF, so go look at the specification.

Another Example - The hProduct

This one is still in draft status, but I find it extremely useful so I use it anyway. This time I'm just going to include the full hproduct:

Prod Name:
Night Googles
Company:
NightOwels
Categories:
Nightvision
Fasion Accessory
Images:
Me hunting leprecons at night
Me shoping for candies with my googles
Description

There Googles can be used at a range of lighting scenes, ranging from starlight to mall light. As you can see, they are also quite cool looking and will make all your friends jealous

Price:
1,000 NIS

Now this again might look a bit pointless because the DL is so useful, but it can still help robots and MF tools to find more sense in it.

Some tools and links

JavaScript Reference, JavaScript Guide, JavaScript API, JS API, JS Guide, JS Reference, Learn JS, JS Documentation