Have you ever seen those small grey descriptions in Google search results below the title? If you’re curious on how to get them, then the answer is embedded metadata.
With the words embedded metadata we refer to a way to add invisible information in an HTML/XHTML document. These informations will be machine readable, by Google or Yahoo for example, but will not be seen in the browser. Basically we’re going to add some properties to our HTML elements that will say to Google: “Hey, this h1 title is my name, and this h2 title is my work title, I’m a web developer“. As a result Google will show in the search results, under our page title, a little line with our name and our work title.
There are three main embedded metadata specifications that are struggling to become a standard, and probably none of them will be 100% standard like it’s happening with HTML5, so it’s better to have a basic understanding of how all of them work. The projects are:
- RDFa: a specification strictly connected with XHTML, supported with the XHTML1.1 doctype
- Microformats: the most diffused specification till the arrive of HTML5
- Microdata: the HTML5 specific set of instructions.
The history of the formats shows how RDFa started the topic, basing everything on the Resource Description Framework; it’s complex but well supported.
Then arrived Microformats, with his friendly structure and became very popular. With HTML5, the group decided to create his own version of interconnected information organization. Let’s avoid asking if we really needed another specification for this standard, and let’s start seeing some example on how enrich our HTML with a machine readable representation of data.
We’re going to see how the three different standards can be used to represent our name and our work title, in a typical about me page. These informations could be added to google search results and every future applications that will use embedded metadata.
Let’s start with an RDFa example:
<div xmlns:v="http://rdf.data-vocabulary.org/#" typeof="v:Person"> <p>Name: <span property="v:name">Marco Lisci</span></p> <p>Title: <span property="v:title">Web Developer</span></p> </div>
First of all RDFa needs a proper name space when working with it, to avoid conflicts in the XML tree. So we’re going to add the xml schema, with xmlns:v=”http://rdf.data-vocabulary.org/”, the official Google RDF schema. Then we have to declare the type of what our informations are going to represent, in this case a Person adding typeof=”v:Person”.
If you look at the documentation, there are a lot of other types that can be used, according to our needs. Then, using the v root, we’re going to add the properties to our span elements. Using v:name, we’re telling to the system that will read our page that what’s inside the span is the name of the person we want to represent. And the v:title will be read as the title of the current person. As you can see, you’re not breaking the XHTML, it’s about adding some little properties that can be really useful. You can find the entire specification on the W3 website.
Microformats are far simpler that RDFa. The reason is clear, there’s no need to specify an xml schema and use properties. It’s all about using special names in classes. So our previous example will be:
<div class="vcard"> <p>Name: <span class="fn">Marco Lisci</span></p> <p>Title: <span class="title">Web Developer</span></p> </div>
Yes, it’s really so simple. Just add the class vCard to the wrapper element, and add fn to the name span element (the fn is the only required class), and title to the work title span element. This is the representation of hCard microformat element. By doing this, Google and other softwares will be able to grab the info and use them.
There are a lot of other elements that you can use to enrich your hCard representation, all listed at the official hCard page. There’s also an hCard creator, a little form to create an hCard representation from your info. I think that Microformats are really great, but if you’re following the HTML5 train, you can’t miss microdata.
Microdata are the Microformats for HTML5. and this spec has it’s own DOM API, so it could become the standard when HTML5 will be widely spread. We can already start using it since Google announced microdata support. So, let’s take a look at how it works:
<div itemscope itemtype="http://data-vocabulary.org/Person"> <p>Name: <span itemprop="name">Marco Lisci</span></p> <p>Title: <span itemprop="title">Web Developer</span></p> </div>
You can see more than one similarity with RDFa. Also in this case you have to add a data vocabulary with itemtype. We used again the official Google vocabulary for microdata. The other important thing is to add itemscope to the wrapper element of all your informations. Then with itemprop we can assign to our spans the name and title values. It’s a little bit complex compared to Microformats, but could become the standard.
When you’ll get a little confidence with these three standards you’ll want to add more and more infos to your pages. Every one of these standards has schemas and properties for the most common informations used on the web, even nested elements, but they’ll follow the simple structure described here. The official specification page of RDFa is at the W3 website, it’s a little bit complex, but useful to understand deeply the Resource Description Framework.
Remember that all of them are Google ready, so pick one and start experimenting! I personally use Microformats, but I’ll switch to HTML5 Microdata if it will show a solid foundation.
Your Turn To Talk
I hope you found this article useful. Please feel free to chime in by leaving a comment below! ;)