Skip to main content

Advanced Link Attributes

You already know the two most important attributes of the <a> tag: href (the destination) and target (where the link opens).

However, the Anchor tag has several other powerful attributes that control link security, influence SEO, and change the link's fundamental behavior (like forcing a download or initiating a call).


1. Security and SEO Control: The rel Attribute

The rel attribute, short for relationship, defines the relationship between the current page and the linked document. This is crucial for security and controlling how search engines treat your links.

rel ValuePurposeWhen to Use
noopenerSecurity: Prevents the new page (opened via target="_blank") from gaining control over the original page's window object.Always use this when target="_blank" is present.
noreferrerPrivacy: Hides the referrer information, preventing the linked site from knowing where the user came from.Used alongside noopener for maximum security and privacy.
nofollowSEO: Instructs search engines (like Google) not to follow the link or pass any "link equity" (SEO juice) to the destination page.Use for sponsored content, paid links, or links you don't trust.
ugcSEO: Marks content generated by users (User Generated Content), such as comments or forum posts.Use for links submitted by users on your site.
sponsoredSEO: Marks links that are advertisements, sponsorships, or paid placements.Use for all paid links.

Security Best Practice Example

When opening any external link in a new tab, you should always include both noopener and noreferrer for user safety and to prevent malicious code injection.

index.html: Secure External Link
<a href="https://externalsite.com" target="_blank" rel="noopener noreferrer">
Visit External Site
</a>

SEO Example

index.html: SEO Control
<a href="/sponsor-link" rel="nofollow sponsored">
Check out our sponsor!
</a>

2. Behavior Attributes: Download and Protocols

These attributes change the link's action from simply navigating to executing a function.

The download Attribute

Adding the download attribute tells the browser that the linked resource should be downloaded instead of displayed in the browser.

  • Value: The attribute can be left empty, or it can be set to a value which will be suggested as the filename for the downloaded file.
index.html: Forcing a Download
<a href="/documents/report.pdf" download="Annual Report 2024.pdf">
Download the Annual Report (PDF)
</a>

You can use the href attribute with special protocols to trigger native device applications instead of navigating to a URL.

Email (mailto:)

Triggers the user's default email program to open a new message, pre-addressed to the specified email address.

<a href="mailto:codeharborhub@gmail.com?subject=Question%20About%20HTML">
Email Support
</a>
note

We used %20 for spaces in the subject line. This is called URL encoding.

Phone (tel:)

On mobile devices, this triggers the device's phone application, pre-filled with the number.

<a href="tel:6268765881">
Call Us Now 6268765881
</a>

AttributeCategoryPurposeExample
rel="noopener"SecurityPrevents tabnabbing vulnerability when using target="_blank".rel="noopener"
rel="noreferrer"Security/PrivacyHides the referrer URL from the destination site.rel="noreferrer"
rel="nofollow"SEOTells search engines not to pass rank or follow the link.rel="nofollow"
downloadBehaviorForces the browser to download the file instead of viewing it.download="my-file.zip"
href="mailto:..."BehaviorOpens the user's default email client.href="mailto:test@email.com"
href="tel:..."BehaviorInitiates a call on mobile devices.href="tel:+15555551212"

Conclusion

The <a> tag is far more than just a navigational tool. By utilizing attributes like rel for security and SEO control, and the download attribute for file distribution, you can control the entire user experience and ensure your links are both functional and safe.