πŸŽ‰ New: Top 75 PHP Interview Questions for 2026 β€” Free for all learners
Beginner ⏱ 9 min read πŸ”„ Updated

HTML Links

Advertisement

Master web navigation with this complete HTML links guide. Learn anchor tags, href attributes, absolute vs relative URLs, target attributes, and page anchors.

Estimated Read Time: 19 Minutes | Category: Web Development Fundamentals


Quick HTML Links Summary:

  1. Web Navigation Engine: Hyperlinks (created using the <a> anchor tag) connect web pages, documents, and online resources together across the World Wide Web.
  2. The href Attribute: The href (Hypertext Reference) attribute specifies the target destination URL or file path where the link navigates when clicked.
  3. Absolute vs. Relative URLs: Absolute URLs link to external website domains (e.g., https://example.com), while relative URLs link to internal pages within the same website directory.
  4. Target Attribute Control: The target="_blank" attribute forces links to open inside a new browser tab or window.
  5. Security Safeguards: External links opening in new tabs should always include rel="noopener noreferrer" to protect against cross-origin security vulnerabilities.

Welcome to Lesson 5 of our structured Web Development curriculum, marking the beginning of Module 2: Links, Images & Media. Following our previous tutorial on Easy HTML Formatting Tags Guide: 10 Essential Elements & Examples, you now understand how to apply inline emphasis, bolding, highlighting, and code formatting to text. The next vital step in building web pages is creating navigation networks using HTML links.

Hyperlinks are the single defining feature that transformed simple digital text documents into the interconnected World Wide Web. Without links, users would have no way to navigate between web pages, browse online stores, download files, or access external resources.

In this comprehensive HTML links guide, we will explore anchor tag syntax, destination URL paths, opening links in new tabs safely, email and telephone shortcuts, page jump bookmark anchors, link security, and practical code examples.

html links, learn html links, html anchor tag, html href attribute, target blank html, absolute vs relative urls html, mailto link html
html links, learn html links, html anchor tag, html href attribute, target blank html, absolute vs relative urls html, mailto link html

To test the hands-on code examples in this HTML links tutorial, verify that your development environment meets these basic requirements:

  • Web Browser: A modern web browser such as Google Chrome, Mozilla Firefox, Microsoft Edge, or Apple Safari.
  • Code Editor: A text editor such as Visual Studio Code, Sublime Text, or Notepad++.
  • Document Structure Foundations: Understanding of standard body elements and text formatting tags.

If you need to review how inline text formatting tags operate inside links, visit our previous guide on Easy HTML Formatting Tags Guide: 10 Essential Elements & Examples.


1. Anatomy of the HTML Anchor Tag (<a>)

Hyperlinks are created in HTML using the <a> (anchor) element. The anchor tag wraps around visible clickable content (called anchor text or clickable media) and uses the href attribute to define the target destination:

<!-- Basic HTML Link Structure -->
<a href="https://phponline.in">Visit PHPOnline Platform</a>

Want to test this HTML markup live? Try running it in our Online HTML Editor.

Key Components of an Anchor Element:

  • Opening Tag (<a>): Marks the start of the hyperlink container.
  • Destination Attribute (href="..."): Tells the browser exactly where to send the user upon clicking.
  • Anchor Text: The visible, clickable text or image displayed inside the browser viewport.
  • Closing Tag (</a>): Marks the end of the clickable hyperlink zone.

When specifying destination addresses inside the href attribute, web developers choose between two path formats depending on whether the destination is external or internal:

URL Path TypeSample SyntaxTarget LocationPrimary Application Scenario
Absolute URLhref="https://phponline.in/tutorials/html/"External website domain or explicit protocol path.Linking to external third-party websites, APIs, or official documentation.
Relative URLhref="about.html" or href="../images/pic.png"Internal file within the same website directory structure.Navigating between local pages on your own website server.

A. Absolute URL Example

<!-- Absolute URL linking to an external website domain -->
<a href="https://www.w3.org" target="_blank">Official W3C Standards Website</a>

B. Relative URL Example

<!-- Relative URL linking to an internal page in the same folder -->
<a href="contact.html">Contact Us</a>

<!-- Relative URL navigating up one directory level -->
<a href="../index.html">Return to Home</a>

Want to test this HTML markup live? Try running it in our Online HTML Editor.


By default, clicking a link loads the target destination inside the current browser window, replacing the active page. The target attribute allows developers to control where the linked document opens:

  • target="_self" (Default): Opens the document in the same window/tab.
  • target="_blank": Opens the document in a new, separate browser tab or window.
  • target="_parent": Opens the document in the parent frame.
  • target="_top": Opens the document in the full body of the browser window.

Crucial Security Safeguard: rel=”noopener noreferrer”

Whenever you open external links in a new tab using target="_blank", the newly opened page gains partial JavaScript access to your original page via the window.opener object. Attackers can exploit this (known as tabnabbing) to silently redirect your original tab to a malicious phishing site.

To block tabnabbing security risks, always pair target="_blank" with rel="noopener noreferrer":

<!-- Secure External Link Configuration -->
<a href="https://phponline.in" target="_blank" rel="noopener noreferrer">
    Open Secure External Resource
</a>

Want to test this HTML markup live? Try running it in our Online HTML Editor.


4. Page Jump Bookmark Anchors (#id)

When writing long-form tutorials or documentation pages, you can create internal bookmark links (also called anchor jumps) that instantly scroll the user to a specific section on the exact same page.

Two-Step Anchor Jump Setup:

  1. Assign a unique id attribute to the target section heading (e.g., id="faq-section").
  2. Create a hyperlink with a hash symbol (#) followed by that exact ID name inside the href attribute (e.g., href="#faq-section").
<!-- Step 1: Clickable Jump Link -->
<p><a href="#troubleshooting-section">Jump to Troubleshooting Table &darr;</a></p>

<!-- Page content... -->

<!-- Step 2: Target Section with Matching ID -->
<h2 id="troubleshooting-section">Troubleshooting Common Link Errors</h2>
<p>Here are solutions to frequent hyperlink errors...</p>

Want to test this HTML markup live? Try running it in our Online HTML Editor.


HTML links are not limited to opening web pages. Using specialized URL protocol prefixes, anchor tags can trigger email clients, phone calls, or file downloads:

<!-- Launches the user's default email app with pre-filled recipient -->
<a href="mailto:support@phponline.in?subject=Course%20Inquiry">Send Us an Email</a>
<!-- Triggers dialer on mobile devices or softphone apps on desktop -->
<a href="tel:+18005550199">Call Customer Support (+1-800-555-0199)</a>
<!-- Forces browser to download the file instead of displaying it -->
<a href="cheatsheet.pdf" download="HTML5_Cheatsheet.pdf">Download HTML Cheat Sheet (PDF)</a>

Want to test this HTML markup live? Try running it in our Online HTML Editor.


Unclosed anchor tags, broken URLs, and invalid attribute syntax can corrupt entire web page layouts. Always validate your markup using automated standard tools like our HTML Validator Tool to verify compliance with W3C web standards.


Attribute NameSample SyntaxDefault BehaviorPrimary Application Scenario
hrefhref="https://example.com"MandatoryDefines target destination URL, file path, email address, or phone number.
targettarget="_blank"_selfSpecifies whether the linked document opens in the current tab or a new tab.
relrel="noopener noreferrer"NoneSecures external links opening in new tabs against cross-site tabnabbing attacks.
downloaddownload="file.pdf"Opens in browserInstructs browser to download the linked file directly to local storage.
titletitle="Additional details"NoneDisplays a helpful pop-up tooltip when a user hovers over the link text.

Observed Link ErrorProbable CauseRecommended Solution
Clicking a link returns 404 Not Found errorMisspelled file path, missing file extension (e.g., about instead of about.html), or case mismatch.Verify relative folder paths and exact filename spellings. Validate code using our HTML Validator Tool.
Relative link resolves to external web address incorrectlyForgetting the https:// protocol prefix on external links (e.g., href="google.com").Always include full protocol prefixes (https://) for external website domain links.
Page jump anchor link (#id) does not scroll when clickedMismatch between the link’s href="#target-id" and the target element’s id="target-id".Ensure the target heading or container has a matching id="..." attribute without the hash symbol.
Text following a link becomes blue and clickable across the entire pageOmitting the closing </a> tag on an anchor element.Add a closing </a> tag immediately after the intended clickable anchor text.

Frequently Asked Questions (FAQ)

HTML links (or hyperlinks) are anchor elements (<a>) that allow users to navigate between web pages, download files, jump to sections on a page, or access external websites. They form the navigational foundation of the World Wide Web.

Q2: What is the difference between an absolute URL and a relative URL?

An absolute URL contains the complete address protocol and domain name (e.g., https://phponline.in/tutorials/html/) used to link to external sites. A relative URL specifies a local path relative to the current file (e.g., contact.html) used to navigate within the same site.

Q3: Why should target=”_blank” always be paired with rel=”noopener noreferrer”?

Pairing target="_blank" with rel="noopener noreferrer" prevents security vulnerabilities known as tabnabbing. It prevents the newly opened external tab from accessing your original page’s window.opener JavaScript property to manipulate or redirect your page.

Create an email link by placing the mailto: protocol prefix followed by the recipient email address inside the href attribute (e.g., <a href="mailto:support@phponline.in">Contact Email</a>).


Next Steps & Official References

Consult official technical web standards on the MDN Official Anchor Element Documentation (mozilla.org).

Before publishing your hyperlink navigation, validate your code syntax using our PHPOnline HTML Validator Tool.

Ready for the next lesson in sequence? Proceed directly to the next lesson in Module 2: Next Lesson: HTML Images & Image Attributes β†’

# Summary

Here is what you've learned in this lesson:

  • Easy HTML Links Guide: 5 Core Hyperlink Attributes & Examples
  • Overview: Understanding HTML Links & Hypertext Navigation
  • Prerequisites Before Creating Hyperlinks
  • 1. Anatomy of the HTML Anchor Tag (<a>)
  • 2. Absolute vs. Relative URLs in HTML Links
  • 3. Opening Links in New Tabs (<a target="_blank">)
  • 4. Page Jump Bookmark Anchors (#id)
  • 5. Special Hyperlink Shortcuts: Email, Phone & File Downloads
  • Validating HTML Link Code Standards
  • Summary Comparison of Top HTML Link Attributes
  • Troubleshooting Common HTML Link Errors
  • Frequently Asked Questions (FAQ)
  • Next Steps & Official References
πŸš€
Next up: HTML Images

Continue to the next lesson and learn more about HTML Images.

Start Next Lesson β†’

← Previous Post
HTML Formatting Tags
Next Post β†’
HTML Images