Friday, February 24, 2012

Embedding Phone Numbers with HTML5 for iOS

Snippet to embed contact data in a web page so that an iOS device can recognise text as a phone number or as contact data. Use the 'itemprop' attribute, although you can also wrap the div in a 'vcard' class, and setting the class of the phone number span to 'tel' seemed to do funky things too:

<div itemscope>
  <span itemprop="name">Rob Carr</span>
  <a class="nowrap" href="" itemprop="email"></a>
  <span class="nowrap" itemprop="tel">+44 1234 567 890</span>

I added a 'nowrap' class (white-space:nowrap;) purely for styling and usability. When the name or phone number is clicked on, you get the iOS dialogue box:

Contact info recognition doesn't seem to work on HTML5 desktop browsers, and no idea about whether other mobile devices will recognise the 'itemprop' property.

You can wade through the Microdata spec for HTML5 at, or Google for more examples. HTML5 Doctor always a good read.


  1. Although can also set format-detection for Safari/iOS. Enables or disables automatic detection of possible phone numbers in a webpage in Safari on iOS.

    meta name="format-detection" content="telephone=yes"

    Default value is 'no' BTW.

  2. There's a new bit of HTML5 - the href="tel:" attribute:
    Book now, call 01234 567 890