Mobile Web Quick Tip: Phone Number Links

Mobile Web Quick Tip: Phone Number Links

Tutorial Details
  • Technology: Mobile Web
  • Difficulty: Beginner
  • Completion Time: 5 - 15 Minutes

This quick tip demonstrates how to create phone number links with HTML. The techniques in this tip work on both Android and iPhone devices and can greatly improve the experience of mobile web site visitors.

Default Phone Links

By default on iOS and Android, the device browser will “magically” create links out of text interpreted as a phone number. When the user taps one of these links, the device phone application will launch. The exact phone number patterns that will be automatically turned into links vary between platforms, but I’ve listed several of the patterns I’ve successfully tested below:

  • 555-5555 (iPhone Only)
  • (555) 555-5555 (Android + iPhone)
  • +1 (555) 555-5555 (iPhone Only)
  • 555 5555 (iPhone Only)
  • 555 555 5555 (Android + iPhone)
  • +1 555 555 5555 (iPhone Only)
  • 555.5555 (iPhone Only)
  • 555.555.5555 (Android + iPhone)
  • +1 555.555.5555 (iPhone Only)

If your site or app uses one of the cross-device formats above, your users should already be able to quickly make calls just by tapping the text.

Creating Phone Number Links

The recipe for creating your own phone number links is simple. Instead of using a normal link based on the HTTP/S protocol or the file system, you can use the “tel:” protocol. This works just like a normal link would, only instead of the href attribute pointing to a URL or file, you prepend either “tel:” or “tel://” to a phone number.

Check out the following examples to see this in action:

<!-- Embedded within normal page text -->
<p>If you'd like to talk, <a href="tel:5555555">Call Me!</a></p>
<!-- Linking a custom image -->
<a href="tel://555-5555"><img src="phone.png" alt="Call Now!" /></a>
<!-- Cross-platform compatible (Android + iPhone) -->
<a href="tel://1-555-555-5555">+1 (555) 555-5555</a>

NOTE: The above code should be tested on a physical device. It will not work on the iOS SDK emulator.

The last example snippet is especially worth noting. Many web developers don’t have the luxury of performing extensive mobile device testing on both iPhone and Android, so it would be easy to miss the fact that some of the phone formats listed at the beginning of this tip will not be auto-recognized on all devices.

Because the phone formats recognized may vary between devices, I suggest always wrapping your phone numbers in a link with the “tel://” prefix. Not only will doing so ensure that the greatest number of devices will link to the phone application, but this also seems to be a more explicit, accessible, and semantic approach to handling phone links.

Of course, if the content you are creating might be viewed on a device without a phone, you should either use a server-side language to only add the “tel:” links when necessary, or you should check the device type with JavaScript and add the links to the page progressively when applicable.

Disabling Link Detection

For both Android and iPhone, you can easily disable automatic phone number linking with the following meta tag:

<meta name="format-detection" content="telephone=no" />

This meta tag will disable phone number auto-linking while still allowing you to manually create phone number links using the “tel://” method described above.

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://www.appsbynight.com Josh Jones

    Great tip! I had no idea you could do that within an “href” tag. Learn something new every day!

    • http://mobile.tutsplus.com Mark Hammonds
      Author

      Thanks for the feedback, Josh! I’m really glad to hear that mobile web quick tips are useful for people. :)

  • http://www.delveswoodwebdesign.co.uk/ Delves Wood Web Design

    Great advice, with these tips, I’ve been able to modify our e-commerce system, so that order numbers and company registration numbers etc, don’t get automatically converted to links on the iPhone, while adding links with “tel:” lets me control the links for phone numbers.

    • http://mobile.tutsplus.com Mark Hammonds
      Author

      Awesome, glad to hear this tutorial helped!

  • naren

    can I add text in tel “”.
    +1 (555) 555-5555

    • http://mobile.tutsplus.com Mark Hammonds
      Author

      Great question. Substituting letters for numbers within a tel:// link worked for me on iPhone but not on Android. Consequently, if you’re working with a data source that provides them in this format you’ll need to convert them to numbers at some point in order to normalize the links for both platforms.

  • Roger

    Can you show an example for linking UK phone numbers from US? So we’d need the full number with country code etc. Something like the following…

    +44-20-7631-0001

    -Thanks

  • http://www.clarkwebdesign.com rick clark

    Great article. Unfortunately, I can’t get the number to show up in my motorola android. Listed below is the code I am trying to use:

    <a href=”tel://321 805 0588″&rt;<img style=”margin: 0 3px;” src=”http://m.clarkwebdesign.com/wp-content/uploads/2012/03/btn_phone.png” alt=”Call Now!” /&rt;</a&rt;

  • Michael

    Anyway you can turn this off within the iPad itself? I use a website that already makes phone numbers hyperlinks to other places within that site. When I try to use this on the iPad it denies me access to the link asking instead if I’d like to add the phone number to my contact list.

    Thanks

    Mike

  • Bartdude

    Thanks for this !

    A client comes with an stranger request, he would like his shop address to be clickable and launch the GPS navigation to it when clicked. Is there anyway to do this ? I’m thinking microformats, link to GPS coordinates, …

    • Pat Ducat

      I too am looking for the answer to this question. Have you had any luck @fb9c047ed28d71ccd863350eddb2a451:disqus ?

  • Zakie

    thats fine.

    But i have a question.

    I dont want the link will be shown in desktop pc/mac, the link will be shown only in mobile devices.

    Currently 555-555-5555 works in mobile, but this link does not work obviousley in desktop pc. so i want to hide or disable that link for desktop pc users so they cant click. but i must be clickable in mobile.

    any clue?

    • fubals

      Hey Zakie,

      Have you found any solution to that obvious issue? I have tried a few things, but so far, no joy.

    • Steven

      Anyone have the complete code that could be used to determine if a mobile device is being use. If mobile, allow phone number to be dialed.. If not, then a message with the phone number.

    • http://www.facebook.com/richard.calvert.902 Richard Calvert

      This is my JQuery solution – wrap the number in a span, give the span class=”mobile_tel” then load jQuery and this script:

      if(screen.width <= 500){
      $('.mobile_tel').wrap(function() {
      return '‘;
      });
      };

  • http://www.promotemobilemarketing.co.uk mobile web design

    hey there and thank you for your information – I’ve certainly picked up anything new from right here. I did however expertise a few technical points using this website, as I experienced to reload the web site a lot of times previous to I could get it to load properly. I had been wondering if your web host is OK? Not that I am complaining, but sluggish loading instances times will sometimes affect your placement in google and could damage your high-quality score if advertising and marketing with Adwords. Well I’m adding this RSS to my e-mail and could look out for much more of your respective exciting content. Ensure that you update this again very soon.

  • Brent

    Any ideas on how to make this work with WordPress “Custom Links”? I need to add phone numbers like above (href=”tel:123.456.7890″) and WordPress strips out the “tel:”
    Any solution would be greatly appreciated!? I have not been able to find a plugin or answer anywhere. vey frustrating!
    Thank you,
    Brent

    • http://mobile.tutsplus.com Mark Hammonds
      Author

      Hey Brent, sorry, but I don’t have any experience implementing this in WordPress. If it isn’t something you can control from the WordPress admin filtering settings, then you’ll likely have to write or find a custom plugin.

    • http://www.anphira.com Gen

      Brent,

      I don’t have any problem with the following in wordpress:
      <a href=”tel://1234564001″>T (123) 456-4001</a>

      I am using the current version of WordPress, version 3.4.1. If you are using an older version, then that could be the issue.

    • http://www.facebook.com/richard.calvert.902 Richard Calvert

      I made a plugin to do this in WordPress – please use it if you want. http://wordpress.org/extend/plugins/telephone-number-linker/

      • jt

        Great plugin. Works perfectly. Thanks!

      • richard calvert

        That’s cool! – I’m hoping to improve it in future.

  • http://www.horsespy.co.uk Lee Greenhill

    Thanks Mark. Just what I was looking for!

  • Sai

    Excellent post…Thanks a lot, but i believe that the “disabling link detection” does not work on Windows Phone. Please advice with a solution.

    • putz

      buy an android. :P

  • http://www.facebook.com/jeff.passwater Jeff Passwater

    Great post, and I see the code works for most people. Can I ask where you put the code? I am working with a template, and I have tried plugging it in a lot of different places, and it either kills the whole site, or doesn’t show up at all. Any help would be great.

  • http://twitter.com/jjspelman JJ Spelman

    Thanks for the tip! I had just finished telling someone that I thought it only worked with actual text telephone numbers and not images. Glad you corrected me!

  • sucksanotherbug

    awesome.. the s3 running jellybean incorrectly uses the Text of the hyperlink rather than the actual hef attribute. so many hyperlinks in jellybean do not work properly. i can guarantee we will never see a fix.

  • http://twitter.com/susanreednet Susan Reed

    I have a question. What about phone numers in Mexico? Some of the numbers are 01 800 xxx xxxx and some of them are like xx-xxxxxx

  • http://twitter.com/SEO__Company SEO Professional

    Nice little piece of code. Perfect for tow trucks, taxi cab, limo sites.

  • engrmudasirmalik

    this is great but what if i want to check that if it is computer then disable link and for devices enable this link??
    How can i do that?

  • Aniruddha

    Thanks for this tip. It was very useful in my current project.
    Nice to learn new stuff here…