Hyperlinks are the fundamental building blocks of the World Wide Web, transforming isolated documents into an interconnected global network. By utilizing the HTML anchor tag, developers seamlessly guide users between distinct web pages, downloadable resources, or entirely different applications.
1The Anchor Element and Href
To create a functional link, you must use the anchor element (<a>) paired with its most critical attribute: href (Hypertext Reference). The anchor tag acts as a vehicle, but the href attribute dictates the exact destination URL the browser should navigate to when the user clicks the enclosed text.
Without this required attribute, the anchor element is semantically broken. It becomes a useless inline element rather than an interactive gateway to another document.
2Absolute vs. Relative URLs
When defining the href destination, you can use either absolute or relative URLs. An absolute URL includes the complete web protocol (like https://) and domain address. This is strictly mandatory for linking to external websites on different servers.
A relative URL (like /about.html) acts as a localized shortcut for linking to pages within your own website's directory structure. It is highly preferred for internal routing because it makes your codebase portable; you can move the entire project to a new domain without breaking thousands of internal links.
3Managing Tab Behavior
By default, browsers execute link navigation within the current active tab. This is perfect for internal routing, but when linking out to external resources, it forcefully rips the user away from your application.
It is a UX best practice to keep your web app open and launch the new external site in a separate window. You achieve this by applying the target="_blank" attribute to the anchor tag. Always pair this with rel="noopener noreferrer" to prevent the new tab from maliciously hijacking your original application's process via the window object.
4Internal Anchors and Protocols
Hyperlinks are incredibly versatile. By assigning a unique id attribute to a target element, you can create an internal 'jump link' using an href value starting with a hash symbol (like #pricing). This scrolls the user directly to that section without reloading the page.
Furthermore, anchor tags can trigger deep system-level actions via specialized protocols. Using the mailto: protocol launches the user's default email client, while the tel: protocol initiates a phone call directly from mobile devices. The download attribute forces the browser to instantly save the payload to the user's drive rather than attempting to render it.
5Step-by-Step Breakdown
Introduction to Hyperlinks. Hyperlinks are the fundamental building blocks of the World Wide Web, transforming isolated documents into an interconnected global network. By utilizing the HTML anchor tag, developers can seamlessly guide users between distinct web pages, downloadable resources, or entirely different websites.
The Anchor Element and Href. To create a functional link, you must use the anchor element (<a>) paired with its most critical attribute: href (Hypertext Reference). The href attribute dictates the exact destination URL the browser should navigate to when the user clicks the enclosed text. Without this required attribute, the anchor element is semantically broken.
Defining the Destination. The anchor tag acts as a vehicle, but it needs a coordinate to know where it is driving. Which required HTML attribute of the anchor tag explicitly specifies the destination URL the browser should navigate to upon clicking?
- →src
- →href
- →link
Absolute vs. Relative URLs. When defining the href destination, you can use either absolute or relative URLs. An absolute URL includes the complete web protocol and address (like https://domain.com/page), which is mandatory for linking to external websites. A relative URL (like /about.html) acts as a localized shortcut for linking to pages within your own website's directory.
Absolute vs Relative. When linking to an external website on a completely different domain, which type of URL must you use?
- →absolute
- →relative
Managing Tab Behavior. By default, browsers execute link navigation within the current active tab, which is ideal for internal website routing. However, when linking out to external resources, it is often a UX best practice to keep your application open and launch the new site in a separate window. You achieve this by applying the target="_blank" attribute.
Opening External Links. Directing users away from your application can result in lost traffic if they cannot easily navigate back. When linking to a completely external website, which attribute value ensures the destination page safely opens in a brand-new browser tab?
- →_new
- →_blank
Internal Page Anchors. Hyperlinks are not restricted to opening entirely new pages; they can also aggressively route users to specific sections within the exact same document. By assigning a unique id attribute to a target element, you can create a 'jump link' using an href value starting with a hash symbol (like #contact).
Internal Anchors. When creating a jump link to scroll down to a specific section on the exact same page, which symbol must precede the target ID in the href attribute?
- →/
- →#
- →@
Specialized Linking Protocols. Anchor tags are not strictly limited to standard web addresses. By utilizing specific protocol prefixes inside the href attribute, you can trigger deep system-level actions. For example, using the mailto: protocol will launch the user's default email client. Similarly, the tel: protocol initiates a phone call directly from mobile devices.
Forcing File Downloads. Occasionally, you want a link to directly download a file—like a PDF—rather than having the browser attempt to open and display it natively. HTML5 introduced the download attribute, which explicitly instructs the browser to download the URL's payload directly to the user's hard drive.
Navigation Mastered. Congratulations, you have mastered the core technical mechanics of HTML hyperlinks! By precisely configuring anchor tags, utilizing accurate relative routing paths, and managing tab behavior, you can construct highly seamless and intuitive user journeys. Your HTML documents are no longer isolated files.
Next Steps: Lists. With navigation mastered, the next step is organizing content. Often, navigation links are grouped together in lists to form menus. In the next module, we will explore Ordered and Unordered Lists, learning how to present grouped data and build semantic navigation structures.
Open A Link Safely In A New Tab. target="_blank" needs rel="noopener" to prevent the new page from accessing window.opener.
Level Up 🚀
Advanced cheat sheets, SEO tricks, and interview prep for this topic.
Browser Support
Fully supported.
Fully supported.
Fully supported.
Fully supported.
Accessibility (A11y)
1Never Use 'Click Here' as Link Text
Screen reader users frequently pull up a list of all links on a page out of context. A list full of "click here", "click here", "click here" is meaningless — link text must describe the destination on its own, e.g. "Download the 2024 pricing PDF".
<a href="/pricing.pdf">Download the 2024 pricing PDF</a>2Give Icon-Only Links an Accessible Name
A link wrapping only an SVG or icon font glyph has no text content for a screen reader to announce. Add `aria-label` describing the action, not just the icon's appearance.
<a href="/cart" aria-label="View shopping cart"><svg>...</svg></a>SEO Implications
- 1
Internal Links Distribute Page Authority
Search engines use your internal link graph to understand site structure and pass ranking signal between pages. A well-linked page (many relevant internal links pointing to it) is generally crawled more often and treated as more important than an orphaned page with none.
- 2
Descriptive Anchor Text Helps Rankings for the Linked Page
The visible text of a link is a strong relevance signal for what the destination page is about. Generic anchor text like "click here" wastes that signal; descriptive anchor text like "our HTML forms tutorial" reinforces what the destination page should rank for.
Best Practices
Always Pair `target="_blank"` With `rel="noopener noreferrer"`
Without `noopener`, the newly opened page gets partial JavaScript access to your original tab via `window.opener`, a known phishing/tabnabbing vector. `noreferrer` additionally suppresses the referrer header for privacy.
Prefer Root-Relative Internal URLs (`/about`)
Root-relative paths resolve correctly regardless of which directory the current page lives in, and survive a domain migration without any find-and-replace across the codebase — plain relative paths like `about.html` don't.
Frequent Bugs
Clicking an external link silently breaks the original tab's state (e.g., a SPA resets or redirects).
The destination site abused `window.opener` from a `target="_blank"` link that was missing `rel="noopener"`. Add `rel="noopener noreferrer"` to every externally-targeted link.
An anchor jump link (`href="#section"`) does nothing when clicked.
The target element's `id` doesn't exactly match the fragment (case-sensitive, no leading `#`), or the target element doesn't exist yet at the time of the click due to lazy-loaded content further down the page.
Real-World Examples
Safe External Link in a Content Site
A blog links out to a source citation, opening in a new tab without exposing the original tab to the destination site, and using descriptive anchor text for both accessibility and SEO.
<a href="https://developer.mozilla.org/en-US/docs/Web/HTML" target="_blank" rel="noopener noreferrer">MDN's HTML documentation</a>