🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
HTML MASTER CLASS /// LEARN TAGS /// BUILD STRUCTURE /// SEMANTIC WEB /// HTML MASTER CLASS /// LEARN TAGS ///

HTML Links: Connecting the Web

Master the HTML anchor tag. Learn the difference between absolute and relative URLs, how to open links in new tabs, jump to specific page sections, and trigger email or phone actions.

Narrated Video Summary
data-composition-id="html-html-creating-links"1280×720 @ 30fps10 clips3:44 total

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.

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.

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.

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`).

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.

0:00 / 3:44
Scene 1 / 10 — Introduction to Hyperlinks
Total XP: 0|💻 html XP: 0

Skill Matrix

UNLOCK NODES BY LEARNING NEW TAGS.

Navigation Node

Web Connectivity.


🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.

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.

+
<!-- Broken: Missing href attribute -->
<a>Click here</a>

<!-- Valid: Directs to destination -->
<a href="https://developer.mozilla.org">
  MDN Web Docs
</a>
localhost:3000

Click here

MDN Web Docs

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.

+
<!-- Absolute URL (External site) -->
<a href="https://github.com">GitHub</a>

<!-- Relative URL (Internal site) -->
<a href="/dashboard/settings">Settings</a>
localhost:3000
Leaving site ➡️ https://github.com
Internal route ➡️ localhost:3000/dashboard/settings

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.

+
<!-- Opens safely in a new background tab -->
<a
  href="https://external-resource.com"
  target="_blank"
  rel="noopener noreferrer"
>
  External Resource ↗
</a>
localhost:3000

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.

+
<!-- Jump Link -->
<a href="#contact-section">Jump down</a>

<!-- System Email Trigger -->
<a href="mailto:help@app.com">Email Support</a>

<!-- Target for Jump Link -->
<h2 id="contact-section">Contact Us</h2>
localhost:3000

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

ChromeSupported

Fully supported.

FirefoxSupported

Fully supported.

SafariSupported

Fully supported.

EdgeSupported

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

THE BUG

Clicking an external link silently breaks the original tab's state (e.g., a SPA resets or redirects).

THE FIX

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.

THE BUG

An anchor jump link (`href="#section"`) does nothing when clicked.

THE FIX

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>

Interview Prep

?Frequently Asked Questions

Pascual Vila

Pascual Vila

Frontend Instructor // Code Syllabus

Common Pitfalls & Errors

The Error //

Empty link text (e.g., surrounding an icon without text)

<!-- Wrong --> <a href="/home"><i class="icon-home"></i></a> <!-- Correct --> <a href="/home" aria-label="Go to homepage"><i class="icon-home"></i></a>

The Solution //

If an <a> tag only contains an image or icon, it must have an aria-label or visually hidden text for screen readers.

The Error //

Using absolute paths for internal links

<!-- Wrong --> <a href="https://mysite.com/about">About Us</a> <!-- Correct --> <a href="/about">About Us</a>

The Solution //

Use relative paths for links within your own site so that if your domain changes, your links don't break.

Lesson Glossary

[01]Hyperlink

A reference to data that the user can follow by clicking or tapping.

Code Preview
<a>

[02]href

Hypertext Reference. The attribute that specifies the URL of the page the link goes to.

Code Preview
href='url'

[03]Absolute URL

A full web address including the protocol (https://) and domain name.

Code Preview
https://domain.com

[04]Relative URL

A path to a file within the same website, omitting the domain name.

Code Preview
/about.html

[05]target='_blank'

An attribute value that forces the browser to open the linked document in a new tab or window.

Code Preview
target='_blank'

[06]mailto:

A URL scheme used to produce a hyperlink that allows users to send an email.

Code Preview
mailto:email@x.com

Continue Learning