Mastering HTML Links: href & target

Go beyond simple links. Learn to control their destinations, behavior, and security like a pro with the essential `href`, `target`, and `rel` attributes.

Lesson ProgressStep 1 of 9
0 EXP

Welcome! Let's learn about HTML links, the <a> tag, which stands for 'anchor'.

The `href` Attribute: The Destination

The href (Hypertext Reference) attribute is the most crucial part of an anchor (<a>) tag. It specifies the destination URL—where the link should go.

Without an href, the <a> tag is just a placeholder and isn't a keyboard-navigable link.

<a href="https://www.example.com">Visit Example</a>

System Check

What is the primary purpose of the `href` attribute?

Advanced Holo-Simulations

0 EXP

Log in to unlock these advanced training modules and test your skills.


Achievements

🔗
Link Master

Construct a well-formed HTML link with a valid href.

🎯
Target Pro

Correctly use the target='_blank' attribute.

🛡️
Security Expert

Apply security best practices using the rel attribute.

Mission: Build a Secure External Link

Create a link to `https://www.google.com` that opens in a new tab and includes security best practices. Our AI assistant will provide real-time feedback.

A.D.A. Feedback:

> Awaiting input...

Challenge: Assemble the Link

Drag the components into the correct order to form a valid HTML link.

href="https://example.com"
<a>
</a>
Visit Site

Challenge: Complete the Attributes

Fill in the missing attribute names for a secure, external link.

<a="https://"="_blank"="noopener">...</a>

Consult A.D.A.

Community Holo-Net

Peer Project Review

Submit your "Secure External Link" project for feedback from other Net-Runners.

Mastering the Web's Connective Tissue: A Deep Dive into HTML Links

The hyperlink, created by the <a> (or "anchor") tag, is arguably the most important element in HTML. It is the fundamental concept that transforms a collection of documents into a "web" of interconnected information. While creating a basic link is simple, mastering its attributes is essential for building secure, accessible, and user-friendly websites.

Section 1: The `href` Attribute (The "Where")

The `href` (Hypertext Reference) attribute is the heart of the link. It specifies the destination URL. Without it, the <a> tag is just a placeholder. The `href` attribute can accept several types of URLs:

  • Absolute URLs: This is a full web address, complete with the protocol (https://) and domain name. You must use this when linking to external websites.
    <a href="https://www.google.com">Go to Google</a>
  • Relative URLs: This links to another page *within your own website*, relative to the current page. If you are on `about.html` and link to `contact.html`, the browser looks for it in the same folder.
    <a href="contact.html">Contact Us</a>
  • Root-Relative URLs: This links to a page relative to your website's *root folder*. The leading forward slash `/` tells the browser to start from the domain root. This is often the most robust way to link internally.
    <a href="/images/logo.png">View Logo</a>
  • Fragment Identifiers (Page Anchors): By using a hash `#` followed by the `id` of an element, you can make a link that jumps the user to a specific section of the *same page*.
    <a href="#section-2">Jump to Section 2</a>

Section 2: The `target` Attribute (The "How")

The `target` attribute specifies *where* to open the linked document. By default, it opens in the same tab or window, but you can change this behavior.

  • _self: (Default) Opens the link in the same browsing context (the same tab).
  • _blank: Opens the link in a **new tab** or window. This is the most common value and is highly recommended for external links.
  • _parent: Opens the link in the parent browsing context. If the current page is in an `iframe`, this will load the link in the main window.
  • _top: Opens the link in the top-most browsing context, breaking out of all `iframe`s.

Section 3: Security & UX with the `rel` Attribute

The `rel` (Relationship) attribute clarifies the relationship between your page and the linked page. When used with target="_blank", it is a **critical security feature**.

Security Warning: The `target="_blank"` Vulnerability

When you link to a page with target="_blank", the new page gains partial access to your page via the window.opener JavaScript object. A malicious page could use this to redirect your original page to a phishing site.

  • rel="noopener": This is the **fix** for the vulnerability. It severs the connection by setting window.opener to `null`, preventing the new tab from accessing your page.
  • rel="noreferrer": This provides an additional benefit: it prevents the browser from sending the `Referer` HTTP header, which hides information about where the user came from. It also includes the `noopener` behavior.
  • rel="nofollow": This is an instruction for search engines, telling them "do not endorse this link" and not to pass any "link juice" (ranking power) to the destination. It's often used for user-generated content or paid links.
Best Practice: Always use rel="noopener noreferrer" when you use target="_blank".

Section 4: Special Links (`mailto:`, `tel:`, `download`)

The `href` attribute isn't just for web pages. It can trigger browser actions:

  • Email Links: Using mailto: will open the user's default email client. You can even pre-fill the subject and body.
    <a href="mailto:support@example.com?subject=Help!&body=My issue is...">Email Support</a>
  • Telephone Links: Using tel: will prompt a "call" dialog on mobile devices.
    <a href="tel:+15551234567">Call Us</a>
  • Download Attribute: Adding the download attribute tells the browser to download the linked file instead of trying to display it. You can even suggest a new filename.
    <a href="/files/report.pdf" download="Annual-Report-2025.pdf"> Download Report</a>

Section 5: Accessibility and Best Practices

A link is useless if a user doesn't know what it does.

❌ Bad Practice

Ambiguous link text like "Click Here" or "Read More" is confusing for screen reader users, who often navigate by tabbing from link to link.

✔️ Good Practice

Use descriptive link text that makes sense out of context. Instead of "Click here for our report," write "Read our 2025 Annual Report."

The `title` attribute can add a tooltip on hover, but it is **not** a substitute for good link text, as it's inaccessible to keyboard-only and mobile users. Use it only for supplementary, non-essential information.

HTML Links Glossary

`<a>` (Anchor Tag)
The fundamental HTML element used to create a hyperlink to another web page, file, location, or URL.
`href` (Hypertext Reference)
The most important attribute of the `<a>` tag. It specifies the destination URL of the link.
Absolute URL
A full web address, including the protocol (e.g., `https://`) and domain name. Used for linking to external sites.
Relative URL
A partial web address that points to a file or directory in relation to the current page (e.g., `contact.html`).
Root-Relative URL
A URL that starts with a `/`, pointing to a file or directory relative to the site's root domain (e.g., `/images/logo.png`).
`target` Attribute
Specifies where to open the linked document (e.g., in the same tab or a new one).
`_self`
The default value for the `target` attribute. Opens the link in the current tab.
`_blank`
A value for the `target` attribute that opens the link in a new tab or window.
`rel` Attribute
Defines the "relationship" between the current page and the linked page. Used for security and SEO.
`noopener`
A `rel` value that prevents a new tab (opened with `target="_blank"`) from accessing the original page's `window.opener` object. This is a critical security feature.
`noreferrer`
A `rel` value that prevents the browser from sending the `Referer` header to the new page. It also includes `noopener` behavior.
`nofollow`
A `rel` value that instructs search engines not to "endorse" the link or pass ranking authority to it.
`mailto:`
A URL prefix used in an `href` attribute to open the user's default email client.
`tel:`
A URL prefix used in an `href` attribute to initiate a phone call on a mobile device.
`download`
A boolean attribute that instructs the browser to download the linked file instead of navigating to it.
Fragment Identifier
A part of a URL beginning with a `#` that points to a specific element `id` on a page, allowing the link to "jump" to that section.

About the Author

Author's Avatar

TodoTutorial Team

Passionate developers and educators making programming accessible to everyone.

This article was written and reviewed by our team of web development experts, who have years of experience teaching HTML and building robust and accessible web applications.

Verification and Updates

Last reviewed: October 2025.

We strive to keep our content accurate and up-to-date. This tutorial is based on the latest HTML5 specifications and is periodically reviewed to reflect industry best practices.

External Resources

Found an error or have a suggestion? Contact us!