Hyperlink in HTML Explained: Complete Guide to Anchor Tag Types and Attributes

In the realm of web development, a fundamental element that facilitates the transition between different sources of information across the internet is the humble hyperlink. But what exactly is a hyperlink in HTML, and what are its various types? Let's delve into this essential aspect of the language that governs the World Wide Web.

How to Code a Hyperlink in HTML (it's easier than you think!)
How to Code a Hyperlink in HTML (it's easier than you think!)

At its core, a hyperlink, often abbreviated as 'link', is a reference from one web page to another. It is like a bridge that connects related or relevant content, allowing users to navigate seamlessly between different parts of a website or across the vast expanse of the internet.

Difference Between Hypertext and Hyperlink
Difference Between Hypertext and Hyperlink

Understanding Hyperlinks in HTML

In HTML, a hyperlink is created using the '<a>' tag. The 'href' attribute, short for 'hypertext reference', is used to specify the target of the link. This could be a webpage, an image, a video, or even an email address. Here's a basic example:

HOW TO CREATE LINKS IN HTML
HOW TO CREATE LINKS IN HTML

<a href="https://www.example.com">Visit Example</a>

Absolute vs. Relative Hyperlinks

a screen shot of a web page with the words'html input types '
a screen shot of a web page with the words'html input types '

Hyperlinks can be either absolute or relative. Absolute links provide the full URL of the target, starting from the protocol (like 'http://' or 'https://'), followed by the domain name and path to the resource. They are beneficial when linking to external websites or resources that may not be under your control.

For instance: <a href="https://www.example.com/path/to/page">Example</a>

On the other hand, relative links use a shorthand notation to reference files within the same website. They are relative to the current webpage's location. Relative links are useful when maintaining or updating a website, as they automatically adjust when the website's structure changes. The format usually starts with './' for the current directory or '../' for the parent directory.

Web Design in HTML & CSS – The Ultimate Lesson Plans Bundle
Web Design in HTML & CSS – The Ultimate Lesson Plans Bundle

For example: <a href="./page.html">Page</a> or <a href="../parent_page.html">Parent Page</a>

Blank Targets and New Windows

By default, HTML links open in the same window or tab. However, you can specify that a link should open in a new window or tab using the 'target' attribute. The 'blank' value is commonly used, directing the browser to open the link in a new window or tab.

Learn to create links in HTML.
Learn to create links in HTML.

Here's an example: <a href="https://www.example.com" target="_blank">Visit Example</a>

Types of Hyperlinks in HTML

the different types of web pages are shown
the different types of web pages are shown
HYPER LINK
HYPER LINK
Internal vs external links (HTML basics) 👇
Internal vs external links (HTML basics) 👇
What is HTML?
What is HTML?
What is HTML
What is HTML
an image of a web page with the text'html inputt types '
an image of a web page with the text'html inputt types '
the different types of html tags are shown in this screenshote screen graber
the different types of html tags are shown in this screenshote screen graber
HTML Cheat Sheet 📄✨ Quick Guide for Beginners
HTML Cheat Sheet 📄✨ Quick Guide for Beginners
an image of a web page with the text'html link target attribute '
an image of a web page with the text'html link target attribute '
HTML Input Types : A Comprehensive Guide
HTML Input Types : A Comprehensive Guide
All HTML Input Types 📌 Save it or Miss it 🚀 Follow For More 💥
All HTML Input Types 📌 Save it or Miss it 🚀 Follow For More 💥
an info sheet with different types of text
an info sheet with different types of text
Links in HTML
Links in HTML
HTML input types
HTML input types
an image of a web page with the words in different languages
an image of a web page with the words in different languages
HTML Full Form + 10 Essential Tags Every Beginner Must Know 🚀
HTML Full Form + 10 Essential Tags Every Beginner Must Know 🚀
The HTML Backbone
The HTML Backbone
About HTML tags
About HTML tags
HTML Full Notes for Beginners 💻
HTML Full Notes for Beginners 💻
Types of tags in HTML
Types of tags in HTML

Beyond simple webpage links, HTML supports several types of hyperlinks to cater to various use cases. Let's explore a few:

Email Links

Email links allow users to send an email to a predefined address by simply clicking on a link. The 'mailto:' protocol is used, followed by the email address. You can also add subject and body parameters for convenience.

For example: <a href="mailto:info@example.com?subject=Feedback&body=I enjoyed your website.">Contact Us</a>

JavaScript Links

JavaScript links or 'javascript:' protocol links execute a JavaScript function when clicked. This can be used to implement client-side functionality like form validation, smooth scrolling, or custom behaviors.

Here's a simple example using smooth scrolling: <a href="#sectionID" onclick="smoothScroll()">Go to Section</a>

Download Links

HTML5 introduced the 'download' attribute for the '<a>' tag, enabling direct file downloads. When a link with the 'download' attribute is clicked, the browser prompts the user to download the targeted file instead of navigating to it.

For example: <a href="example.pdf" download>Download PDF</a>

In the ever-evolving landscape of web development, understanding and effectively using hyperlinks is not just key, but central to creating a seamless and engaging user experience. Whether you're linking to other pages, resources, or actions, mastering HTML hyperlinks is a fundamental step towards becoming a proficient web developer.

Related Articles

Attributes Of Marquee Tag In Html With Example Attributes Of Marquee Tag With Examples Explain Img Tag In Html With Example What Text Is Used To Create A Hyperlink In Html Img Tag Html With Url Explain Hyperlink In Html With Example Simple Marquee Tag In Html Example Marquee Html Code Example Tables Html W3 Explain Image Tag With Example