hCard
Continuing my discussion of microformats, let's take a look at the hCard. The hCard microformat is a way of identifying contact information in HTML. People can use tools to look into the HTML and extract this information as a vCard. vCard is a standard for an electronic business card. There are a number of values you'd expect (name, phone number, organisation, etc.). hCard takes these labels and uses them as class names around data in HTML.
Here are the more common values you can use in hCard (for the complete list, see the wiki:
- fn (family name)
- nickname
- url
- tel (telephone)
- adr (address)
- org (organization)
- etc...
Every hCard starts inside a block that has class="vcard"
. So, a very simple hCard might look like this:
<div class="vcard"> <span class="fn">Jesse Skinner</span> <a class="url" href="http://www.thefutureoftheweb.com">http://www.thefutureoftheweb.com/</a> </div>
Some of these types have subproperties. For example, the 'tel' value contains 'type' and 'value'. This way you can specify separate home and business phone numbers. The 'adr' type has a lot of subproperties (post-office-box, extended-address, street-address, locality, region, postal-code, country-name, type, value). An address might look something like this:
<div class="vcard"> <div class="fn">Jesse Skinner</div> <div class="adr"> <span class="locality">Berlin</span>, <span class="country-name">Germany</span> </div> </div>
The class names don't have to mean anything within your page. However, you can always take advantage of them to style your contact information. You could also style them in your browser's User Style Sheet, so that you can find them while you surf the web.
The hCard standard is very flexible. It doesn't matter which tags you put the classes on. It certainly doesn't have to be in nested div tags. You could just mark up your contact information any way you like, and then wrap the data in span tags to tie the data together. For example, it can be within regular text in a paragraph:
<p class="vcard"> My name is <span class="fn">Jesse Skinner</span>. I live in <span class="adr"><span class="locality">Berlin</span>, <span class="country-name">Germany</span></span>. I work for <span class="org">Strato AG</span>. I have a web development blog at <a class="url" href="http://www.thefutureoftheweb.com/">http://www.thefutureoftheweb.com/</a>. </p>
There's lots of tools already, and more on the way. If you don't want to install a browser plugin, or if you want to give all visitors to your site a way to download your hCard as a vCard, X2V is a service that does just this. Just link to:
http://suda.co.uk/projects/X2V/get-vcard.php?uri=[URL with an hCard]For example, click here to download a vCard of this simple hCard:
My name is Jesse Skinner. I live in Berlin, Germany. I work for Strato AG. I have a web development blog at http://www.thefutureoftheweb.com/.
hCard, like other microformats, is wonderfully simple yet incredibly powerful. You can begin using it right away with very little work, without waiting for the standard to be widely used. As more people start looking for hCards (and your contact information), your web site will already make things easier for them.