Quick Tip: Make Telephone Numbers Do Something

Quick Tip: Make Telephone Numbers Do Something

Tutorial Details
  • Estimated completion time: 30 secs
  • Difficulty: Beginner
  • Topic: Accessibility

I’m not going to begin this quick tip with the old “these days people view your websites on a multitude of devices” spiel, but it is true. Many mobile devices will do a good job of recognizing phone numbers in your HTML, making them clickable so you can directly call that number – but not always.

What happens if a user’s mobile doesn’t recognize a telephone number as being “callable”? Perhaps, for example, the way you’ve entered the number isn’t recognized by the platform. Missed opportunity!

(Check out Mark Hammond’s list of patterns which are recognized for iOS and Android..)


Make That Number Clickable

This one’s dead easy: wrap your phone numbers in anchors, but instead of using the http* protocol (or whatever else you’d normally stick in an anchor) use tel: or tel://. This way, even if you’ve used an unrecognized pattern, the device will still know what to do:

<a href="tel:+4411122233344">+44 (0)111 - 222 333 44</a>

Non-supporting browsers (your desktop, for example) don’t know what to do with the tel: protocol yet – unless the user has some kind of extension enabled which allows Skype to recognize telephone numbers. Google Chrome will happily ignore the click, but at the moment other major browsers start to cry. Other non-phone devices (such as the iPad) will recognize the number, prompting the user to add a contact to their address book – this would be a sensible approach for desktop browsers too.


Styling Phone Links

As an optional extra, let’s make it even clearer to the user that they’re looking at a phone link by styling each one. We’ll use an attribute value selector for this, targeting only the :before pseudo element of links which contain the string tel: within their href attribute:

a[href^="tel:"]:before {
	content: "\260E";
	display: block;
	margin-right: 0.5em;
}

The little carat there ^ denotes that it’s looking for any elements whose href attributes begin with the string we specify. tel: and tel:// will therefore both be covered here. We’ve slotted in a little unicode telephone \260E;, so we needn’t even use a webfont icon. Nice.


Nice hue eh? color: tomato believe it or not..

We’re all done here, in the name of accessibility give it a try!


Further Reading

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://www.facebook.com/brunocezar.ferreiratomaz Bruno Cezar Ferreira Tomaz

    Hahahaha. Simple and easy to do! Nice post, man!

  • http://www.creativeloop.co.zw/ Creative Loop Zimbabwe

    You’ve fallen in love with tomato, huh?

    • ianyates

      Get ready for another tutorial using tomato this week – but after that I’ll stop, I promise :)

      • http://www.espidesigns.com/ Mark Louie Espedido

        but tomato will be 2014′s official color believe it or not.

  • rw

    tomato again :)

  • Adam Srebniak

    callto: ;)

  • http://www.codeconquest.com/ Charles @ CodeConquest.com

    Nice tip and nice color! On the topic of telephone numbers, it’s also possible in HTML5 to have input elements with type=”tel”, but it’s not supported by most browsers yet.

  • Mfawa Alfred Onen

    Cool Tip, Thanks Ian!

  • Alex

    I think u intended to use margin-left, rather than a margin-right, don’t you?

    • Alex

      or even padding-right? :D

    • Patrick Johnson-Cheatham

      margin-left would put a margin to the left of the phone icon, he wanted it to the right to create some spacing between it and the telephone number itself. Could use padding as well if there was a background color being applied that he wanted to be seamless, but he didn’t specify a background color so margin is the right call.

      • ianyates

        You’ve saved me answering that one! Thanks :)

  • http://apkestudio.com/ Francisco Aguilera G.

    Hey, this is a great tip
    Pd: Hahaha tomato…

  • Adi Purdila

    Nice, had no idea that you can make it clickable, but I guess it makes sense since you can also use “mailto:”

    • ianyates

      It would be interesting to see what other values can bee added to href – aside from the usual protocols (http:, ftp: etc.) tel:, mailto:, non standards such as skype: and callto:, and fragment identifiers (#some-id) does anyone have any others?

    • ianyates

      Update! It seems the following protocols can also be used:

      facetime: (which opens the native app)
      wtai: (part of another spec, but intended for the same as tel:)
      dc: (direct call – used for radio networks or intranets)
      tel-av: (apparently there are some phones which invoke a video call using this URI scheme..)
      sms: and smsto: (which send text messages, but are poorly supported)

      Worth noting that few of these are actually standards, so not worth relying on..

      • Adi Purdila

        Cool, thanks for sharing :D

  • http://twitter.com/eakroko Andreas Krokowski

    Nice tip with the styling

  • Bounasser Abdelwahab

    i love the tomato color beleive it or not

  • Ian

    Would be nice if there is a standard for this so it’s just tel: or tel:// for all devices. Would also be nice if skype would detect these so the same can be used for both mobile and non-mobile sites. But I guess as you mentioned javascript could be used to dynamically create them so for someone on a pc it would be changed to skype:

    • ianyates

      That’s right, Skype is also triggered by callto: (weirdly) but currently ignores tel: which I believe has been the standard since 2004.

      Using JavaScript to perform some kind of browser sniffing is possible, but not fool-proof.. I’d thought about adding modernizr to this quick tip, to apply the styling only on mobile devices, but the touch events detection isn’t a perfect way of saying “this is a mobile phone”..

      • ianSimmons

        yeah I tried skype links extension in chrome which gives you the option to convert numbers to skype, callto, or tel links but only the skype and callto links trigger chrome to ask if I want it to use skype. The tel link does nothing. Seems like it’s more to do with non-mobile browsers just not knowing what to do with a tel: link.

        This might be helpful for php users. http://code.google.com/p/php-mobile-detect/wiki/Mobile_Detect . It has methods to distinguish between tablet and non tablet mobile devices but seems to be using the user agent string which I’m guessing would not be reliable for devices like the galaxy tab unless it identifies it’s self as a tablet. I don’t know but it’s worth looking into further. If only we could look for device specific calling functions rather than browser features or user agents.

  • http://twitter.com/maxlibin max li bin

    nice quick tip.

  • http://www.facebook.com/afoekema Albert Foekema

    Thats an quick awesome tip, cheers! :)

  • http://twitter.com/xeeeveee Jack Neary

    This is a technique I’ve used several times before, but in the article it states: “Non-supporting browsers (your desktop, for example) will just ignore clicks”

    I Have found this only to be the case in Chrome, the examples I’ve tried both fail in IE9 and FF16, throwing an unknown protocol error.

    The links used in the screenshot are the links on the page on the http://mobile.tutsplus.com/tutorials/mobile-web-apps/phone-number-links/ tutorial, as linked to at the bottom of this one.

    Is there anything more to this? =/

    • ianyates

      Hmm, you’re right. I checked in Chrome, but (stupidly) didn’t think to see what other browsers did with the tel: protocol. There’s no obvious solution yet, but I’ll get back to you :)

  • http://tempertemper.net/ tempertemper

    Great post– heading straight to my site to update the phone numbers with a link!

  • Lastrose Studios

    A good reason to do this, is that some devices will autodetect numbers and make them into a link. This can cause styling issues (for example if you have a phone number in the footer, no link styling for the footer, and your default link color is the same as your footer, the numbers in the footer will disappear). By pre-emptively making it a link, and then styling it, you eliminate that issue.

  • Pingback: Quick Tip: Make the Most of CSS Attribute Selectors | Webdesigntuts+

  • Pingback: Designing a Better Contact Page | Webdesigntuts+

  • Janus

    Nice and snazzy, but has issues when parsed by SCSS.