Conveying Information with Microdata
A web application or API parsing a page can interpret HTML marked up with microdata and respond to it. For instance, a search engine that returns results marked up with microdata could be parsed by a browser extension or script to better present the data to a visually impaired or colorblind user. Microformats are a preceding concept that serves the same goal. One key difference between microformats and HTML5 microdata is the way that the data is denoted. As shown in Listing 1-6, microformats use the class property of an object to indicate the fields on an object.
Listing 1-6. hCard Microformat Example
<div class="vcard"> <div class="fn">James Williams</div> <div class="org">Some Company</div> <div class="tel">650-555-3055</div> <a class="url" href="http://example.com/">http://example.com/</a> </div>
Microdata uses the same concept with slightly different notation. Instead of marking properties using classes, the itemprop keyword is used. The keyword itemscope marks an individual unit. At its core, microdata is a set of name/value pairs composed into items. Listing 1-7 shows a microdata example. The itemtype property indicates a definition of the object and specifies valid properties. You could use microdata to encode the names and scores on a leader board page or instructions and screenshots from a game.
Listing 1-7. Microdata Example
<p itemprop="address" itemscope itemtype="http://data-vocabulary.org/Address"> <span itemprop="street-address">1600 Amphitheatre Parkway</span><br> <span itemprop="locality">Mountain View</span>, <span itemprop="region">CA</span> <span itemprop="postal-code">94043</span><br> <span itemprop="country-name">USA</span> </p>