Skip to content
Tutorials Center
My learning

Topics

Lesson 19 of 122 Β· Links and Navigation

Email, Phone and Download Links

Create email links with subject and body, phone and SMS links, and download links. Learn hreflang, type and the rel values nofollow, sponsored and ugc.

Not every link leads to another web page. A link can open the visitor's email program with a message already started, dial a phone number, start a text message, or save a file to their device. All of that is done with the same <a> element you already know. Only the href and a few extra attributes change.

This lesson covers those special links, plus the attributes that describe a link's destination to browsers and search engines: hreflang, type and rel.

A mailto: URL opens the visitor's default email program (or webmail service, if they have set one up) with a new message addressed to you:

HTML
<a href="mailto:[email protected]">[email protected]</a>

Showing the address as the link text is a good idea. Not everyone has an email program set up, and people can then copy the address instead.

Adding a subject, body and more recipients

You can prefill parts of the message with a query string. Start it with ? and separate fields with &:

Field Example Meaning
(address list) mailto:[email protected],[email protected] Several "To" addresses, separated by commas.
subject ?subject=Order%20question The subject line.
body &body=Hi%20there The start of the message text.
cc &[email protected] Carbon-copy recipients.
bcc &[email protected] Blind carbon-copy recipients.

Put together, it looks like this:

HTML
<a href="mailto:[email protected]?subject=Order%20%2312345&body=Hello%2C%0D%0A%0D%0AI%20have%20a%20question%20about%20my%20order.">
  Ask about order #12345
</a>

Encode the values

Because the subject and body live inside a URL, special characters must be percent-encoded:

  • A space becomes %20. (Don't use +: in a mailto: URL a plus sign stays a literal plus.)
  • A line break becomes %0D%0A.
  • &, ?, # and , inside a value become %26, %3F, %23 and %2C, so they aren't mistaken for separators.

Encoding by hand is error-prone. JavaScript's encodeURIComponent() does it for you. Type a subject and body below and watch the link update:

Build a mailto link

The URL Encoding lesson explains percent-encoding in detail.

Email addresses on a page attract spam. Bots harvest every mailto: link they find. For a busy public site, a contact form is often the better choice, and you will build one in the Forms chapter. Also remember that a mailto: link only starts a message; nothing is sent until the visitor presses Send in their own program.

On a phone, a tel: link offers to call the number. On a computer it may open a calling app, or do nothing if none is installed.

HTML
<a href="tel:+15555550123">+1 555-555-0123</a>

Write the href in the international format: a +, the country code, then the digits, with no spaces. The link text can use whatever format is friendliest for your readers. That way the link works for visitors in any country.

An sms: link opens the messaging app with the recipient filled in. You can suggest the message text with body:

HTML
<a href="sms:+15555550123?body=Hi%2C%20I%27d%20like%20to%20book%20a%20table">
  Text us to book a table
</a>

sms: is widely supported on phones, but the details of the body parameter have varied between platforms over the years. Test on real devices, and always offer another way to get in touch.

Contact links

The icons come from CSS attribute selectors: a[href^="mailto:"] matches every link whose href starts with mailto:. It is a neat way to label special links without extra markup. Depending on your device and browser settings, clicking a link in the preview may open an app or do nothing at all.

The download attribute tells the browser to save the linked file instead of opening it:

HTML
<a href="/files/menu-2026.pdf" download>Download the menu (PDF, 220 KB)</a>

Give download a value to suggest a file name. The browser may still adjust it, for example to remove characters that aren't allowed in file names:

HTML
<a href="/files/m26-final-v3.pdf" download="riverside-cafe-menu.pdf">
  Download the menu (PDF, 220 KB)
</a>

A few rules to know:

  • download only works for same-origin URLs (files on your own site) and for blob: and data: URLs created by your page. For a file on another site, browsers ignore the attribute and simply navigate to it.
  • The server can override it. A Content-Disposition response header wins over the attribute.
  • Tell people the file type and size in the link text, as in the examples above.

Downloads don't work in the preview. The editor's preview runs in a sandboxed frame without permission to download files, which is why the download examples on this page are read-only.

Describing the destination: hreflang and type

Two optional attributes describe what's at the other end of a link. They are hints only; the browser does not check them.

  • hreflang gives the language of the linked page, using a language tag like es or pt-BR. It helps when you link to a translation.
  • type gives the MIME type of the linked file, such as application/pdf or text/csv.
HTML
<a href="/es/" hreflang="es" lang="es">Leer en espaΓ±ol</a>
<a href="/data/prices.csv" type="text/csv" download>Price list (CSV)</a>

Note the difference between lang and hreflang in the first link: lang="es" says the link text is Spanish, so screen readers pronounce it correctly, while hreflang="es" says the destination is Spanish.

The rel attribute describes the relationship between your page and the linked one. You already met noopener and noreferrer in Link Targets and Page Jumps. Search engines read three more values:

Value Use it for
nofollow Links you don't want to vouch for.
sponsored Paid links: ads, sponsorships, affiliate links.
ugc Links inside user-generated content, such as comments and forum posts.

You can combine several values, separated by spaces:

HTML
<a href="https://example.com/blender" rel="sponsored noopener" target="_blank">
  The blender we recommend (affiliate link, opens in a new tab)
</a>

<p class="comment">
  Great recipe! I wrote about mine at
  <a href="https://example.org/my-soup" rel="ugc nofollow">my blog</a>.
</p>

Marking paid links as sponsored is expected by major search engines and, in many countries, honest disclosure is also a legal requirement. The visible text should say so too, as in the example.

Check your understanding

Quick check Β· 4 questions

of 4 answered You scored / 4 Β· perfect!

  1. 1. How do you write a space inside the subject of a mailto link?

    Values in a mailto: URL must be percent-encoded, and a space is %20. A + would appear as a literal plus sign.
  2. 2. What is the best href for a phone link?

    Use the tel: scheme with the international format: a plus sign, the country code and the digits. Format the visible text however you like.
  3. 3. You add download to a link that points to a PDF on another website. What happens?

    download only applies to same-origin, blob: and data: URLs. For other sites, the link behaves like a normal link.
  4. 4. A blog comment contains a link written by a visitor. Which rel value describes it?

    ugc stands for user-generated content. sponsored is for paid links, and noopener is about new tabs, not trust.

Summary

  • mailto: links start an email; add subject, body, cc and bcc in the query string, percent-encoded.
  • tel: links start a call; use the international + format in the href.
  • sms: links start a text message; test the body parameter on real devices.
  • download saves a same-origin file instead of opening it, and its value suggests a file name.
  • hreflang and type are hints about the destination's language and file type.
  • rel="nofollow", "sponsored" and "ugc" describe links for search engines.

Next lesson: Building Navigation Menus.