# New Tabs, rel & mailto/tel

> Opening links in a new tab requires a companion `rel` attribute to close a security hole. `mailto:` and `tel:` hand off to the operating system instead of navigating the browser.

Subject: HTML | Lesson 16 of 42 | 5 min read
Interactive lesson: https://codewithanimation.in/html/target-rel-and-protocols
Previous: [Paths & Fragment Links](https://codewithanimation.in/html/link-paths-and-fragments.md) | Next: [The img Element & Alt Text](https://codewithanimation.in/html/img-and-alt.md)

## What they are

`target` controls where a link opens. `target="_blank"` opens in a new tab or window. Without anything else, that new page has access to `window.opener`, a reference back to your original tab. A malicious page can use that reference to silently redirect the tab that launched it, a technique called tabnapping. Adding `rel="noopener"` severs the opener connection. Adding `noreferrer` also suppresses the `Referer` request header. Both together is the standard pattern.

`mailto:` and `tel:` are URL schemes that hand off to the operating system rather than navigating the browser. `href="mailto:hello@example.com"` asks the OS to open the default email client with that address pre-filled. `href="tel:+15551234567"` asks the OS to dial the number, which on mobile opens the phone app.

## Why it matters

The tabnapping attack is subtle: the user clicks an external link, the new tab opens, and nothing looks wrong. But the opened page runs `window.opener.location = 'https://phishing-site.com'` and the original tab silently redirects. The user glances back at the original tab and sees a convincing fake login page. `rel="noopener"` makes `window.opener` null in the new tab, shutting this attack down entirely.

`mailto:` and `tel:` links reduce friction on mobile. A phone number wrapped in a `tel:` link lets a user tap once to call instead of copying the number and switching apps. An email address in a `mailto:` link opens a compose window with the address already filled in. Both patterns are especially valuable on mobile where switching between apps and copying text is cumbersome.

## How it works

For external links that open in a new tab, always pair `target="_blank"` with `rel="noopener noreferrer"`. Modern browsers (since 2021) automatically add `noopener` behavior to `_blank` links, but being explicit is clearer and maintains correct behavior in older browsers. The `rel` attribute takes a space-separated list of relationship types, so both values sit in the same attribute.

The `mailto:` href follows the format `mailto:address?subject=Subject&body=Body`. All three parts after the colon are optional: a bare `mailto:` with no address opens a compose window with everything blank. Use `encodeURIComponent` in JavaScript if you are building the href dynamically, since spaces and special characters in the subject or body must be percent-encoded.

The `tel:` href uses the E.164 format: `tel:+15551234567`. Include the country code and omit spaces and dashes in the `href` value, even if you display the formatted number as the link text. The browser does not reformat the number.

## Common mistake: Opening external links without rel="noopener noreferrer"

Every `target="_blank"` link without `rel="noopener"` is a potential vector for tabnapping. The risk is low on a personal blog and higher on a site that lets users post links, because user-posted links can point anywhere. Make `rel="noopener noreferrer"` a habit for all external `_blank` links rather than a case-by-case decision. Linters like eslint-plugin-jsx-a11y can flag missing `rel` automatically.

## Tip: Pre-fill mailto: subject and body for one-click feedback

A feedback link like `href="mailto:support@example.com?subject=Feedback&body=Page%3A%20docs%2Fguide"` opens a compose window with the subject and page URL already filled in. Users send better reports when the context is pre-populated. Encode the values with `encodeURIComponent` if you build the href in JavaScript; write percent-encoded values manually if it is static HTML.

## Try it: Try it

See `target="_blank"` paired with `rel`, a `mailto:` link with a pre-filled subject, and a `tel:` link in their natural rendered form.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/html/target-rel-and-protocols

## Check yourself

### Question 1

Why should you add rel="noopener" to a target="_blank" link?

- A. To prevent the opened page from accessing window.opener and redirecting your tab
- B. To stop search engines from following the link
- C. To prevent the browser from sending cookies to the destination

Correct answer: A

Without `rel="noopener"`, a page opened via `target="_blank"` can access `window.opener` and silently redirect the original tab. `noopener` makes `window.opener` null in the new tab, shutting down that attack.

- Why not B: That is rel="nofollow". noopener is specifically about severing the window.opener reference to prevent tabnapping.
- Why not C: Cookies are governed by the SameSite cookie attribute and CORS, not by the rel attribute. noopener only severs window.opener.

### Question 2

What does rel="noreferrer" do in addition to what rel="noopener" already does?

- A. It also suppresses the Referer request header
- B. It prevents the link from opening in a new tab
- C. It tells search engines not to follow the link

Correct answer: A

`noreferrer` implies `noopener` and also prevents the browser from sending the `Referer` header, hiding the origin page from the destination site. Use both together for external links in new tabs.

- Why not B: noreferrer does not change the target behavior. It adds privacy on top of noopener by not sending the Referer header.
- Why not C: That is rel="nofollow". noreferrer suppresses the Referer header and implies noopener, but has no effect on crawlers.

### Question 3

Which href value is correct for a tel: link to the number +1 (555) 123-4567?

- A. tel:+15551234567
- B. tel:+1 (555) 123-4567
- C. phone:+15551234567

Correct answer: A

The `tel:` href uses E.164 format: country code, then digits only, no spaces or punctuation. Write the formatted number in the link text for readability; the href value stays compact.

- Why not B: The href value should use E.164 format with no spaces, parentheses, or dashes. The human-readable formatting belongs in the link text, not the href.
- Why not C: The correct URI scheme is tel:, not phone:. The tel: scheme is defined in RFC 3966.

## Remember this

- Always pair `target="_blank"` with `rel="noopener noreferrer"` to prevent tabnapping.
- `noreferrer` implies `noopener` and also suppresses the `Referer` header; both together is the standard combo.
- `mailto:address?subject=X&body=Y` opens the email client; `tel:+country-digits` opens the phone dialer.
- `rel` is a space-separated list: `rel="noopener noreferrer"` sets both values in one attribute.
