Types Of Links: How To Build Them

A comprehensive guide to creating hyperlinks in HTML, from basic anchor elements to advanced link attributes for SEO and accessibility.

What Are Links and Why They Matter

Links are the fundamental building blocks of the World Wide Web. Without hyperlinks, the web would simply be a collection of isolated documents with no way to navigate between them. Understanding how to create and implement different types of links is essential for any web developer or designer.

The Role of Hyperlinks in Web Architecture

Hyperlinks enable the interconnected nature of the web, allowing users to navigate seamlessly between resources, documents, and websites. Every time you click a link, you're traversing the web's vast network of connected information. The invention of hyperlinks by Tim Berners-Lee in 1989 transformed what could have been a static repository of documents into the dynamic, interconnected ecosystem we know today.

Links serve multiple critical functions beyond simple navigation. They establish the information hierarchy that helps both users and search engines understand your site's structure. Internal linking distributes page authority throughout your site, making it easier for content to rank in search results. External links to authoritative sources signal to search engines that your content is well-researched and trustworthy, while also providing additional value to your visitors. Our web development services help businesses build sites with optimal link architecture.

Key Points:

  • Links create the "web" structure that makes the internet navigable
  • Internal linking improves site architecture and user navigation
  • External links provide additional resources and credibility
  • Search engines use links to discover and rank content

MDN Web Docs explains how links form the foundational structure of web navigation and information architecture.

Types of Links You'll Learn

Master all the link types used in modern web development

External Links

Links that point to other websites using absolute URLs with full domain paths.

Internal Links

Links within your own website using relative paths for efficient navigation.

Anchor Links

Jump links for in-page navigation using fragment identifiers (#section-id).

Email Links

mailto: links that open the user's default email client with pre-filled fields.

Phone Links

tel: links that enable click-to-call functionality on mobile devices.

Download Links

Links with download attribute for triggering file downloads instead of navigation.

The Anchor Element: Foundation of All Links

The HTML anchor element <a> is the core component for creating hyperlinks. Despite its name suggesting it "anchors" text to a location, its primary modern use is creating clickable links to other resources. The <a> element has been the workhorse of web navigation since the earliest days of HTML, and understanding its structure is essential for any web developer.

Basic Anchor Syntax

The anchor element requires at least one attribute to function as a hyperlink: the href attribute, which stands for "hypertext reference." This attribute specifies the URL or destination of the link. Without the href attribute, an anchor element becomes a placeholder that can serve as a link target using the id attribute.

<a href="https://example.com">Click here to visit Example</a>

The <a> element requires the href attribute (hypertext reference) to define where the link points. Without href, the anchor element becomes a placeholder or id attribute for navigation. When you include href, the browser renders the enclosed content as clickable and interactive, typically displaying it as underlined text in a distinct color.

href Attribute: The Link Destination

The href attribute specifies the URL of the page the link goes to. It supports multiple URL formats:

  • Absolute URLs: https://example.com/page - Complete address including protocol and domain
  • Relative URLs: ../page or /page - Paths relative to current location or root
  • Protocol-relative: //example.com/page - Uses same protocol as current page
  • Special schemes: mailto:, tel:, javascript: - Triggers different browser behaviors

Understanding which URL format to use is crucial for maintaining flexible, maintainable code. Relative URLs make your site more portable, while absolute URLs are necessary for external destinations.

target Attribute: Controlling Link Behavior

The target attribute determines where the linked document opens:

  • _self (default): Opens in the same frame/window, replacing the current page
  • _blank: Opens in a new tab or window, keeping users on your site
  • _parent: Opens in the parent frame, useful for embedded content
  • _top: Opens in the full body of the window, breaking out of all frames

Security Note: When using target="_blank", always add rel="noopener noreferrer" to prevent security vulnerabilities where the new page can access the window.opener object and potentially redirect your page.

<a href="https://external-site.com" target="_blank" rel="noopener noreferrer">
 Opens in new tab
</a>

download Attribute: Triggering Downloads

The download attribute suggests that the linked resource should be downloaded rather than opened in the browser. This attribute works well for PDFs, images, documents, and archive files where you want users to save the file locally.

<a href="/files/document.pdf" download="guide.pdf">Download PDF</a>

The download attribute can optionally specify a filename for the downloaded file. However, note that this attribute only works for same-origin URLs due to security restrictions.

Types of Links You Can Build

External Links

External links point to resources on other domains. They require absolute URLs with full protocol and domain. When building external links, you're essentially vouching for the destination to your users, so choose external links carefully and ensure they provide genuine value.

When linking to external sites, always include rel="noopener noreferrer" for security. This prevents the newly opened page from accessing your window.opener object, which could otherwise be exploited for malicious purposes. Additionally, consider whether a new tab is truly beneficial--some users prefer to control their own browsing experience.

<a href="https://developer.mozilla.org" target="_blank" rel="noopener noreferrer">
 MDN Web Docs
</a>

Best Practices:

  • Use rel="noopener noreferrer" for security on all external links
  • Consider if the external link truly benefits your users before adding it
  • Don't make every external link open in new tabs--let users choose
  • Add title attributes for additional context when helpful

Internal Links

Internal links connect pages within your own site using relative paths. They form the backbone of your site's navigation and help search engines understand your content structure. Using relative paths makes your site more portable between different environments (development, staging, production).

A well-structured web development approach includes strategic internal linking to distribute page authority and guide users through your content. Relative paths can be document-relative (starting from the current directory) or root-relative (starting from the domain root). Root-relative paths are generally preferred because they remain consistent regardless of the current page's location in your directory structure.

<!-- Same directory -->
<a href="about.html">About Us</a>

<!-- Parent directory -->
<a href="../services.html">Services</a>

<!-- Root-relative (recommended for main navigation) -->
<a href="/contact/">Contact</a>

<!-- Fragment link to section on same page -->
<a href="#faq">Jump to FAQ</a>

A well-structured internal linking strategy improves user experience by helping visitors find related content, and it distributes "link equity" throughout your site to help deeper pages rank in search results.

Anchor Links (Jump Links)

Anchor links navigate to specific sections within a page using fragment identifiers. They create smooth, efficient navigation for long-form content, allowing users to jump directly to the information they need. This is particularly valuable for FAQs, documentation, and table of contents.

To create anchor links, add an id attribute to any element, then link to it using a hash symbol in the href. Modern browsers support smooth scrolling, which creates a gradual transition instead of an instant jump. Enable this with scroll-behavior: smooth in your CSS.

<!-- Link to section -->
<a href="#getting-started">Getting Started</a>

<!-- Target section -->
<section id="getting-started">
 <h2>Getting Started</h2>
 <!-- Content -->
</section>

Accessibility Tip: Ensure target sections have proper heading structure and are reachable via keyboard navigation. Add tabindex="-1" to target elements if focus management becomes an issue. The destination elements should always have meaningful heading content above them.

Special Link Types

Email Links (mailto:)

Create links that open the user's default email client with the address pre-filled. The mailto scheme is universally supported and requires no JavaScript or server-side processing. While simple, mailto links expose email addresses to potential scrapers, so consider using contact forms for publicly accessible pages when spam is a concern.

The basic syntax requires only the email address, but you can also include subject lines, body text, and multiple recipients. When adding subject or body content, use URL encoding for special characters like ampersands, question marks, and line breaks. The JavaScript encodeURIComponent() function handles this encoding automatically.

<!-- Basic email link -->
<a href="mailto:[email protected]">Email Us</a>

<!-- With subject line -->
<a href="mailto:[email protected]?subject=Inquiry">Contact Us</a>

<!-- With subject and body -->
<a href="mailto:[email protected]?subject=Question&body=Hello,%0D%0A%0D%0AI have a question about your services.">
 Send Message
</a>

<!-- Multiple recipients -->
<a href="mailto:[email protected],[email protected]">Email Team</a>

Encoding Tip: Use encodeURIComponent() for special characters in subject and body. For example, encodeURIComponent('Question?') produces Question%3F, and %0D%0A represents line breaks.

Telephone Links (tel:)

Enable click-to-call functionality on mobile devices with the tel: scheme. When mobile users tap a phone link, their device prompts them to dial immediately. Desktop users typically see a non-clickable link, though some may see options to open in a VoIP application.

Always use international format with the country code (E.164 format) for phone links. This ensures the number works correctly regardless of where your users are located. Remove all formatting characters except the leading plus sign.

<!-- Basic phone link -->
<a href="tel:+1-555-123-4567">1-555-123-4567</a>

<!-- International format recommended -->
<a href="tel:+15551234567">Call Us</a>

<!-- With extension -->
<a href="tel:+1-555-123-4567;ext=100">Call and ask for extension 100</a>

For businesses, phone links in the header and footer of every page ensure mobile visitors can reach you instantly from any location on your site.

Download Links

Use the download attribute to prompt file downloads instead of opening files in the browser. This works for PDFs, spreadsheets, images, archives, and other file types that users typically want to save rather than view online.

Without the download attribute, the browser's default behavior varies by file type--PDFs might open in a new tab, images display directly, and text files show as raw content. Adding download overrides this behavior and forces a download dialog.

<!-- Download with default filename -->
<a href="/files/report.pdf" download>Download Report (PDF)</a>

<!-- Download with custom filename -->
<a href="/files/data.csv" download="annual-report-2024.csv">
 Download CSV
</a>

<!-- Download different file types -->
<a href="/files/archive.zip" download>Download ZIP</a>

Browser Limitations: The download attribute only works for same-origin URLs (files on your own domain). Cross-origin downloads may be ignored by browsers for security reasons.

Link Attributes for SEO and Security

Understanding the rel Attribute

The rel attribute (relationship) defines how the current page relates to the linked page. This attribute is crucial for SEO, security, and proper page interpretation by search engines and browsers. Using the correct rel values helps search engines understand which links are paid, which are endorsed, and which are purely navigational.

Modern SEO best practices recommend using specific relationship values rather than applying nofollow universally. This granular approach provides clearer signals about link purpose and helps maintain trust with search engines. Working with our SEO services team can help you implement proper link attributes across your site.

ValuePurpose
noopenerPrevents security vulnerabilities when opening new tabs
noreferrerPrevents sending referrer information to destination
nofollowTells search engines not to follow/pass link equity
sponsoredMarks paid/partnered/sponsored links (Google standard)
ugcMarks user-generated content links (comments, forums)
prev/nextIndicates paginated content structure

nofollow for Untrusted Content

Use rel="nofollow" when linking to content you don't fully endorse or when you cannot verify the content's quality. Google introduced this attribute to prevent comment spam and reduce manipulation of search rankings through link schemes.

Common use cases include links in unmoderated comments, forum posts from unknown users, and content on websites with questionable reputation. The nofollow attribute tells search engines not to pass "link juice" to the target page.

<a href="https://forum.example.com" rel="nofollow">
 User Forum
</a>

Google Guidelines: Use nofollow for paid links, untrusted third-party content, and crawl budget management. Consider it a last-resort attribute when other specific values don't apply.

sponsored for Paid Links

Google introduced rel="sponsored" to specifically mark advertising, sponsored, or partner links. This distinction helps search engines accurately categorize links and prevents violations of link spam guidelines. If you're compensated (monetarily or otherwise) for a link, use sponsored.

<a href="https://partner.example.com" rel="sponsored">
 Our Partner
</a>

Using sponsored instead of nofollow for paid links shows transparency with search engines and can prevent potential penalties under Google's link spam policies.

ugc for User-Generated Content

Use rel="ugc" for links in user-generated content like comments, forum posts, guest books, and reviews. This category was introduced to provide more specific link classification beyond the catch-all nofollow.

<a href="https://commenter.example.com" rel="ugc">
 Commenter Profile
</a>

UGC links are inherently less trustworthy because site owners cannot verify their destination. Using ugc provides search engines with accurate information about link origin without completely discounting potential legitimate content.

Link Best Practices

Accessibility Guidelines

Descriptive Link Text: Write link text that clearly describes where the link goes. Avoid generic phrases like "click here" or "read more" that provide no context for screen reader users or those scanning page content. Descriptive link text helps all users understand the link destination before clicking.

<!-- ❌ Bad - no context -->
<p>Click <a href="/services/">here</a> for more information.</p>

<!-- ✅ Good - descriptive text -->
<p>Learn more about our <a href="/services/">web development services</a>.</p>

Keyboard Accessibility:

  • Ensure links are reachable via Tab key navigation
  • Provide visible focus indicators (never remove outline without replacement)
  • Test link functionality without a mouse using keyboard only
  • Avoid trapping focus within interactive elements

Screen Reader Best Practices:

  • Avoid duplicate link text on the same page
  • Use aria-label for icon-only links or when context is needed
  • Don't open new tabs without warning users
  • Ensure links have sufficient color contrast (WCAG AA: 4.5:1 minimum)

Link Styling

  • Consistency: Use the same styling for similar types of links throughout your site
  • Color: Ensure adequate contrast--text links should stand out from body text
  • Underlines: Don't remove underlines unless absolutely necessary and replace with clear visual alternatives
  • Hover states: Provide visual feedback when users hover over links
  • Focus states: Ensure keyboard focus is clearly visible for navigation

Performance Optimization

Preconnect to domains you link to frequently, especially for external resources like CDNs, analytics, or embedded content. This resolves DNS and establishes connections in advance, reducing latency when users click those links.

<link rel="preconnect" href="https://cdn.example.com">
<link rel="dns-prefetch" href="https://external-analytics.com">

Common Mistakes to Avoid

  1. Missing href attribute - An anchor without href is not a clickable link
  2. Broken relative paths - Double-check path structure and directory levels
  3. Case sensitivity - URLs are case-sensitive on most servers
  4. Orphaned anchors - Ensure target elements with matching ids actually exist
  5. Excessive new tabs - Don't surprise users with unexpected behavior
  6. Non-descriptive link text - Avoid vague phrases in favor of specific descriptions

Frequently Asked Questions

Summary and Key Takeaways

Links are the foundation of web navigation and user experience. By mastering different link types and their attributes, you can create intuitive, accessible, and SEO-friendly navigation for any website. Proper link implementation improves both user satisfaction and search engine visibility.

Key Takeaways:

  1. Anchor Element: The <a> element with href creates hyperlinks--the fundamental building block of web navigation
  2. Link Attributes: Use target for opening behavior, rel for relationship definitions
  3. Link Types: External, internal, anchor, mailto, tel, and download links each serve specific purposes
  4. SEO: Use nofollow, sponsored, and ugc appropriately to signal link purpose to search engines
  5. Accessibility: Write descriptive link text and ensure keyboard navigation works for all users
  6. Security: Always use noopener noreferrer with target="_blank" to prevent vulnerabilities

Quick Reference: Link Types

TypeExampleUse Case
Externalhref="https://..."Linking to other websites
Internalhref="/about/"Pages on your own website
Anchorhref="#section"In-page navigation
Emailhref="mailto:..."Opening email client
Phonehref="tel:..."Click-to-call on mobile
Downloadhref="file.pdf" downloadTriggering file downloads

Building effective links requires attention to HTML syntax, accessibility, SEO implications, and user experience. By following the patterns and best practices in this guide, you'll create navigation that works for all users and performs well in search results. For more web development techniques, explore our comprehensive web development services or contact our team for personalized guidance on your project.

Ready to Build Better Websites?

Our web development experts can help you create intuitive navigation and exceptional user experiences.

Sources