Blog

Happy Vishu

11 December
2015
microdata means ? By, Appeonix

Microdata is a standardized way to provide additional semantics in your web pages.

Microdata lets you define your own customized elements and start embedding custom properties in your web pages. At a high level, microdata consists of a group of name-value pairs.

The groups are called items, and each name-value pair is a property. Items and properties are represented by regular elements.

Example

  • To create an item, the itemscope attribute is used.
  • To add a property to an item, the itemprop attribute is used on one of the item's descendants.

Here there are two items, each of which has the property "name" −

<html>
   <body>
      
      <div itemscope>
         <p>My name is <span itemprop="name">Zara</span>.</p>
      </div>
      
      <div itemscope>
         <p>My name is <span itemprop="name">Nuha</span>.</p>
      </div>
      
   </body>
</html>

It will produce the following result −

Properties generally have values that are strings but it can have following data types −

Global Attributes

Micro data introduces five global attributes which would be available for any element to use and give context for machines about your data.

Attribute Description
itemscope This is used to create an item. The itemscope attribute is a boolean attribute that tells that there is Microdata on this page, and this is where it starts.
itemtype This attribute is a valid URL which defines the item and provides the context for the properties.
itemid This attribute is global identifier for the item.
itemprop This attribute defines a property of the item.
itemref This attribute gives a list of additional elements to crawl to find the name-value pairs of the item.

Properties Datatypes

Properties generally have values that are strings as mentioned in above example but they can also have values that are URLs. Following example has one property, "image", whose value is a URL −

<div itemscope>
   <img itemprop="image" src="tp-logo.gif" alt="TutorialsPoint">
</div>

Properties can also have values that are dates, times, or dates and times. This is achieved using the time element and its datetime attribute.

<html>
   <body>
      
      <div itemscope>
         My birthday is:
         
         <time itemprop="birthday" datetime="1971-05-08">
            Aug 5th 1971
         </time>
         
      </div>
      
   </body>
</html>

It will produce the following result −

Properties can also themselves be groups of name-value pairs, by putting the itemscope attribute on the element that declares the property.

Microdata API support

If a browser supports the HTML5 microdata API, there will be a getItems() function on the global document object. If browser doesn't support microdata, the getItems() function will be undefined.

function supports_microdata_api() {
   return !!document.getItems;
}
    

Modernizr does not yet support checking for the microdata API, so you’ll need to use the function like the one listed above.

The HTML5 microdata standard includes both HTML markup (primarily for search engines) and a set of DOM functions (primarily for browsers).

You can include microdata markup in your web pages, and search engines that don't understand the microdata attributes will just ignore them. But if you need to access or manipulate microdata through the DOM, you'll need to check whether the browser supports the microdata DOM API.




The itemscope attribute is a key part of microdata. This attribute indicates that the contents of an HTML element are part of the same element. Nested HTML elements are denoted using the itemprop attribute and are propertiesof that element. The element given in the example above includes the term and definition properties; the value of the term property is “Webpage”. This markup means that web crawlers can easily recognize the term and definition in the text block.

The value of this property can also be text, a link (URL), date and/or time The property may also comprise an element containing embedded properties.

The type attribute is another important part of the itemscope element. The element type denotes what it describes: this could be a person, business, event, product, article etc. The element type should be specified within theitemtype attribute.

Yandex currently supports the following element types:

  • encyclopedic articles (for more information, please see our section on Markup for an encyclopedia article);
  • word definitions (for more information, please see our section on Markup for term definitions).
  • Schema Scholarly Article semantic markup standard Schema.org.

You can find more information on HTML5 microdata on the W3C consortium website and WHATWG community website.




Author,



Appeonix Creative Lab